utilities
predspot.utilities
¶
Utilities Module¶
Helpers used across Predspot: a PandasFeatureUnion that
keeps
DataFrames (and their index) when combining feature transformers, and a
GeoJSON contour export for density maps.
PandasFeatureUnion
¶
Bases: TransformerMixin, BaseEstimator
Concatenate the DataFrame outputs of several transformers column-wise.
Unlike sklearn.pipeline.FeatureUnion, the transformers' outputs
are aligned on their index and returned as a DataFrame. Rows with missing
values after alignment (e.g. warm-up rows of lag features) are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer_list
|
list
|
|
required |
Source code in src/predspot/utilities.py
merge_dataframes_by_column
staticmethod
¶
Align a list of DataFrames on their index and concatenate columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs
|
list
|
DataFrames returned by the transformers. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The merged features without missing rows. |
Source code in src/predspot/utilities.py
contour_geojson
¶
Export a density surface as filled GeoJSON contours.
Requires the optional dependency geojsoncontour
(pip install predspot[contour]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Series
|
Values indexed by the positional index of the
full point grid returned by
|
required |
bbox
|
GeoDataFrame
|
Study area used to build the grid. |
required |
resolution
|
float
|
Grid resolution in kilometers (same as the grid). |
required |
cmin
|
float
|
Lowest contour level. |
required |
cmax
|
float
|
Highest contour level. |
required |
Returns:
| Type | Description |
|---|---|
str
|
GeoJSON string with the contour polygons. |