From 3d5bd9b95abb861d43c17e3521e2d01565b388a7 Mon Sep 17 00:00:00 2001 From: manishvenu Date: Tue, 14 Jan 2025 11:22:03 -0700 Subject: [PATCH 1/6] Temp --- CrocoDash/case.py | 16 ++++++++-------- CrocoDash/data_access.py | 0 CrocoDash/visualCaseGen | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 CrocoDash/data_access.py diff --git a/CrocoDash/case.py b/CrocoDash/case.py index 4e89740..2c6885e 100644 --- a/CrocoDash/case.py +++ b/CrocoDash/case.py @@ -255,8 +255,8 @@ def configure_forcings( date_range: list[str], boundaries: list[str] = ["south", "north", "west", "east"], tidal_constituents: list[str] | None = None, - tpxo_elevation_filepath: str | Path | None = None, - tpxo_velocity_filepath: str | Path | None = None, + tidal_elevation_filepath: str | Path | None = None, + tidal_velocity_filepath: str | Path | None = None, ): """Configure the boundary conditions and tides for the MOM6 case.""" @@ -284,14 +284,14 @@ def configure_forcings( self.tidal_constituents = tidal_constituents # all tidal arguments must be provided if any are provided - if any([tidal_constituents, tpxo_elevation_filepath, tpxo_velocity_filepath]): - if not all([tidal_constituents, tpxo_elevation_filepath, tpxo_velocity_filepath]): + if any([tidal_constituents, tidal_elevation_filepath, tidal_velocity_filepath]): + if not all([tidal_constituents, tidal_elevation_filepath, tidal_velocity_filepath]): raise ValueError( "If any tidal arguments are provided, all must be provided." ) self.tidal_constituents = tidal_constituents - self.tpxo_elevation_filepath = Path(tpxo_elevation_filepath) if tpxo_elevation_filepath else None - self.tpxo_velocity_filepath = Path(tpxo_velocity_filepath) if tpxo_velocity_filepath else None + self.tidal_elevation_filepath = Path(tidal_elevation_filepath) if tidal_elevation_filepath else None + self.tidal_velocity_filepath = Path(tidal_velocity_filepath) if tidal_velocity_filepath else None session_id = cvars["MB_ATTEMPT_ID"].value @@ -394,8 +394,8 @@ def process_forcings(self): # Process the tides self.expt.setup_boundary_tides( - tpxo_elevation_filepath=self.tpxo_elevation_filepath, - tpxo_velocity_filepath=self.tpxo_velocity_filepath, + tpxo_elevation_filepath=self.tidal_elevation_filepath, + tpxo_velocity_filepath=self.tidal_velocity_filepath, tidal_constituents=self.tidal_constituents, boundary_type=boundary_type, ) diff --git a/CrocoDash/data_access.py b/CrocoDash/data_access.py new file mode 100644 index 0000000..e69de29 diff --git a/CrocoDash/visualCaseGen b/CrocoDash/visualCaseGen index daf3ade..f59dc70 160000 --- a/CrocoDash/visualCaseGen +++ b/CrocoDash/visualCaseGen @@ -1 +1 @@ -Subproject commit daf3ade1d8eca909bbba4b67fa3d4f570b28286e +Subproject commit f59dc70727fbdf73b906e7ecb87b153a73f02b57 From ed5553a2c370f8628734727e5c29713820c2c6d9 Mon Sep 17 00:00:00 2001 From: manishvenu Date: Wed, 15 Jan 2025 16:38:00 -0700 Subject: [PATCH 2/6] Revert "Temp" This reverts commit 3d5bd9b95abb861d43c17e3521e2d01565b388a7. --- CrocoDash/case.py | 16 ++++++++-------- CrocoDash/data_access.py | 0 CrocoDash/visualCaseGen | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 CrocoDash/data_access.py diff --git a/CrocoDash/case.py b/CrocoDash/case.py index 2c6885e..4e89740 100644 --- a/CrocoDash/case.py +++ b/CrocoDash/case.py @@ -255,8 +255,8 @@ def configure_forcings( date_range: list[str], boundaries: list[str] = ["south", "north", "west", "east"], tidal_constituents: list[str] | None = None, - tidal_elevation_filepath: str | Path | None = None, - tidal_velocity_filepath: str | Path | None = None, + tpxo_elevation_filepath: str | Path | None = None, + tpxo_velocity_filepath: str | Path | None = None, ): """Configure the boundary conditions and tides for the MOM6 case.""" @@ -284,14 +284,14 @@ def configure_forcings( self.tidal_constituents = tidal_constituents # all tidal arguments must be provided if any are provided - if any([tidal_constituents, tidal_elevation_filepath, tidal_velocity_filepath]): - if not all([tidal_constituents, tidal_elevation_filepath, tidal_velocity_filepath]): + if any([tidal_constituents, tpxo_elevation_filepath, tpxo_velocity_filepath]): + if not all([tidal_constituents, tpxo_elevation_filepath, tpxo_velocity_filepath]): raise ValueError( "If any tidal arguments are provided, all must be provided." ) self.tidal_constituents = tidal_constituents - self.tidal_elevation_filepath = Path(tidal_elevation_filepath) if tidal_elevation_filepath else None - self.tidal_velocity_filepath = Path(tidal_velocity_filepath) if tidal_velocity_filepath else None + self.tpxo_elevation_filepath = Path(tpxo_elevation_filepath) if tpxo_elevation_filepath else None + self.tpxo_velocity_filepath = Path(tpxo_velocity_filepath) if tpxo_velocity_filepath else None session_id = cvars["MB_ATTEMPT_ID"].value @@ -394,8 +394,8 @@ def process_forcings(self): # Process the tides self.expt.setup_boundary_tides( - tpxo_elevation_filepath=self.tidal_elevation_filepath, - tpxo_velocity_filepath=self.tidal_velocity_filepath, + tpxo_elevation_filepath=self.tpxo_elevation_filepath, + tpxo_velocity_filepath=self.tpxo_velocity_filepath, tidal_constituents=self.tidal_constituents, boundary_type=boundary_type, ) diff --git a/CrocoDash/data_access.py b/CrocoDash/data_access.py deleted file mode 100644 index e69de29..0000000 diff --git a/CrocoDash/visualCaseGen b/CrocoDash/visualCaseGen index f59dc70..daf3ade 160000 --- a/CrocoDash/visualCaseGen +++ b/CrocoDash/visualCaseGen @@ -1 +1 @@ -Subproject commit f59dc70727fbdf73b906e7ecb87b153a73f02b57 +Subproject commit daf3ade1d8eca909bbba4b67fa3d4f570b28286e From 8c6a1ff7181a0ef69d2912a1b4de9493da05e1fc Mon Sep 17 00:00:00 2001 From: manishvenu Date: Wed, 15 Jan 2025 16:38:16 -0700 Subject: [PATCH 3/6] VCG --- CrocoDash/visualCaseGen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CrocoDash/visualCaseGen b/CrocoDash/visualCaseGen index daf3ade..9a9b906 160000 --- a/CrocoDash/visualCaseGen +++ b/CrocoDash/visualCaseGen @@ -1 +1 @@ -Subproject commit daf3ade1d8eca909bbba4b67fa3d4f570b28286e +Subproject commit 9a9b9063bbb1b1545aebe98f47553e65cec33776 From e23ef21d914e088529bc315226a4924837ba9cc7 Mon Sep 17 00:00:00 2001 From: manishvenu Date: Tue, 21 Jan 2025 10:56:04 -0700 Subject: [PATCH 4/6] Update RM6 Commit --- CrocoDash/rm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CrocoDash/rm6 b/CrocoDash/rm6 index e832983..022dd01 160000 --- a/CrocoDash/rm6 +++ b/CrocoDash/rm6 @@ -1 +1 @@ -Subproject commit e83298369939822d518843364449c1cc9cbac104 +Subproject commit 022dd01ab4f34eb4c2faa5cf654ce94409df59ea From 19a98acb1e4bca4b7c223035e41cf0c958075544 Mon Sep 17 00:00:00 2001 From: manishvenu Date: Wed, 22 Jan 2025 09:40:04 -0700 Subject: [PATCH 5/6] Start Data Access Module --- CrocoDash/data_access.py | 41 +++++++++++++++++++++++++++++++++++++++ tests/test_data_access.py | 20 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 CrocoDash/data_access.py create mode 100644 tests/test_data_access.py diff --git a/CrocoDash/data_access.py b/CrocoDash/data_access.py new file mode 100644 index 0000000..cf5b88b --- /dev/null +++ b/CrocoDash/data_access.py @@ -0,0 +1,41 @@ +""" +Data Access Module -> Query Data Sources like GLORYS & GEBCO +""" +import xarray as xr +import glob +import os +import copernicusmarine + +def get_glorys_data_from_rda(dates: list,lat_min, lat_max, lon_min,lon_max) -> xr.Dataset: + """ + Gather GLORYS Data on Derecho Computers from the campaign storage and return the dataset sliced to the llc and urc coordinates at the specific dates + """ + + # Set + drop_var_lst = ['mlotst','bottomT','sithick','siconc','usi','vsi'] + ds_in_path = '/glade/campaign/cgd/oce/projects/CROCODILE/glorys012/GLOBAL/' + ds_in_files = [] + date_strings = [date.strftime('%Y%m%d') for date in dates] + for date in date_strings: + pattern = os.path.join(ds_in_path, "**",f'*{date}*.nc') + ds_in_files.extend(glob.glob(pattern, recursive=True)) + ds_in_files = sorted(ds_in_files) + dataset = xr.open_mfdataset(ds_in_files,decode_times=False).drop_vars(drop_var_lst).sel(latitude=slice(lat_min,lat_max),longitude=slice(lon_min,lon_max)) + + return dataset + +def get_glorys_data_from_cds_api(dates: tuple, lat_min, lat_max, lon_min, lon_max) -> xr.Dataset: + """ + Using the copernucismarine api, query GLORYS data + """ + ds = copernicusmarine.open_dataset( + dataset_id = 'cmems_mod_glo_phy_my_0.083deg_P1D-m', + minimum_longitude = lon_min, + maximum_longitude = lon_max, + minimum_latitude = lat_min, + maximum_latitude = lat_max, + start_datetime = dates[0], + end_datetime = dates[1], + variables=["uo","vo","thetao","so","zos"], + ) + return ds \ No newline at end of file diff --git a/tests/test_data_access.py b/tests/test_data_access.py new file mode 100644 index 0000000..923dd41 --- /dev/null +++ b/tests/test_data_access.py @@ -0,0 +1,20 @@ +from CrocoDash import data_access as da +import pandas as pd + +def test_get_glorys_data_from_rda(): + dates = ['2005-01-01','2005-02-01'] + lat_min = 30 + lat_max = 31 + lon_min = -71 + lon_max = -70 + dataset = da.get_glorys_data_from_rda(pd.date_range(start=dates[0], end=dates[1]).to_pydatetime().tolist(),lat_min, lat_max, lon_min,lon_max) + print(dataset) + +def test_get_glorys_data_from_api(): + dates = ['2000-01-01','2020-12-31'] + lat_min = 3 + lat_max = 61 + lon_min = -101 + lon_max = -34 + dataset = da.get_glorys_data_from_cds_api(dates,lat_min, lat_max, lon_min,lon_max) + dataset.to_netcdf("") \ No newline at end of file From decbea7467ddd1567ce1d13d2d410b59b063fda1 Mon Sep 17 00:00:00 2001 From: manishvenu Date: Thu, 23 Jan 2025 13:59:19 -0700 Subject: [PATCH 6/6] RM6 Draft GLORYS --- CrocoDash/data_access.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CrocoDash/data_access.py b/CrocoDash/data_access.py index cf5b88b..24984ea 100644 --- a/CrocoDash/data_access.py +++ b/CrocoDash/data_access.py @@ -5,10 +5,12 @@ import glob import os import copernicusmarine +from .rm6.regional_mom6 import regional_mom6 as rm6 def get_glorys_data_from_rda(dates: list,lat_min, lat_max, lon_min,lon_max) -> xr.Dataset: """ Gather GLORYS Data on Derecho Computers from the campaign storage and return the dataset sliced to the llc and urc coordinates at the specific dates + 2005 Only """ # Set @@ -26,7 +28,7 @@ def get_glorys_data_from_rda(dates: list,lat_min, lat_max, lon_min,lon_max) -> x def get_glorys_data_from_cds_api(dates: tuple, lat_min, lat_max, lon_min, lon_max) -> xr.Dataset: """ - Using the copernucismarine api, query GLORYS data + Using the copernucismarine api, query GLORYS data (any dates) """ ds = copernicusmarine.open_dataset( dataset_id = 'cmems_mod_glo_phy_my_0.083deg_P1D-m', @@ -38,4 +40,15 @@ def get_glorys_data_from_cds_api(dates: tuple, lat_min, lat_max, lon_min, lon_ma end_datetime = dates[1], variables=["uo","vo","thetao","so","zos"], ) - return ds \ No newline at end of file + return ds + +def get_glorys_data_script_for_cli(dates: tuple, lat_min, lat_max, lon_min, lon_max, filename, download_path) -> None: + """ + Script to run the GLORYS data query for the CLI + """ + return rm6.get_glorys_data([lon_min, lon_max], + [lat_min,lat_max], + [dates[0],dates[-1]], + filename, + download_path) +