Skip to content

Commit a96378d

Browse files
committed
Time Units Thing
1 parent c5e2b96 commit a96378d

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

regional_mom6/regional_mom6.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,7 @@ def regrid_velocity_tracers(
26252625
rotational_method=rot.RotationMethod.EXPAND_GRID,
26262626
regridding_method="bilinear",
26272627
time_units="days",
2628+
calendar="julian",
26282629
fill_method=rgd.fill_missing_data,
26292630
):
26302631
"""
@@ -2743,25 +2744,31 @@ def regrid_velocity_tracers(
27432744
xdim=f"{coords.attrs['parallel']}_{self.segment_name}",
27442745
zdim=reprocessed_var_map["depth_coord"],
27452746
)
2747+
if "since" not in time_units:
2748+
times = xr.DataArray(
2749+
np.arange(
2750+
0, #! Indexing everything from start of experiment = simple but maybe counterintutive?
2751+
segment_out[reprocessed_var_map["time"]].shape[
2752+
0
2753+
], ## Time is indexed from start date of window
2754+
dtype=float,
2755+
), # Import pandas for this shouldn't be a big deal b/c it's already kinda required somewhere deep in some tree.
2756+
dims=["time"],
2757+
)
2758+
segment_out.time.attrs = {
2759+
"calendar": calendar,
2760+
"units": f"{time_units} since {self.startdate}",
2761+
}
2762+
# This to change the time coordinate.
2763+
segment_out = rgd.add_or_update_time_dim(
2764+
segment_out, times, reprocessed_var_map["depth_coord"]
2765+
)
2766+
else:
2767+
segment_out.time.attrs = {
2768+
"calendar": calendar,
2769+
"units": time_units,
2770+
}
27462771

2747-
times = xr.DataArray(
2748-
np.arange(
2749-
0, #! Indexing everything from start of experiment = simple but maybe counterintutive?
2750-
segment_out[reprocessed_var_map["time"]].shape[
2751-
0
2752-
], ## Time is indexed from start date of window
2753-
dtype=float,
2754-
), # Import pandas for this shouldn't be a big deal b/c it's already kinda required somewhere deep in some tree.
2755-
dims=["time"],
2756-
)
2757-
# This to change the time coordinate.
2758-
segment_out = rgd.add_or_update_time_dim(
2759-
segment_out, times, reprocessed_var_map["depth_coord"]
2760-
)
2761-
segment_out.time.attrs = {
2762-
"calendar": "julian",
2763-
"units": f"{time_units} since {self.startdate}",
2764-
}
27652772
# Here, keep in mind that 'var' keeps track of the mom6 variable names we want, and self.tracers[var]
27662773
# will return the name of the variable from the original data
27672774

@@ -2840,7 +2847,6 @@ def regrid_velocity_tracers(
28402847
encoding_dict,
28412848
default_fill_value=1.0e20,
28422849
)
2843-
28442850
segment_out.load().to_netcdf(
28452851
self.outfolder / f"forcing_obc_{self.segment_name}.nc",
28462852
encoding=encoding_dict,

0 commit comments

Comments
 (0)