@@ -33,7 +33,12 @@ def __init__(self, tw_handler: TimeWindowHandler, filename: Path, stream_info: d
3333 self .z = zarr .open (filename , mode = "r" )
3434 self .data = self .z ["data" ]
3535 self .dt = self .z ["dates" ] # datetime only
36- self .hrly_index = self .z ["idx_197001010000_1" ]
36+ self .base_datetime = stream_info .get ("base_datetime" , "1970-01-01T00:00:00" )
37+ format_str = "%Y-%m-%dT%H:%M:%S"
38+ self .base_datetime = datetime .datetime .strptime (str (self .base_datetime ), format_str )
39+ # To read idx convert to a string, format e.g.: 197001010000
40+ base_date_str = self .base_datetime .strftime ("%Y%m%d%H%M" )
41+ self .hrly_index = self .z [f"idx_{ base_date_str } _1" ]
3742 self .colnames = self .data .attrs ["colnames" ]
3843
3944 data_colnames = [col for col in self .colnames if "obsvalue" in col ]
@@ -63,7 +68,7 @@ def __init__(self, tw_handler: TimeWindowHandler, filename: Path, stream_info: d
6368 self .geoinfo_idx = list (range (self .coords_idx [- 1 ] + 1 , data_idx [0 ]))
6469 self .geoinfo_channels = [self .colnames [i ] for i in self .geoinfo_idx ]
6570
66- # load additional properties (mean, var, obs_id )
71+ # load additional properties (mean, var)
6772 self ._load_properties ()
6873 self .mean = np .array (self .properties ["means" ]) # [data_idx]
6974 self .stdev = np .sqrt (np .array (self .properties ["vars" ])) # [data_idx])
@@ -140,19 +145,13 @@ def _setup_sample_index(self) -> None:
140145 )
141146 step_hrs = int (self .time_window_handler .t_window_step .item ().total_seconds ()) // 3600
142147
143- # TODO: move to ctor
144- base_yyyymmddhhmm = 197001010000
145-
146- # Derive new index based on hourly backbone index
147- format_str = "%Y%m%d%H%M%S"
148- base_dt = datetime .datetime .strptime (str (base_yyyymmddhhmm ), format_str )
149148 self .start_dt = self .time_window_handler .t_start .item ()
150149 self .end_dt = self .time_window_handler .t_end .item ()
151150
152151 ## Calculate the number of hours between start of hourly base index
153152 # and the requested sample index
154- diff_in_hours_start = int ((self .start_dt - base_dt ).total_seconds () / 3600 )
155- diff_in_hours_end = int ((self .end_dt - base_dt ).total_seconds () / 3600 )
153+ diff_in_hours_start = int ((self .start_dt - self . base_datetime ).total_seconds () / 3600 )
154+ diff_in_hours_end = int ((self .end_dt - self . base_datetime ).total_seconds () / 3600 )
156155
157156 end_range_1 = min (diff_in_hours_end , self .hrly_index .shape [0 ] - 1 )
158157 self .indices_start = self .hrly_index [diff_in_hours_start :end_range_1 :step_hrs ]
@@ -201,7 +200,6 @@ def _load_properties(self) -> None:
201200
202201 self .properties ["means" ] = self .data .attrs ["means" ]
203202 self .properties ["vars" ] = self .data .attrs ["vars" ]
204- self .properties ["obs_id" ] = self .data .attrs ["obs_id" ]
205203
206204 @override
207205 def _get (self , idx : int , channels_idx : list [int ]) -> ReaderData :
0 commit comments