Skip to content

Commit

Permalink
add in interp method and other tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mariahpope committed May 2, 2024
1 parent e75b3da commit 323feab
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 21 deletions.
7 changes: 4 additions & 3 deletions examples/replay/config-0.25-degree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ MOM6Dataset:

cycles:
start: "1994-01-01T00"
end: "1999-06-13T06"
end: "2023-12-31T06"
freq: "6h"

time:
start: "1993-12-31T18"
end: "1999-06-13T03"
start: "1994-01-01T00"
end: "2023-12-31T06"
freq: "3h"

chunks_in:
Expand Down Expand Up @@ -284,5 +284,6 @@ MOM6Dataset:
weights_file_u2t:
weights_file_v2t:
periodic: True
interp_method: "conservative"

gaussian_grid: "gcs://noaa-ufs-gefsv13replay/ufs-hr1/0.25-degree/03h-freq/zarr/fv3.zarr"
7 changes: 4 additions & 3 deletions examples/replay/config-1.00-degree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ MOM6Dataset:

cycles:
start: "1994-01-01T00"
end: "1999-06-13T06"
end: "1999-06-14T00"
freq: "6h"

time:
start: "1993-12-31T18"
end: "1999-06-13T03"
start: "1994-01-01T00"
end: "1999-06-14T00"
freq: "6h"

chunks_in:
Expand Down Expand Up @@ -291,5 +291,6 @@ MOM6Dataset:
weights_file_u2t:
weights_file_v2t:
periodic: True
interp_method: "conservative"

gaussian_grid: "gcs://noaa-ufs-gefsv13replay/ufs-hr1/1.00-degree/03h-freq/zarr/fv3.zarr"
Binary file removed examples/replay/mom6_grid_0.25_degree.nc
Binary file not shown.
Binary file removed examples/replay/mom6_grid_1.00_degree.nc
Binary file not shown.
16 changes: 14 additions & 2 deletions examples/replay/replay_mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
import dask.array as darray
from zarr import NestedDirectoryStore

from ufs2arco import FV3Dataset, MOM6Dataset, CICE6Dataset, Timer, MOM6Regridder
from ufs2arco import (
FV3Dataset,
MOM6Dataset,
CICE6Dataset,
Timer,
MOM6Regridder,
CICE6Regridder
)

class ReplayMover1Degree():

Expand Down Expand Up @@ -110,15 +117,20 @@ def __init__(
self.cycles = pd.date_range(**config[name]["cycles"])
self.time = pd.date_range(**config[name]["time"])

self.Regridder = None
if component.lower() == "fv3":
self.Dataset = FV3Dataset
self.cached_path = self.fv3_path
if "regrid" in self.config.keys():
raise NotImplementedError
elif component.lower() == "mom6":
self.Dataset = MOM6Dataset
self.cached_path = self.mom6_path
self.Regridder = MOM6Regridder
elif component.lower() == "cice6":
self.Dataset = CICE6Dataset
self.cached_path = self.cice6_path
self.Regridder = CICE6Regridder

# for move_single_dataset, we have to figure out how many resulting timestamps we have
# within a single DA cycle
Expand Down Expand Up @@ -175,7 +187,7 @@ def regrid_to_gaussian(
)
lons = gaussian_grid['grid_xt'].values
lats = gaussian_grid['grid_yt'].values
rg = MOM6Regridder(
rg = self.Regridder(
lats1d_out=lats,
lons1d_out=lons,
ds_in=xds,
Expand Down
10 changes: 5 additions & 5 deletions ufs2arco/regrid/cice6regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def __init__(
lons1d_out: np.array,
ds_in: xr.Dataset,
config_filename: str,
interp_method: str = "bilinear",
) -> None:
super(CICE6Regridder, self).__init__(
lats1d_out, lons1d_out, ds_in, config_filename, interp_method
lats1d_out, lons1d_out, ds_in, config_filename
)

def _create_regridder(self, ds_in: xr.Dataset) -> None:
Expand Down Expand Up @@ -85,9 +84,10 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:

# paths to interpolation weights files
wfiles = dict()
interp_method = self.config["interp_method"]
for key in ["weights_file_t2t", "weights_file_u2t"]:
vin = key[-3]
default = f"weights-cice6-{self.ires}.C{vin}.{self.ores}.Ct.{self.interp_method}.nc"
default = f"weights-cice6-{self.ires}.C{vin}.{self.ores}.Ct.{interp_method}.nc"
path = self.config.get(key, None)
wfiles[key] = path if path is not None else default

Expand All @@ -97,7 +97,7 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:
self.rg_tt = xe.Regridder(
ds_in_t,
grid_out,
self.interp_method,
interp_method,
periodic=periodic,
reuse_weights=reuse,
filename=wfiles["weights_file_t2t"],
Expand All @@ -107,7 +107,7 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:
self.rg_ut = xe.Regridder(
ds_in_u,
ds_in_t,
self.interp_method,
interp_method,
periodic=periodic,
reuse_weights=reuse,
filename=wfiles["weights_file_u2t"],
Expand Down
12 changes: 6 additions & 6 deletions ufs2arco/regrid/mom6regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ def __init__(
lons1d_out: np.array,
ds_in: xr.Dataset,
config_filename: str,
interp_method: str = "conservative",
) -> None:
super(MOM6Regridder, self).__init__(
lats1d_out, lons1d_out, ds_in, config_filename, interp_method
lats1d_out, lons1d_out, ds_in, config_filename
)

def create_grid_in(
Expand Down Expand Up @@ -165,10 +164,11 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:
self.ores = f"{nlon_o}x{nlat_o}"

# paths to interpolation weights files
interp_method = self.config["interp_method"]
wfiles = dict()
for key in ["weights_file_t2t", "weights_file_u2t", "weights_file_v2t"]:
vin = key[-3]
default = f"weights-mom6-{self.ires}.C{vin}.{self.ores}.Ct.{self.interp_method}.nc"
default = f"weights-mom6-{self.ires}.C{vin}.{self.ores}.Ct.{interp_method}.nc"
path = self.config.get(key, None)
wfiles[key] = path if path is not None else default

Expand All @@ -178,7 +178,7 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:
self.rg_tt = xe.Regridder(
ds_in_t,
grid_out,
self.interp_method,
interp_method,
periodic=periodic,
reuse_weights=reuse,
filename=wfiles["weights_file_t2t"],
Expand All @@ -189,7 +189,7 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:
self.rg_ut = xe.Regridder(
ds_in_u,
ds_in_t,
self.interp_method,
interp_method,
periodic=periodic,
reuse_weights=reuse,
filename=wfiles["weights_file_u2t"],
Expand All @@ -199,7 +199,7 @@ def _create_regridder(self, ds_in: xr.Dataset) -> None:
self.rg_vt = xe.Regridder(
ds_in_v,
ds_in_t,
self.interp_method,
interp_method,
periodic=periodic,
reuse_weights=reuse,
filename=wfiles["weights_file_v2t"],
Expand Down
3 changes: 1 addition & 2 deletions ufs2arco/regrid/ufsregridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(
lons1d_out: np.array,
ds_in: xr.Dataset,
config_filename: str,
interp_method: str = "conservative",
) -> None:
"""
Initialize the UFSRegridder object.
Expand All @@ -80,7 +79,7 @@ def __init__(
# specify an output resolution
self.lats1d_out = lats1d_out
self.lons1d_out = lons1d_out
self.interp_method = interp_method
self.interp_method = self.config["interp_method"]

# create regridder
self._create_regridder(ds_in)
Expand Down

0 comments on commit 323feab

Please sign in to comment.