Skip to content

Commit

Permalink
Merge pull request #82 from schism-dev/feature/ElevIc
Browse files Browse the repository at this point in the history
Feature/elev ic
  • Loading branch information
cuill authored Jun 6, 2023
2 parents 6b1fc20 + fd8f220 commit 83e395c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/Gr3/Elev_IC/gen_elev.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pyschism.mesh.base import Gr3
from pyschism.mesh.hgrid import Hgrid
from pyschism.mesh.gridgr3 import ElevIc

if __name__ == '__main__':

hgrid = Gr3.open('./hgrid.gr3', crs='epsg:4326')
hgrid = Hgrid.open('./hgrid.gr3', crs='epsg:4326')

elevic = ElevIc.default(hgrid=hgrid, offset=0.1)
elevic.write('elev.ic', overwrite=True)
8 changes: 4 additions & 4 deletions pyschism/forcing/hycom/hycom2schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def convert_longitude(ds, bbox):

t0 = time()
ds = (
ds.swap_dims({lon_name: '_lon_adjusted'})
ds.swap_dims({'lon': '_lon_adjusted'})
.sel(**{'_lon_adjusted': sorted(ds._lon_adjusted)})
.drop(lon_name)
.drop('lon')
)
ds = ds.rename({'_lon_adjusted': lon_name})
ds = ds.rename({'_lon_adjusted': 'lon'})
#ds = ds.sortby(ds.lon)
#ds.coords['lon'].attrs = lon_attr
logger.info(f'swap dims took {time()-t0} seconds!')
Expand Down Expand Up @@ -713,7 +713,7 @@ def fetch_data(self, outdir: Union[str, os.PathLike], vgrid, start_date, rnday,
xmin, xmax = np.min(nlon), np.max(nlon)
ymin, ymax = np.min(nlat), np.max(nlat)
bbox = Bbox.from_extents(xmin, ymin, xmax, ymax)
#logger.info(f'xmin is {xmin}, xmax is {xmax}')
logger.info(f'bbox for nudge is {bbox}')

time_idx, lon_idx1, lon_idx2, lat_idx1, lat_idx2, x2, y2, _ = get_idxs(date, database, bbox, lonc=nlonc, latc=nlatc)

Expand Down
7 changes: 3 additions & 4 deletions pyschism/mesh/gridgr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,11 @@ class IcField(Gr3Field):
pass


class ElevIc(Gr3):
class ElevIc(IcField):
@classmethod
def default(cls, hgrid, offset=0.1):
#Use Gr3.open to read hgrid.gr3 thus keep original bathymetry
obj = hgrid.copy()
obj.values[:] = np.maximum(0, -hgrid.values - offset)
obj = cls.constant(hgrid, 0.0)
obj.values[:] = np.maximum(0.0, hgrid.values - offset)
return obj

class TempIc(IcField):
Expand Down

0 comments on commit 83e395c

Please sign in to comment.