Skip to content

Commit 70e6514

Browse files
working on it
1 parent c790545 commit 70e6514

7 files changed

Lines changed: 46 additions & 45 deletions

File tree

cybench/datasets/alignment.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ def align_inputs_and_labels(df_y: pd.DataFrame, dfs_x: dict) -> tuple:
383383
index_y_selection = set(df_y.index.values)
384384

385385
for df_x in dfs_x.values():
386-
#print(df_x.head(), len(index_y_selection))
387386
if len(df_x.index.names) == 1:
388387
index_y_selection = {
389388
(loc_id, year)
@@ -483,42 +482,42 @@ def interpolate_time_series_data_items(X: list, max_season_window_length: int):
483482
return df_ts
484483

485484

486-
def aggregate_time_series_data(df_ts: pd.DataFrame, aggregate_time_series_to: str):
487-
"""Aggregate time series data to the specified resolution.
488-
489-
Args:
490-
df_ts (pd.DataFrame): time series data in daily resolution
491-
aggregate_time_series_to (str): resolution of aggregated data
492-
493-
Returns:
494-
pd.DataFrame with interpolated data
495-
"""
496-
if aggregate_time_series_to not in ["week", "dekad"]:
497-
raise Exception(
498-
f"Unsupported time series aggregation resolution {aggregate_time_series_to}"
499-
)
500-
501-
if "date" not in df_ts.columns:
502-
assert "date" in df_ts.index.names
503-
df_ts.reset_index(inplace=True)
504-
505-
assert "date" in df_ts.columns
506-
if aggregate_time_series_to == "week":
507-
df_ts["week"] = df_ts["date"].dt.isocalendar().week
508-
else:
509-
df_ts["dekad"] = df_ts.apply(lambda r: dekad_from_date(r["date"]), axis=1)
510-
511-
ts_aggrs = {k: TIME_SERIES_AGGREGATIONS[k] for k in TIME_SERIES_PREDICTORS}
512-
# Primarily to avoid losing the "date" column.
513-
ts_aggrs["date"] = "min"
514-
df_ts = (
515-
df_ts.groupby([KEY_LOC, KEY_YEAR, aggregate_time_series_to], observed=True)
516-
.agg(ts_aggrs)
517-
.reset_index()
518-
)
519-
df_ts.drop(columns=[aggregate_time_series_to], inplace=True)
520-
521-
return df_ts
485+
# def aggregate_time_series_data(df_ts: pd.DataFrame, aggregate_time_series_to: str):
486+
# """Aggregate time series data to the specified resolution.
487+
#
488+
# Args:
489+
# df_ts (pd.DataFrame): time series data in daily resolution
490+
# aggregate_time_series_to (str): resolution of aggregated data
491+
#
492+
# Returns:
493+
# pd.DataFrame with interpolated data
494+
# """
495+
# if aggregate_time_series_to not in ["week", "dekad"]:
496+
# raise Exception(
497+
# f"Unsupported time series aggregation resolution {aggregate_time_series_to}"
498+
# )
499+
#
500+
# if "date" not in df_ts.columns:
501+
# assert "date" in df_ts.index.names
502+
# df_ts.reset_index(inplace=True)
503+
#
504+
# assert "date" in df_ts.columns
505+
# if aggregate_time_series_to == "week":
506+
# df_ts["week"] = df_ts["date"].dt.isocalendar().week
507+
# else:
508+
# df_ts["dekad"] = df_ts.apply(lambda r: dekad_from_date(r["date"]), axis=1)
509+
#
510+
# ts_aggrs = {k: TIME_SERIES_AGGREGATIONS[k] for k in TIME_SERIES_PREDICTORS}
511+
# # Primarily to avoid losing the "date" column.
512+
# ts_aggrs["date"] = "min"
513+
# df_ts = (
514+
# df_ts.groupby([KEY_LOC, KEY_YEAR, aggregate_time_series_to], observed=True)
515+
# .agg(ts_aggrs)
516+
# .reset_index()
517+
# )
518+
# df_ts.drop(columns=[aggregate_time_series_to], inplace=True)
519+
#
520+
# return df_ts
522521

523522

524523
def make_aligned_tensors(

cybench/datasets/data_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def build(self) -> Dataset:
8989
)
9090

9191
# Caching Strategy: Save result
92-
if use_cache:
92+
if use_cache: #Torch?!
9393
torch.save(dataset, cache_path)
9494

9595
return dataset

cybench/datasets/features.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ def design_features(
284284
# Add location features if available
285285
if "location" in input_dfs:
286286
location_df = input_dfs["location"]
287-
# Apply spherical transformations to geographic coordinates
288-
spherical_features = {"lat_lon": {"lat": [-90, 90], "lon": [-180, 180]}}
289-
location_df = apply_spherical_transformations(location_df, spherical_features)
287+
# # Apply spherical transformations to geographic coordinates
288+
# spherical_features = {"lat_lon": {"lat": [-90, 90], "lon": [-180, 180]}}
289+
# location_df = apply_spherical_transformations(location_df, spherical_features)
290290
soil_features = soil_features.merge(location_df, on=[KEY_LOC], how="left")
291291

292292
# Feature design for time series

cybench/datasets/normalizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def fit_normalize(self, dfs):
9999
return self.normalize(dfs)
100100

101101
def normalize(self, dfs):
102+
### WARNING: this is done in-place
102103
"""
103104
Normalize using already-fitted parameters.
104105
Returns new list of DataFrames.

cybench/datasets/torch_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __len__(self) -> int:
3737
"""Return the total number of samples in the dataset."""
3838
return len(self.y)
3939

40-
def __getitem__(self, index: int) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
40+
def __getitem__(self, index: int) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
4141
"""
4242
Get a sample from the dataset.
4343
@@ -51,7 +51,7 @@ def split_on_years(
5151
) -> Tuple['TorchDataset', 'TorchDataset']:
5252
"""
5353
Create two new datasets based on the provided split in years.
54-
!!NOTE!!: This is a memory intensive operation, because its making two subsets by copying the original data.
54+
!!NOTE!!: This is a memory intensive operation, because it's making two subsets by copying the original data.
5555
Future implementations might want to rely on more memory-efficiency, in case that becomes a bottleneck.
5656
5757
:param years_split: Tuple of two lists, e.g., ([2012, 2014], [2015, 2017])

cybench/util/store_and_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import os
99

1010
from cybench.datasets.dataset import Dataset
11-
from cybench.datasets.torch_dataset import TorchDataset
11+
from cybench.config import DatasetConfig
1212

1313

14-
def cfg_to_hash(cfg: OmegaConf, add_str: bool = True):
14+
def cfg_to_hash(cfg: DatasetConfig, add_str: bool = True):
1515
"""
1616
Create a deterministic hash from a DatasetConfig, to use it as a keys e.g. in caching
1717

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fastcore = "1.7.29"
3535
hydra-core = "^1.3.2"
3636
optuna = "^4.5.0"
3737
codecarbon = "^3.2.0"
38+
omegaconf = "^2.3.0"
3839

3940

4041
[build-system]

0 commit comments

Comments
 (0)