Skip to content

Commit

Permalink
update strat analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason T Holt committed Jan 16, 2024
1 parent 8296722 commit 08331ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
31 changes: 31 additions & 0 deletions coast/data/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from pathlib import Path
import pandas as pd

import os


class Profile(Indexed):
"""
Expand Down Expand Up @@ -154,7 +156,36 @@ def subset_indices_lonlat_box(self, lonbounds, latbounds):
self.dataset.longitude, self.dataset.latitude, lonbounds[0], lonbounds[1], latbounds[0], latbounds[1]
)
return Profile(dataset=self.dataset.isel(id_dim=ind[0]))
def extract_en4_profiles(self, dataset_names, region_bounds):
"""
Helper method to load EN4 data file, subset by region and process.
Args:
dataset_names: list of file names.
region_bounds: [lon min, lon max, lat min lat max]
config : a configuration file (optional)
"""
x_min = region_bounds[0]
x_max = region_bounds[1]
y_min = region_bounds[2]
y_max = region_bounds[3]
#self.profile = Profile(config=config)
self.read_en4(dataset_names, multiple=True)
pr = self.subset_indices_lonlat_box(lonbounds=[x_min, x_max], latbounds=[y_min, y_max])
pr= pr.process_en4()
return pr
@staticmethod
def make_filenames(path, dataset, yr_start, yr_stop):
if dataset == "EN4":
dataset_names = []
january = 1
december = 13 # range is non-inclusive so we need 12 + 1
for yr in range(yr_start, yr_stop + 1):
for im in range(january, december):
name = os.path.join(path, f"EN.4.2.1.f.profiles.l09.{yr}{im:02}.nc")
dataset_names.append(name)
return dataset_names
print("Data set not coded")
"""======================= Plotting ======================="""

def plot_profile(self, var: str, profile_indices=None):
Expand Down
2 changes: 1 addition & 1 deletion coast/diagnostics/profile_hydrographic_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def grid_hydro_mnth(self):

###############################################################################
@staticmethod
def makefilenames(path, dataset, yr_start, yr_stop):
def make_filenames(path, dataset, yr_start, yr_stop):
if dataset == "EN4":
dataset_names = []
january = 1
Expand Down
2 changes: 2 additions & 0 deletions coast/diagnostics/profile_stratification.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ 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)

def quick_plot(self, var: xr.DataArray = None):
"""
Expand Down

0 comments on commit 08331ff

Please sign in to comment.