Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions CrocoDash/raw_data_access/datasets/glorys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pandas as pd
from .utils import convert_lons_to_180_range
from CrocoDash.raw_data_access.base import *
from mom6_forge.utils import longitude_slicer


class GLORYS(ForcingProduct):
Expand Down Expand Up @@ -75,9 +76,6 @@ def get_glorys_data_from_rda(
ds_in_files = []
date_strings = [date.strftime("%Y%m%d") for date in dates]

# Adjust lat lon inputs to make sure they are in the correct range of -180 to 180
lon_min, lon_max = convert_lons_to_180_range(lon_min, lon_max)

for date in date_strings:
pattern = os.path.join(ds_in_path, "**", f"*_{date}_*.nc")
ds_in_files.extend(glob.glob(pattern, recursive=True))
Expand All @@ -87,30 +85,11 @@ def get_glorys_data_from_rda(
ds_in_files, decode_times=False, engine="h5netcdf", parallel=True
)[variables]

if lon_min * lon_max > 0:
dataset = ds.sel(
latitude=slice(lat_min - 1, lat_max + 1),
longitude=slice(lon_min - 1, lon_max + 1),
)
else:
dataset = xr.concat(
[
ds.sel(
latitude=slice(lat_min - 1, lat_max + 1),
**{"longitude": slice(lon_min - 1, 360)},
),
ds.sel(
latitude=slice(lat_min - 1, lat_max + 1),
**{"longitude": slice(-180, lon_max + 1)},
),
],
dim="longitude",
)

# convert longitude from degree west to degree east
dataset["longitude"] = (360 - dataset["longitude"]) % 360
dataset = dataset.sortby("longitude")
buf = 1.0 # buffer in degrees to ensure we have enough data for interpolation at the boundaries

dataset = longitude_slicer(
ds, [lon_min - buf, lon_max + buf], longitude_coords="longitude"
)
dataset.to_netcdf(path)
return path

Expand Down
2 changes: 1 addition & 1 deletion CrocoDash/visualCaseGen
Loading