macroeco.empirical.Patch

class macroeco.empirical.Patch(metadata_path, subset='')

An object representing an empirical census

Parameters:

metadata_path : str

Path to metadata file describing census data

subset : str

String describing subset of data to use for Patch analysis. See Notes.

Notes

The table file described by the metadata must contain column names consisting only of letters and numbers, with no spaces or other special characters.

The parameter subset takes different forms depending on whether the data file described by the metadata is a csv or a sql/db file.

For csv data files, subset is a semicolon-separated string describing subset operations. For example, the string “year==2005; x>20; x<40; spp==’cabr’” loads a data table containing only records for which the year is 2005, x values are between 20 and 40, and species is ‘cabr’. Note that for categorical columns, the value of the column must be enclosed in single quotes.

For sql/db files, subset is a SQL query string that selects the data from the data file.

The meta attribute of this object is processed to reflect the value of subset. If columns with a min and a max are included in the subset string, the min and max values for that column in meta will be updated to reflect the specified limits.

An empty Patch object can be created with a metadata_path of None.

Examples

>>> # Using the ANBO data provided in demo_files_ANBO.zip found at
>>> # https://github.com/jkitzes/macroeco/releases/
>>> import macroeco as meco
>>> # Pass in path to metadata in order to make patch object
>>> pat = meco.empirical.Patch('~/Desktop/ANBO.txt')
>>> # Subset data upon loading using subset string.
>>> # Should be a conditional statements separated by a semicolon
>>> pat = meco.empirical.Patch('~/Desktop/ANBO.txt',
                                subset="year==2010; row>2")

Attributes

table dataframe Table of census data recorded in patch
meta ConfigParser obj Dict-like metadata, loaded from metadata_path and processed by subset
subset str Subset string passed as parameter