Skip to content

Commit

Permalink
still not working - failed installation of xesmf libraries and HDF er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
ashjbarnes committed Sep 11, 2023
1 parent 15debc9 commit 413d543
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 18 deletions.
5 changes: 4 additions & 1 deletion environment-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: mom6-regional-dev
channels:
- conda-forge
- defaults
dependencies:
- esmpy
- esmpy # 8.0.1
- xesmf # 0.3.0
- dask # 2.21.0
44 changes: 27 additions & 17 deletions regional_mom6/regional_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,26 +869,36 @@ def bathymetry(
{varnames["yh"]: slice(self.yextent[0] - 0.1, self.yextent[1] + 0.1)}
).astype("float")

bathy = nicer_slicer(
bathy, np.array(self.xextent) + np.array([-0.1, 0.1]), varnames["xh"]
)

## Here need to make a decision as to whether to slice 'normally' or with nicer slicer for 360 degree domain.

if bathy[varnames["xh"]][-1] - bathy[varnames["xh"]][0] > 355:
## Assume that we're dealing with a global grid, in which case we use nicer slicer
bathy = nicer_slicer(
bathy, np.array(self.xextent) + np.array([-0.1, 0.1]), varnames["xh"]
)
else:
## Otherwise just slice normally
bathy = bathy.sel(
{varnames["xh"]: slice(self.xextent[0] - 0.1, self.xextent[1] + 0.1)}
)

bathy.attrs[
"missing_value"
] = -1e20 # This is what FRE tools expects I guess?

bathy = xr.Dataset({"elevation": bathy})

bathy.lon.attrs["units"] = "degrees_east"
bathy.lat.attrs["units"] = "degrees_north"
bathy.lon.attrs["_FillValue"] = 1e20
bathy.elevation.attrs["_FillValue"] = 1e20
bathy.elevation.attrs["units"] = "m"
bathy.elevation.attrs["standard_name"] = "height_above_reference_ellipsoid"
bathy.elevation.attrs["long_name"] = "Elevation relative to sea level"
bathy.elevation.attrs["coordinates"] = "lon lat"

bathy.to_netcdf(
bathyout = xr.Dataset({"elevation": bathy})
bathy.close()

bathyout = bathyout.rename({varnames["xh"] : "lon",varnames["yh"] : "lat"})
bathyout.lon.attrs["units"] = "degrees_east"
bathyout.lat.attrs["units"] = "degrees_north"
# bathyout.lon.attrs["_FillValue"] = 1e20
bathyout.elevation.attrs["_FillValue"] = -1e20
bathyout.elevation.attrs["units"] = "m"
bathyout.elevation.attrs["standard_name"] = "height_above_reference_ellipsoid"
bathyout.elevation.attrs["long_name"] = "Elevation relative to sea level"
bathyout.elevation.attrs["coordinates"] = "lon lat"
bathyout.to_netcdf(
f"{self.mom_input_dir}bathy_original.nc", mode="w", engine="netcdf4"
)

Expand All @@ -912,7 +922,7 @@ def bathymetry(
tgrid.to_netcdf(
f"{self.mom_input_dir}topog_raw.nc", mode="w", engine="netcdf4"
)

tgrid.close()
#! Hardcoded for whole node notebook.
# topog_raw file is the 'target' grid used for gridgen. This is then overweitten by the second ESMF function (needs a blank netcdf to overwrite as the output)

Expand Down
100 changes: 100 additions & 0 deletions tests/test_expt_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import numpy as np
import pytest
from regional_mom6 import experiment

import xarray as xr
# reload(experiment)

@pytest.mark.parametrize(
( "xextent",
"yextent",
"daterange",
"resolution",
"vlayers",
"dz_ratio",
"depth",
"mom_run_dir",
"mom_input_dir",
"toolpath",
"gridtype"
),
[
([-5,5],[0,10],
["2003-01-01 00:00:00","2003-01-01 00:00:00"],
0.1,
5,
1,
1000,
"rundir",
"inputdir",
"toolpath",
"even_spacing"),
],
)
def test_experiment(
xextent,
yextent,
daterange,
resolution,
vlayers,
dz_ratio,
depth,
mom_run_dir,
mom_input_dir,
toolpath,
gridtype):

expt = experiment(
xextent,
yextent,
daterange,
resolution,
vlayers,
dz_ratio,
depth,
mom_run_dir,
mom_input_dir,
toolpath,
gridtype
)

## Generate some bathymetry to test on

bathy = np.random.random((100,100)) * (- 100)
bathy = xr.DataArray(
bathy,
dims=["lata","lona"],
coords={"lata":np.linspace(yextent[0]-5,yextent[1]+5,100),
"lona":np.linspace(xextent[0]-5,xextent[1]+5,100)})
# name the bathymetry variable of xarray dataarray
bathy.name = "elevation"

bathy.to_netcdf("bathy.nc",mode = "a")
bathy.close()
expt.bathymetry(
'bathy.nc',
{"xh":"lona",
"yh":"lata",
"elevation":"elevation"},
minimum_layers = 1
)

## Make an IC file to test on



return


test_experiment(
[-5,5],[0,10],
["2003-01-01 00:00:00","2003-01-01 00:00:00"],
0.1,
5,
1,
1000,
"rundir/",
"inputdir/",
"toolpath",
"even_spacing"
)

0 comments on commit 413d543

Please sign in to comment.