Skip to content

Commit

Permalink
Bug fixes to cleaning data - need to check this works ok. Update to n…
Browse files Browse the repository at this point in the history
…otebook to test this
  • Loading branch information
jasontempestholt committed Oct 20, 2023
1 parent 6463a6b commit ebe6951
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 85 deletions.
15 changes: 9 additions & 6 deletions coast/diagnostics/profile_stratification.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, profile: xr.Dataset):
self.nz = profile.dataset.dims["z_dim"]
debug(f"Initialised {get_slug(self)}")

def clean_data(self,profile: xr.Dataset, gridded: xr.Dataset, Zmax):
def clean_data(profile: xr.Dataset, gridded: xr.Dataset, Zmax):
"""
Cleaning data for stratification metric calculations
Stage 1:...
Expand Down Expand Up @@ -96,6 +96,9 @@ def first_nonzero(arr, axis=0, invalid_val=np.nan):
good_profile[test] = 0

###
else:
print('error no bathy provided, cant clean the data')
return profile
SST = np.zeros(n_prf) * np.nan
SSS = np.zeros(n_prf) * np.nan

Expand Down Expand Up @@ -129,14 +132,14 @@ def first_nonzero(arr, axis=0, invalid_val=np.nan):
dims = ["id_dim", "z_dim"]
profile.dataset["potential_temperature"] = xr.DataArray(tmp_clean, coords=coords, dims=dims)
profile.dataset["practical_salinity"] = xr.DataArray(sal_clean, coords=coords, dims=dims)
self.dataset["sea_surface_temperature"] = xr.DataArray(SST, coords=coords, dims=["id_dim"])
self.dataset["sea_surface_salinity"] = xr.DataArray(SSS, coords=coords, dims=["id_dim"])
self.dataset["good_profile"] = xr.DataArray(good_profile, coords=coords, dims=["id_dim"])
profile.dataset["sea_surface_temperature"] = xr.DataArray(SST, coords=coords, dims=["id_dim"])
profile.dataset["sea_surface_salinity"] = xr.DataArray(SSS, coords=coords, dims=["id_dim"])
profile.dataset["good_profile"] = xr.DataArray(good_profile, coords=coords, dims=["id_dim"])
print("All nice and clean")
#%%
return profile

def calc_pea(self, profile: xr.Dataset, gridded, Zmax):
def calc_pea(self, profile: xr.Dataset, gridded: xr.Dataset, Zmax):
"""
Calculates Potential Energy Anomaly
Expand All @@ -150,7 +153,7 @@ def calc_pea(self, profile: xr.Dataset, gridded, Zmax):
# %%
gravity = 9.81
# Clean data This is quit slow and over writes potential temperature and practical salinity variables
#profile = ProfileStratification.clean_data(profile, gridded, Zmax)
profile = ProfileStratification.clean_data(profile, gridded, Zmax)

# Define grid spacing, dz. Required for depth integral
profile.calculate_vertical_spacing()
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example_scripts/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
fn_grd_dom = "example_files/coast_example_nemo_domain.nc"
fn_grd_cfg = "config/example_nemo_grid_t.json"
nemo = coast.Gridded(fn_domain=fn_grd_dom, config=fn_grd_cfg)
profile.match_to_grid(nemo)
profile.gridded_to_profile_2d(nemo, "bathymetry")
#profile.match_to_grid(nemo)
#profile.gridded_to_profile_2d(nemo, "bathymetry")

Zmax = 200 # metres
pa.calc_pea(profile, nemo, Zmax)

0 comments on commit ebe6951

Please sign in to comment.