diff --git a/coast/data/profile.py b/coast/data/profile.py index 99f4cf68..00b83e58 100644 --- a/coast/data/profile.py +++ b/coast/data/profile.py @@ -172,8 +172,9 @@ def extract_en4_profiles(self, dataset_names, region_bounds,chunks: dict = {}): #self.profile = Profile(config=config) self.read_en4(dataset_names, multiple=True, chunks = chunks) pr = self.subset_indices_lonlat_box(lonbounds=[x_min, x_max], latbounds=[y_min, y_max]) - pr= pr.process_en4() + pr = pr.process_en4() return pr + @staticmethod def make_filenames(path, dataset, yr_start, yr_stop): if dataset == "EN4": @@ -186,6 +187,7 @@ def make_filenames(path, dataset, yr_start, yr_stop): dataset_names.append(name) return dataset_names print("Data set not coded") + """======================= Plotting =======================""" def plot_profile(self, var: str, profile_indices=None): diff --git a/coast/diagnostics/gridded_monthly_hydrographic_climatology.py b/coast/diagnostics/gridded_monthly_hydrographic_climatology.py index 6d62c998..fb25f03c 100644 --- a/coast/diagnostics/gridded_monthly_hydrographic_climatology.py +++ b/coast/diagnostics/gridded_monthly_hydrographic_climatology.py @@ -29,11 +29,11 @@ def __init__(self, gridded_t, z_max=200.0): def calc_climatologies(self): """ - Calculate the climatologies for SSH, sss and pea. + Calculate the climatologies for SSH, sss and pea. - Returns: -# gridded_t: Gridded dataset object. - dataset: Gridded dataset object containing monthly climatologies + Returns: + # gridded_t: Gridded dataset object. + dataset: Gridded dataset object containing monthly climatologies """ # calculate a depth mask @@ -49,7 +49,6 @@ def calc_climatologies(self): pea_monthy_clim = np.zeros((12, ny, nx)) try: - nyear = int(nt / 12) # hard wired for monthly data starting in Jan for iy in range(nyear): print("Calc pea", iy) @@ -63,7 +62,7 @@ def calc_climatologies(self): pea.calc_pea(gridded_t2, zd_mask) pea_monthy_clim[im, :, :] = pea_monthy_clim[im, :, :] + pea.dataset["PEA"].values pea_monthy_clim = pea_monthy_clim / nyear - + except Exception as error: (warn(f"Unable to perform pea calculation. Please check the error {error}")) debug(f"Unable to perform pea calculation. Please check the error {error}") @@ -89,17 +88,17 @@ def calc_climatologies(self): attributes_sst = {"units": "o^C", "standard name": "Conservative Sea Surface Temperature"} attributes_sss = {"units": "", "standard name": "Absolute Sea Surface Salinity"} attributes_pea = {"units": "Jm^-3", "standard name": "Potential Energy Anomaly to " + str(self.z_max) + "m"} -#jth this adds the new variables to the full data set, which makes saving difficult, easier just to keep the new variables in seperate object -# self.dataset = self.gridded_t.dataset["sst_monthy_clim"] = xr.DataArray( -# np.squeeze(sst_monthy_clim), coords=coords, dims=dims, attrs=attributes_sst -# ) -# self.gridded_t.dataset["sss_monthy_clim"] = xr.DataArray( -# np.squeeze(sss_monthy_clim), coords=coords, dims=dims, attrs=attributes_sss -# ) -# self.gridded_t.dataset["pea_monthy_clim"] = xr.DataArray( -# np.squeeze(pea_monthy_clim), coords=coords, dims=dims, attrs=attributes_pea -# ) -# self.dataset = self.gridded_t.dataset + # jth this adds the new variables to the full data set, which makes saving difficult, easier just to keep the new variables in seperate object + # self.dataset = self.gridded_t.dataset["sst_monthy_clim"] = xr.DataArray( + # np.squeeze(sst_monthy_clim), coords=coords, dims=dims, attrs=attributes_sst + # ) + # self.gridded_t.dataset["sss_monthy_clim"] = xr.DataArray( + # np.squeeze(sss_monthy_clim), coords=coords, dims=dims, attrs=attributes_sss + # ) + # self.gridded_t.dataset["pea_monthy_clim"] = xr.DataArray( + # np.squeeze(pea_monthy_clim), coords=coords, dims=dims, attrs=attributes_pea + # ) + # self.dataset = self.gridded_t.dataset self.dataset["sst_monthy_clim"] = xr.DataArray( np.squeeze(sst_monthy_clim), coords=coords, dims=dims, attrs=attributes_sst ) diff --git a/coast/diagnostics/profile_stratification.py b/coast/diagnostics/profile_stratification.py index 5ddad65a..b6907b0d 100644 --- a/coast/diagnostics/profile_stratification.py +++ b/coast/diagnostics/profile_stratification.py @@ -199,8 +199,12 @@ def calc_pea(self, profile: xr.Dataset, gridded: xr.Dataset, Zmax): dims = ["id_dim"] attributes = {"units": "J / m^3", "standard_name": "Potential Energy Anomaly"} self.dataset["pea"] = xr.DataArray(pot_energy_anom, coords=coords, dims=dims, attrs=attributes) - self.dataset["sst"] = xr.DataArray(profile.dataset.variables["sea_surface_temperature"], coords=coords, dims=dims, attrs=attributes) - self.dataset["sss"] = xr.DataArray(profile.dataset.variables["sea_surface_salinity"], coords=coords, dims=dims, attrs=attributes) + self.dataset["sst"] = xr.DataArray( + profile.dataset.variables["sea_surface_temperature"], coords=coords, dims=dims, attrs=attributes + ) + self.dataset["sss"] = xr.DataArray( + profile.dataset.variables["sea_surface_salinity"], coords=coords, dims=dims, attrs=attributes + ) def quick_plot(self, var: xr.DataArray = None): """ @@ -313,4 +317,4 @@ def distance_on_grid(Y, X, jpts, ipts, Ypts, Xpts): DX = (Xpts - X[jpts, ipts]) * earth_radius * np.cos(Ypts * np.pi / 180.0) DY = (Ypts - Y[jpts, ipts]) * earth_radius r = np.sqrt(DX**2 + DY**2) - return r \ No newline at end of file + return r