Skip to content

Commit

Permalink
Merge branch 'feature/535_stratification_diag' of github.com:British-…
Browse files Browse the repository at this point in the history
…Oceanographic-Data-Centre/COAsT into feature/535_stratification_diag

Conflicts:
	coast/data/profile.py
  • Loading branch information
jasontempestholt committed Jan 19, 2024
2 parents 4d3d54c + e4153bf commit e4d4ad7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
4 changes: 3 additions & 1 deletion coast/data/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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):
Expand Down
33 changes: 16 additions & 17 deletions coast/diagnostics/gridded_monthly_hydrographic_climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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}")
Expand All @@ -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
)
Expand Down
10 changes: 7 additions & 3 deletions coast/diagnostics/profile_stratification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
return r

0 comments on commit e4d4ad7

Please sign in to comment.