cybench.util package

Submodules

cybench.util.data module

cybench.util.data.data_to_pandas(data_items)

Convert data items as dict to pandas DataFrame

Parameters:

data_items – list of data items, each of which is a dict

Returns:

pd.DataFrame

cybench.util.data.flatten_nested_dict(d, parent_key='', sep='.')
cybench.util.data.generate_settings(param_space: dict, standard_settings: dict)
cybench.util.data.unflatten_nested_dict(d, sep='.')
cybench.util.data.update_settings(new_settings: dict, standard_settings: dict)

cybench.util.features module

cybench.util.features._add_period(df, period_length)

Add a period column.

Parameters:
  • df – pd.DataFrame

  • period_length – string, which can be “month”, “fortnight” or “dekad”

Returns:

pd.DataFrame

cybench.util.features._aggregate_by_period(df, index_cols, period_col, aggrs, ft_cols)

Aggregate data into features by period.

Parameters:
  • df – pd.DataFrame

  • index_cols – list of indices, which are location and year

  • period_col – string, column added by add_period()

  • aggrs – dict containing columns to aggregate (keys) and corresponding aggregation function (values)

  • ft_cols – dict for renaming columns to feature columns

Returns:

pd.DataFrame with features

cybench.util.features._count_threshold(df, index_cols, period_col, indicator, threshold_exceed=True, threshold=0.0, ft_name=None)

Aggregate data into features by period.

Parameters:
  • df – pd.DataFrame

  • index_cols – list of indices, which are location and year

  • period_col – string, column added by add_period()

  • indicator – string, indicator column to aggregate

  • threshold_exceed – boolean

  • threshold – float

  • ft_name – string name for aggregated indicator

Returns:

pd.DataFrame with features

cybench.util.features.dekad_from_date(date_str)

Get the dekad number from date.

Parameters:

date_str – date string in YYYYmmdd format

Returns:

Dekad number, e.g. “YYYY0101” to “YYYY010” -> 1,

”YYYY0111” to “YYYY0120” -> 2, “YYYY0121” to “YYYY0131” -> 3

cybench.util.features.design_features(crop, weather_df, soil_df, fpar_df, ndvi_df, soil_moisture_df)

Design features based domain expertise.

Parameters:
  • crop – crop name, e.g. maize

  • weather_df – pd.DataFrame, weather variables

  • soil_df – pd.DataFrame, soil properties

  • fpar_df – pd.DataFrame, fraction of absorbed photosynthetically active radiation

  • ndvi_df – pd.DataFrame, normalized difference vegetation index

  • et0_df – pd.DataFrame, potential evapotraspiration

  • soil_moisture_df – pd.DataFrame, soil moisture (surface and root zone)

Returns:

pd.DataFrame of features

cybench.util.features.fortnight_from_date(date_str)

Get the fortnight number from date.

Parameters:

date_str – date string in YYYYmmdd format

Returns:

Fortnight number, “YYYY0101” to “YYYY0115” -> 1.

cybench.util.features.growing_degree_days(df, tbase)
cybench.util.features.unpack_time_series(df, indicators)

Unpack time series from lists into separate rows by date.

Parameters:
  • df – pd.DataFrame

  • indicators – list of indicators to unpack

Returns:

pd.DataFrame

cybench.util.torch module

cybench.util.torch.batch_tensors(*ts)

Module contents