lmpy.point
Module containing Point class.
Note: A namedtuple could replace this class for Python 3.7+
Module Contents
Classes
Constructor. |
|
Constructor for a Point CSV retriever. |
|
Constructor for writing points to csv file. |
|
Constructor for reading Darwin Core Archives. |
|
Constructor for writing JSON points. |
Functions
|
Get a function to process a field for a specimen record. |
|
Return None as a function. |
Attributes
- class lmpy.point.Point(species_name, x, y, attributes=None)[source]
Constructor.
- Parameters
species_name (
str) – The species name for this point.x (
float) – The value of the x coordinate for this occurrence point.y (
float) – The value of the y coordinate for this occurrence point.attributes (
dict) – A dictionary of attributes associated with this point.
- Raises
ValueError – Raised if the species name is omitted.
- __eq__(self, other)[source]
Test if this point equals the other.
- Parameters
other (
Point) – A different Point object to compare with.- Returns
An indication if the two points are equal for the primary attributes.
- Return type
bool
- __lt__(self, other)[source]
Test if this point is less than the other.
- Parameters
other (
Point) – A different Point object to compare with.- Returns
- An indication if this point is less than the other for the primary
attributes.
- Return type
bool
- __repr__(self)[source]
Get a string representation of this Point object.
- Returns
A string representation of this Point.
- Return type
str
- get_attribute(self, attribute_name)[source]
Get an attribute for the point.
- Parameters
attribute_name (
str) – The attribute to attempt to retrieve.- Returns
The value of the attribute if it exists. None: Returned if the attribute does not exist for the Point.
- Return type
object
- class lmpy.point.PointCsvReader(filename, species_field, x_field, y_field, geopoint=None, group_field='species_name')[source]
Constructor for a Point CSV retriever.
- Parameters
filename (
str) – A file path containing CSV occurrence data.species_field (
str) – The field name of the column containing species data.x_field (
str) – The field name of the column containing x coordinates.y_field (
str) – The field name of the column containing y coordinates.geopoint (
str) – The field name of the column containing geopoint data.group_field (
str) – The name of the field to use for grouping points.
- __exit__(self, *args)[source]
Context manager magic method on exit.
- Parameters
*args – Positional arguments passed to the exit function.
- class lmpy.point.PointCsvWriter(filename, fields, write_headers=True, mode='w', **kwargs)[source]
Constructor for writing points to csv file.
- Parameters
filename (
str) – A file location to write points to.fields (
list) – A list of fields to include in the csv headers.write_headers (
bool) – Should headers be written.mode (
str) – File write mode.**kwargs (
dict) – Keyword parameters that will be passed to the DictWriter instance from the csv module.
- class lmpy.point.PointDwcaReader(dwca_filename, meta_filename=DEFAULT_META_FILENAME, species_term=DEFAULT_SPECIES_TERM, x_term=DEFAULT_X_TERM, y_term=DEFAULT_Y_TERM, geopoint_term=None)[source]
Constructor for reading Darwin Core Archives.
- Parameters
dwca_filename (
str) – File location of a DWCA zip file.meta_filename (
str) – File within the archive containing metadata. Defaults to DEFAULT_META_FILENAME.species_term (
str) – Species term in the DWCA file. Defaults to DEFAULT_SPECIES_TERM.x_term (
str) – X term in the DWCA file. Defaults to DEFAULT_X_TERM.y_term (
str) – Y term in the DWCA file. Defaults to DEFAULT_Y_TERM.geopoint_term (
str) – Geopoint term in the DWCA file. Default is None.
- __exit__(self, *args)[source]
Context manager magic method on exit.
- Parameters
*args – Positional arguments passed to the exit function.
- __next__(self)[source]
Get lists of consecutive points with the same attribute value.
- Returns
A list of point objects.
- Return type
list
- Raises
StopIteration – Raised when there are no additional objects.
- _get_species_name(self, point_dict)[source]
Get the species name from the attribute dictionary.
- Parameters
point_dict (
dict) – A dictionary of point attributes.- Returns
A species name
- Return type
str
- _get_x_value(self, point_dict)[source]
Get the x coordinate value from the attribute dictionary.
- Parameters
point_dict (
dict) – A dictionary of point attributes.- Returns
The x coordinate retrieved. None: Returned if there is no x value.
- Return type
numeric
- _get_y_value(self, point_dict)[source]
Get the y coordinate value from the attribute dictionary.
- Parameters
point_dict (
dict) – A dictionary of point attributes.- Returns
The y coordinate retrieved. None: Returned if there is no y value.
- Return type
numeric
- class lmpy.point.PointJsonWriter(filename)[source]
Constructor for writing JSON points.
- Parameters
filename (
str) – A file location to write the points to.
- lmpy.point.get_field_process_func(index=None, default=None, vocabulary=None, delimiter=None)[source]
Get a function to process a field for a specimen record.
- Parameters
index (
int, optional) – The column index of the field value to process. If none, always return the default.default (number or string, optional) – An optional default value (optional if index is not None) to return when the value of the field is empty.
vocabulary (
str, optional) – A URI that identifies a vocabulary used for this field’s possible values.delimiter (
str, optional) – An optional delimiter to split the field value with.
- Returns
A method for getting the value of a field for a specimen row.
- Return type
Method