def get_dynamic_datasets_in_timerange(self, datasets, time_min, time_max): assert (isinstance(time_min, np.datetime64)) assert (isinstance(time_max, np.datetime64)) # find valid time stamps in range mask = np.logical_and(time_min <= self._valid_times, self._valid_times <= time_max) idxs = np.argwhere(mask).flatten().astype(np.int32) # remove duplicate time stamps valid_times = self._valid_times[idxs] valid_times, valid_idxs = np.unique(valid_times, return_index=True) idxs = idxs[valid_idxs] result = [] # find all grids contained in dynamic variables grids_contained = [ d for d in datasets if d in self._dynamic_datasets.keys() ] if len(grids_contained) > 0: progress = ProgressBar(len(grids_contained)) print( "[INFO]: Load dynamic grids <{}> for <{}> in time range ({} - {}) ..." .format(grids_contained, self.area, time_min, time_max)) progress.proceed(0) for i, grid in enumerate(grids_contained): # if grid in self._dynamic_datasets.keys(): selected_grids = self._dynamic_datasets[grid] result += [selected_grids[idxs]] progress.proceed(i + 1) return np.array(result), self._valid_times[idxs], grids_contained
def get_static_datasets(self, datasets, raw=False): assert isinstance(datasets, (list, str)) if not isinstance(datasets, list): datasets = [datasets] result = [] grids_contained = [ d for d in datasets if d in self._static_datasets.keys() ] if len(grids_contained) > 0: progress = ProgressBar(len(grids_contained)) print("[INFO]: Load static grids <{}> for <{}> ...".format( grids_contained, self.area)) progress.proceed(0) for i, grid_name in enumerate(grids_contained): if grid_name == 'seaMask': lsm = self._static_datasets[grid_name] if not raw: lsm = (np.array(lsm) > 0.5).astype(np.float32) result += [lsm] else: result += [self._static_datasets[grid_name]] progress.proceed(i + 1) return np.array(result), grids_contained