def define_coordinates(self): ds = return_xarray_dataset(self.keymap_files['coordinate_file']) ds = self.change_dimensions(ds) ds = self.change_coords(ds) self.dscoord = ds lon_r = self._get(self.dscoord, 'lon_r', chunks=self.chunks, decode_times=False).values lat_r = self._get(self.dscoord, 'lat_r', chunks=self.chunks, decode_times=False).values self.coords['lon_r'] = lon_r self.coords['lat_r'] = lat_r self.coords['lon_u'] = 0.5 * (lon_r[:, :-1] + lon_r[:, 1:]) self.coords['lat_u'] = 0.5 * (lat_r[:, :-1] + lat_r[:, 1:]) self.coords['lon_v'] = 0.5 * (lon_r[:-1, :] + lon_r[1:, :]) self.coords['lat_v'] = 0.5 * (lat_r[:-1, :] + lat_r[1:, :]) self.coords['lon_w'] = lon_r self.coords['lat_w'] = lat_r # time = time - time_origin self.coords['time'] = self._get(self.dscoord, 'time', chunks=self.chunks, decode_times=False) self.coords['time'] = self.coords['time'] * second2day
def define_coordinates(self): ds = return_xarray_dataset(self.keymap_files['coordinate_file']) ds = self.change_dimensions(ds) ds = self.change_coords(ds) self.dscoord = ds lon_r = self._get(self.dscoord, 'lon_r', chunks=self.chunks, decode_times=False).values lat_r = self._get(self.dscoord, 'lat_r', chunks=self.chunks, decode_times=False).values self.coords['lon_r'] = lon_r self.coords['lat_r'] = lat_r self.coords['lon_u'] = 0.5 * (lon_r[:, :-1] + lon_r[:, 1:]) self.coords['lat_u'] = 0.5 * (lat_r[:, :-1] + lat_r[:, 1:]) self.coords['lon_v'] = 0.5 * (lon_r[:-1, :] + lon_r[1:, :]) self.coords['lat_v'] = 0.5 * (lat_r[:-1, :] + lat_r[1:, :]) self.coords['lon_w'] = lon_r self.coords['lat_w'] = lat_r # time = time - time_origin self.coords['time'] = self._get(self.dscoord, 'time', chunks=self.chunks, decode_times=False) self.coords['time'].values = np.array(self.coords['time'], dtype='datetime64[D]') - \ np.array(self.coords['time'].time_origin, dtype='datetime64[D]') self.coords[ 'time'].values = self.coords['time'].values / np.timedelta64( 1, 'D')
def define_metrics(self): ds = return_xarray_dataset(self.keymap_files['metric_file']) ds = self.change_dimensions(ds) ds = self.change_coords(ds) ds = self.change_metrics(ds) self.dsmetrics = ds for key,val in self.keymap_metrics.items(): self.metrics[val] = self._get(self.dsmetrics,val,chunks=self.chunks)
def define_variables(self): ds = return_xarray_dataset(self.keymap_files['variable_file']) ds = self.change_dimensions(ds) ds = self.change_coords(ds) ds = self.change_variables(ds) # Add ssh as variable # ds = ds.assign(ssh = xr.DataArray(data=np.zeros((self.ntimes,self.M,self.L)),dims=('t','y_r','x_r'))) self.dsvar = ds
def define_masks(self): ds = return_xarray_dataset(self.keymap_files['mask_file']) ds = self.change_dimensions(ds) ds = self.change_coords(ds) ds = self.change_mask(ds) self.dsmask = ds for key,val in self.keymap_masks.items(): try: self.masks[val] = self._get(self.dsmask,val,chunks=self.chunks) except: mask_rho = np.ones_like(self.coords['lon_r']) self.masks[val] = xr.DataArray(data=mask_rho) self.masks[val] = np.where(self.masks[val]==0.,np.nan,self.masks[val])
def define_variables(self): ds = return_xarray_dataset(self.keymap_files['variable_file']) ds = self.change_dimensions(ds) ds = self.change_coords(ds) ds = self.change_variables(ds) self.dsvar = ds