Utilities

Utilities Module

This module provides utility functions and classes for data processing and visualization, including contour generation, feature union operations, and pandas-specific transformations.

class predspot.utilities.PandasFeatureUnion(transformer_list, n_jobs=None, transformer_weights=None, debug=False)[source]

Bases: FeatureUnion

A FeatureUnion transformer that preserves pandas DataFrames.

This class extends sklearn’s FeatureUnion to work with pandas DataFrames, maintaining index alignment and column names.

n_jobs

Number of parallel jobs

Type:

int

transformer_list

List of transformer tuples

Type:

list

transformer_weights

Weights for transformers

Type:

dict

debug

Enable debug printing

Type:

bool

fit_transform(X, y=None, **fit_params)[source]

Fit all transformers and transform the data.

Parameters:
  • X (pandas.DataFrame) – Input features

  • y (array-like, optional) – Target values

  • **fit_params – Additional fitting parameters

Returns:

Transformed features

Return type:

pandas.DataFrame

Raises:

ValueError – If no transformers are provided

merge_dataframes_by_column(Xs)[source]

Merge transformed features into a single DataFrame.

Parameters:

Xs (list) – List of transformed DataFrames

Returns:

Merged DataFrame

Return type:

pandas.DataFrame

transform(X)[source]

Transform X separately by each transformer.

Parameters:

X (pandas.DataFrame) – Input features

Returns:

Transformed features

Return type:

pandas.DataFrame

predspot.utilities.contour_geojson(y, bbox, resolution, cmin, cmax, debug=False)[source]

Generate GeoJSON contours from spatial data.

Parameters:
  • y (pandas.Series) – Values to contour

  • bbox (GeoDataFrame) – Bounding box for the contour

  • resolution (float) – Spatial resolution in kilometers

  • cmin (float) – Minimum contour value

  • cmax (float) – Maximum contour value

  • debug (bool, optional) – Enable debug printing. Defaults to False

Returns:

GeoJSON representation of the contours

Return type:

dict

Raises:

AssertionError – If bbox is not a GeoDataFrame