reVX.utilities.region_classifier.RegionClassifier

class RegionClassifier(meta_path, regions, regions_label=None, outlier_value=-999)[source]

Bases: object

Base class of region classification

Examples

>>> meta_path = 'meta.csv'
>>> regions_path = 'us_states.shp'
>>> regions_label = 'NAME'
>>>
>>> classifier = RegionClassifier(meta_path=meta_path,
                                  regions_path=regions_path,
                                  regions_label=regions_label)
>>>
>>> force = True
>>> fout = 'new_meta.csv'
>>>
>>> classification = classifier.classify(force=force)
>>> classifier.output_to_csv(classification, fout)
Parameters:
  • meta_path (str | pandas.DataFrame) – Path to meta CSV file, resource .h5 file, or pre-loaded meta DataFrame containing lat/lon points

  • regions (str | GeoDataFrame) – Path to regions shapefile containing labeled geometries or a pre-loaded GeoDataFrame

  • regions_label (str) – Attribute to use as label in the regions shapefile

  • outlier_value (float | int | str) – Value to assign to outliers if not force

Methods

classify([force])

Classify the meta data with regions labels

output_to_csv(gdf, path)

Export a geopandas dataframe to csv

run(meta_path, regions[, regions_label, ...])

Run full classification

Attributes

CRS

DEFAULT_REGIONS_LABEL

regions

Get the regions GeoDataFrame

property regions

Get the regions GeoDataFrame

Returns:

GeoDataFrame

static output_to_csv(gdf, path)[source]

Export a geopandas dataframe to csv

Parameters:
  • gdf (GeoPandas DataFrame) – Meta data to export

  • path (str) – Output CSV file path for labeled meta CSV file

classify(force=False)[source]

Classify the meta data with regions labels

Parameters:

force (str) – Force outlier classification by finding nearest

classmethod run(meta_path, regions, regions_label=None, force=False, fout=None)[source]

Run full classification

Parameters:
  • meta_path (str | pandas.DataFrame) – Path to meta CSV file, resource .h5 file, or pre-loaded meta DataFrame containing lat/lon points

  • regions (str | GeoDataFrame) – Path to regions shapefile containing labeled geometries or a pre-loaded GeoDataFrame

  • regions_label (str) – Attribute to use a label in the regions shapefile

  • force (str) – Force outlier classification by finding nearest

  • fout (str) – Output CSV file path for labeled meta CSV file

Examples

>>> meta_path = 'meta.csv'
>>> regions_path = 'us_states.shp'
>>> regions_label = 'NAME'
>>> force = True
>>> fout = 'new_meta.csv'
>>>
>>> RegionClassifier.run(meta_path=meta_path,
                         regions_path=regions_path,
                         regions_label=regions_label
                         force=force, fout=fout)