Skip to content

Commit 2d36fe3

Browse files
committed
added CIOFS3, fixed some date issues
* CIOFS3 has been added as an option * some issues were found in `make_ciofs_kerchunk` which should now be fixed
1 parent 75c76aa commit 2d36fe3

4 files changed

Lines changed: 76 additions & 9 deletions

File tree

particle_tracking_manager/config_ocean_model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ def open_dataset(self, drop_vars: list) -> xr.Dataset:
105105
drop_variables=drop_vars,
106106
decode_times=False,
107107
)
108+
elif ".parquet" in self.ocean_model_config.loc_remote:
109+
ds = xr.open_dataset(
110+
self.ocean_model_config.loc_remote,
111+
engine="kerchunk",
112+
# chunks={}, # Looks like it is faster not to include this for kerchunk
113+
drop_variables=drop_vars,
114+
decode_times=False,
115+
)
108116
else:
109117
ds = xr.open_zarr(
110118
self.ocean_model_config.loc_remote,
@@ -185,6 +193,8 @@ def get_file_date_string(name: str, date: datetime) -> str:
185193
return f"{date.year}_{str(date.timetuple().tm_yday - 1).zfill(4)}"
186194
elif name == "CIOFSFRESH":
187195
return f"{date.year}_{str(date.timetuple().tm_yday - 1).zfill(4)}"
196+
elif name == "CIOFS3":
197+
return f"{date.year}_{str(date.timetuple().tm_yday - 1).zfill(4)}"
188198
else:
189199
raise ValueError(f"get_file_date_string not implemented for {name}.")
190200

particle_tracking_manager/models/opendrift/utils.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def make_ciofs_kerchunk(start: str, end: str, name: str) -> dict:
114114

115115
if name == "CIOFS":
116116
output_dir_single_files = "/mnt/vault/ciofs/HINDCAST/.kerchunk_json"
117+
elif name == "CIOFS3":
118+
output_dir_single_files = "/mnt/vault/ciofs/CIOFS3/HINDCAST/.kerchunk_json"
117119
elif name == "CIOFSFRESH":
118120
output_dir_single_files = "/mnt/vault/ciofs/HINDCAST_FRESHWATER/.kerchunk_json"
119121
elif name == "CIOFSOP":
@@ -123,21 +125,24 @@ def make_ciofs_kerchunk(start: str, end: str, name: str) -> dict:
123125

124126
fs2 = fsspec.filesystem("") # local file system to save final jsons to
125127

126-
if name in ["CIOFS", "CIOFSFRESH"]:
128+
if name in ["CIOFS", "CIOFSFRESH", "CIOFS3"]:
127129

128130
# base for matching
129131
def base_str(a_time: str) -> str:
130132
return f"{output_dir_single_files}/{a_time}_*.json"
131133

134+
file_date_format = "%Y_0%j"
132135
date_format = "%Y_0%j"
133136

134137
elif name == "CIOFSOP":
135138

136139
# base for matching
137140
def base_str(a_time: str) -> str:
138-
return f"{output_dir_single_files}/ciofs_{a_time}-*.json"
141+
return f"{output_dir_single_files}/ciofs_{a_time}*.json"
142+
143+
file_date_format = "ciofs_%Y-%m-%d"
144+
date_format = "%Y-%m-%d"
139145

140-
date_format = "ciofs_%Y-%m-%d"
141146
else:
142147
raise ValueError(f"Name {name} not recognized")
143148

@@ -146,21 +151,24 @@ def base_str(a_time: str) -> str:
146151
if end[:4] != start[:4]:
147152
json_list += fs2.glob(base_str(end[:4]))
148153

154+
start_date = datetime.strptime(start, date_format)
155+
end_date = datetime.strptime(end, date_format)
156+
149157
# forward in time
150-
if end > start:
158+
if end_date >= start_date:
151159
json_list = [
152160
j
153161
for j in json_list
154-
if datetime.strptime(Path(j).stem, date_format).isoformat() >= start
155-
and datetime.strptime(Path(j).stem, date_format).isoformat() <= end
162+
if datetime.strptime(Path(j).stem, file_date_format) >= start_date
163+
and datetime.strptime(Path(j).stem, file_date_format) <= end_date
156164
]
157165
# backward in time
158-
elif end < start:
166+
elif end_date < start_date:
159167
json_list = [
160168
j
161169
for j in json_list
162-
if datetime.strptime(Path(j).stem, date_format).isoformat() <= start
163-
and datetime.strptime(Path(j).stem, date_format).isoformat() >= end
170+
if datetime.strptime(Path(j).stem, file_date_format) <= start_date
171+
and datetime.strptime(Path(j).stem, file_date_format) >= end_date
164172
]
165173

166174
if json_list == []:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
standard_name_mapping_CIOFS:
2+
mask_rho: "land_binary_mask"
3+
wetdry_mask_rho: "land_binary_mask"
4+
u_eastward: "x_sea_water_velocity"
5+
v_northward: "y_sea_water_velocity"
6+
7+
CIOFS3:
8+
name: "CIOFS3"
9+
loc_remote: null
10+
temporal_resolution_str: "PT1H"
11+
lon_min: -156.485291
12+
lon_max: -148.925125
13+
lat_min: 56.7004919
14+
lat_max: 61.5247774
15+
start_time_model: "1999-01-01T00:00:00"
16+
end_time_fixed: "2025-01-01T00:00:00"
17+
oceanmodel_lon0_360: false
18+
standard_name_mapping:
19+
mask_rho: "land_binary_mask"
20+
wetdry_mask_rho: "land_binary_mask"
21+
u_eastward: "x_sea_water_velocity"
22+
v_northward: "y_sea_water_velocity"
23+
model_drop_vars:
24+
- "wetdry_mask_psi"
25+
dx: 100
26+
kerchunk_func_str: "make_ciofs_kerchunk"

tests/test_config_ocean_model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
"start_time": "2014-01-01T00:00",
4545
"end_time": "2014-01-01T05:00",
4646
},
47+
"CIOFS3": {
48+
"lon": -153,
49+
"lat": 59,
50+
"start_time": "2023-01-01T00:00",
51+
"end_time": "2023-01-01T05:00",
52+
},
4753
}
4854

4955
# Invalid values (except start_times are valid since not testing those here)
@@ -76,6 +82,13 @@
7682
"end_time": "2022-01-01T05:00",
7783
"ocean_model_config": ocean_model_registry.get("CIOFSFRESH"),
7884
},
85+
"CIOFS3": {
86+
"lon": -145,
87+
"lat": 40,
88+
"start_time": "2026-01-01",
89+
"end_time": "2026-01-01T05:00",
90+
"ocean_model_config": ocean_model_registry.get("CIOFS3"),
91+
},
7992
}
8093

8194

@@ -151,6 +164,16 @@ def test_oceanmodel_lon0_360():
151164
assert m.ocean_model_config.oceanmodel_lon0_360 == False
152165
assert m.lon == lon_in
153166

167+
m = ocean_model_simulation_mapper["CIOFS3"](
168+
start_time="2004-01-01",
169+
lon=lon_in,
170+
lat=57,
171+
end_time="2004-01-01T05:00",
172+
ocean_model_local=True,
173+
)
174+
assert m.ocean_model_config.oceanmodel_lon0_360 == False
175+
assert m.lon == lon_in
176+
154177
m = ocean_model_simulation_mapper["NWGOA"](
155178
start_time="2007-01-01",
156179
lon=lon_in,

0 commit comments

Comments
 (0)