Skip to content

Commit 4c4ef7b

Browse files
committed
[run-ex] ROMS native reader: Copied newest version of module depth from roppy package, supporting now Vstretching=5. Manually merged in earlier adaptations for zeta made by Kristen Thyng.
1 parent 64f0658 commit 4c4ef7b

3 files changed

Lines changed: 167 additions & 107 deletions

File tree

history.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ History
204204
* Using now product_id instead of OPeNDAP URL for CMEMS datasets, and using copernicusmarineclient through new reader_copernicusmarine. username/password can be stored in netrc-file with machine name equal to *copernicusmarine* or *nrt.cmems-du.eu*
205205
* Model property reguired_profiles_z_range is now replaced with config setting drift:profile_depth, and profiles are retrieved from surface to this depth. profiles_depth is now input parameter to get_environment, and not anymore a property of Environment class. prepare_run must now always call prepare_run of parent class, since profile_depth is copied to object in basemodel.prepare_run
206206
* get_variables_along_trajectory now also takes depth (z) as input parameter
207-
* updates to wetting/drying in ROMS reader (Kristin Thyng)
207+
* updates to wetting/drying in ROMS reader (Kristen Thyng)
208208
* Fill value in output netCDF files is now set to NaN for floats and -999 for integers
209209
* Moving basereader.prepare() to variables.prepare(), as the former was overriding structured.prepare() due to multiple inheritance, and thus config *drift:max_speed* was not applied if config setting was made after reader was added. Also increasing *drift:max_speed* of OceanDrift from 1 to 2m/s
210210
* Leeway model now allows capsizing (and un-capsizing for backwards runs), with given probability and reduction of leeway coefficients when wind exceeds given threshold
@@ -217,8 +217,8 @@ History
217217

218218
2024-04-02 / Release v1.11.2
219219
----------------------------
220-
* Proper handling of sea_surface_height implemented by Kristin Thyng. All subclasses of OceanDrift now have `sea_surface_height` (default 0) as new parameter. z=0 is always sea surface (including sea_surface_height), and seafloor is now where z = -(sea_floor_depth + sea_surface_height)
221-
* Improvements of ROMS reader by Kristin Thyng:
220+
* Proper handling of sea_surface_height implemented by Kristen Thyng. All subclasses of OceanDrift now have `sea_surface_height` (default 0) as new parameter. z=0 is always sea surface (including sea_surface_height), and seafloor is now where z = -(sea_floor_depth + sea_surface_height)
221+
* Improvements of ROMS reader by Kristen Thyng:
222222

223223
* Roppy-method `sdepth` (used by ROMS reader) now accounts for `sea_surface_height` (zeta).
224224
* Improved handling of rotation of vectors.

opendrift/readers/reader_ROMS_native.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def drop_non_essential_vars_pop(ds):
142142
dropvars = [v for v in ds.variables if v not in
143143
list(self.ROMS_variable_mapping.keys()) +
144144
['ocean_time', 'time', 'bulk_time', 's_rho',
145-
'Cs_r', 'Cs_rho', 'hc', 'angle', 'Vtransform']
145+
'Cs_r', 'Cs_rho', 'hc', 'angle', 'Vtransform', 'Vstretching']
146146
and v[0:3] not in ['lon', 'lat', 'mas']]
147147
logger.debug('Dropping variables: %s' % dropvars)
148148
ds = ds.drop_vars(dropvars)
@@ -181,6 +181,13 @@ def drop_non_essential_vars_pop(ds):
181181
self.Vtransform = 1
182182
self.Vtransform = np.asarray(self.Vtransform)
183183

184+
if 'Vstretching' in self.Dataset.variables:
185+
self.Vstretching = self.Dataset.variables['Vstretching'].data # scalar
186+
else:
187+
logger.warning('Vstretching not found, using 1')
188+
self.Vstretching = 1
189+
self.Vstretching = np.asarray(self.Vstretching)
190+
184191
if 's_rho' not in self.Dataset.variables:
185192
dimensions = 2
186193
else:
@@ -508,7 +515,8 @@ def get_variables(self, requested_variables, time=None,
508515
Htot = self.sea_floor_depth_below_sea_level
509516
zeta = self.zeta[indxTime]
510517
self.z_rho_tot = depth.sdepth(Htot, zeta, self.hc, self.Cs_r,
511-
Vtransform=self.Vtransform)
518+
Vtransform=self.Vtransform,
519+
Vstretching=self.Vstretching)
512520
# z_rho is positive relative to mean sea level but z is
513521
# 0 at the surface.
514522
# Transform z_rho to match convention of z.
@@ -517,7 +525,8 @@ def get_variables(self, requested_variables, time=None,
517525
H = self.sea_floor_depth_below_sea_level[indy, indx]
518526
zeta = self.zeta[itxy]
519527
z_rho = depth.sdepth(H, zeta, self.hc, self.Cs_r,
520-
Vtransform=self.Vtransform)
528+
Vtransform=self.Vtransform,
529+
Vstretching=self.Vstretching)
521530

522531
# z_rho is positive relative to mean sea level but z is
523532
# 0 at the surface.
@@ -622,13 +631,11 @@ def get_mask(mask_name, imask, masks_store):
622631
logger.debug('Calculating sigma2z-coefficients for whole domain')
623632
starttime = datetime.now()
624633
dummyvar = np.ones((O, M, N))
625-
dummy, self.s2z_total = depth.multi_zslice(dummyvar, self.z_rho_tot, self.zlevels)
634+
dummy, self.s2z_A, self.s2z_C, self.s2z_I, self.s2z_kmax = depth.multi_zslice(dummyvar, self.z_rho_tot, self.zlevels)
626635
# Store arrays/coefficients
627-
self.s2z_A = self.s2z_total[0].reshape(len(self.zlevels), M, N)
628-
self.s2z_C = self.s2z_total[1].reshape(len(self.zlevels), M, N)
629-
#self.s2z_I = self.s2z_total[2].reshape(M, N)
630-
self.s2z_kmax = self.s2z_total[3]
631-
del self.s2z_total # Free memory
636+
self.s2z_A = self.s2z_A.reshape(len(self.zlevels), M, N)
637+
self.s2z_C = self.s2z_C.reshape(len(self.zlevels), M, N)
638+
#self.s2z_I = self.s2z_I.reshape(M, N)
632639
logger.info('Time: ' + str(datetime.now() - starttime))
633640
if 'A' not in locals():
634641
logger.debug('Re-using sigma2z-coefficients')
@@ -661,9 +668,8 @@ def get_mask(mask_name, imask, masks_store):
661668
kmax = len(zle) # Must be checked. Or number of sigma-layers?
662669
if 'A' not in locals():
663670
logger.debug('Calculating new sigma2z-coefficients')
664-
variables[par], s2z = depth.multi_zslice(
671+
variables[par], A,C,I,kmax = depth.multi_zslice(
665672
variables[par], z_rho, variables['z'])
666-
A,C,I,kmax = s2z
667673
# Reshaping to compare with subset of full array
668674
#zle = np.arange(zi1, zi2)
669675
#A = A.reshape(len(zle), len(indx), len(indy))

0 commit comments

Comments
 (0)