diff --git a/spatio_temporal_dataset/spatio_temporal_observations/abstract_spatio_temporal_observations.py b/spatio_temporal_dataset/spatio_temporal_observations/abstract_spatio_temporal_observations.py index a5845546afcbc809b52bdd3b748678c5623d1c83..8c1890b5a2ddf1e7e1b13b3ce25be388a6364314 100644 --- a/spatio_temporal_dataset/spatio_temporal_observations/abstract_spatio_temporal_observations.py +++ b/spatio_temporal_dataset/spatio_temporal_observations/abstract_spatio_temporal_observations.py @@ -19,6 +19,12 @@ class AbstractSpatioTemporalObservations(object): Main attribute of the class is the DataFrame df_maxima Index are coordinates index Columns are independent observations from the same coordinates index + + For example, if we have spatial coordinates, + then all the columns might correspond to annual maxima observations for different years + + If we have a spatio-temporal coordinates, + then all the columns might correspond to observations that were made at some spatial coodinate, and for some given year """ assert df_maxima_gev is not None or df_maxima_frech is not None assert isinstance(df_maxima_gev, pd.DataFrame) or isinstance(df_maxima_frech, pd.DataFrame) @@ -27,13 +33,6 @@ class AbstractSpatioTemporalObservations(object): self.df_maxima_gev = df_maxima_gev # type: pd.DataFrame self.df_maxima_frech = df_maxima_frech # type: pd.DataFrame - @classmethod - def from_csv(cls, csv_path: str = None): - assert csv_path is not None - assert op.exists(csv_path) - df = pd.read_csv(csv_path, index_col=0) - return cls.from_df(df) - @property def _df_maxima(self) -> pd.DataFrame: if self.df_maxima_frech is not None: @@ -70,22 +69,6 @@ class AbstractSpatioTemporalObservations(object): def nb_obs(self) -> int: return len(self.columns) - @classmethod - def from_df(cls, df): - df_maxima_list = [] - for suffix in [cls.OBSERVATIONS_GEV, cls.OBSERVATIONS_FRECH]: - columns_with_suffix = [c for c in df.columns if str(c).endswith(suffix)] - if columns_with_suffix: - df_maxima = df[columns_with_suffix] if columns_with_suffix else None - df_maxima.columns = [c.replace(' ' + suffix, '') for c in df_maxima.columns] - else: - df_maxima = None - df_maxima_list.append(df_maxima) - df_maxima_gev, df_maxima_frech = df_maxima_list - if df_maxima_gev is not None and df_maxima_frech is not None: - assert pd.Index.equals(df_maxima_gev.columns, df_maxima_frech.columns) - return cls(df_maxima_gev=df_maxima_gev, df_maxima_frech=df_maxima_frech) - def convert_to_spatio_temporal_index(self, coordinates: AbstractCoordinates): assert coordinates.has_spatio_temporal_coordinates assert len(coordinates.index) == len(self.index) * self.nb_obs @@ -130,9 +113,6 @@ class AbstractSpatioTemporalObservations(object): def __str__(self) -> str: return self._df_maxima.__str__() - def __len__(self): - return self._df_maxima.__len__() - def print_summary(self): # Write a summary of observations df = self.df_maxima_gev diff --git a/spatio_temporal_dataset/spatio_temporal_observations/alps_precipitation_observations.py b/spatio_temporal_dataset/spatio_temporal_observations/alps_precipitation_observations.py deleted file mode 100644 index 83ead9544aba119a5d350bf4af807c8bfc350aa4..0000000000000000000000000000000000000000 --- a/spatio_temporal_dataset/spatio_temporal_observations/alps_precipitation_observations.py +++ /dev/null @@ -1,36 +0,0 @@ -import os.path as op - -from spatio_temporal_dataset.spatio_temporal_observations.abstract_spatio_temporal_observations import \ - AbstractSpatioTemporalObservations -from root_utils import get_full_path - - -class AlpsPrecipitationObservations(AbstractSpatioTemporalObservations): - RELATIVE_PATH = r'local/spatio_temporal_datasets/Gilles - precipitations' - FULL_PATH = get_full_path(relative_path=RELATIVE_PATH) - - @classmethod - def from_csv(cls, csv_file='max_precip_3j'): - csv_path = op.join(cls.FULL_PATH, csv_file + '.csv') - return super().from_csv(csv_path) - - @classmethod - def transform_gilles_txt_into_csv(cls): - filepath = op.join(cls.FULL_PATH, 'original data', 'max_precip_3j.txt') - station_to_coordinates = {} - # todo: be absolutely sure of the mapping, in the txt file of Gilles we do not have the coordinate - # this seems rather dangerous, especially if he loaded - # todo: re-do the whole analysis, and extraction myself about the snow - with open(filepath, 'r') as f: - for l in f: - _, station_name, coordinates = l.split('"') - coordinates = coordinates.split() - print(len(coordinates)) - assert len(coordinates) == 55 - station_to_coordinates[station_name] = coordinates - # df = pd.DataFrame.from_dict(data=station_to_coordinates, orient='index', - # columns=[cls.COORDINATE_X, cls.COORDINATE_Y, cls.COORDINATE_Z]) - # print(df.head()) - # filepath = op.join(cls.FULL_PATH, 'max_precip_3j.csv') - # assert not op.exists(filepath) - # df.to_csv(filepath)