opendrift icon indicating copy to clipboard operation
opendrift copied to clipboard

CROCO Cs_r KeyError

Open dpereiro91 opened this issue 6 months ago • 1 comments

Hi All,

I got into a KeyError when using reader_ROMS_native (OpenDrift v.1.14.2) with some CROCO files. It seems that ROMS uses Cs_r for the vertical coordinate, while in CROCO (v.2) this variable is called Cs_rho.

In case this is useful for others, this was the solution:

  1. Add 'Cs_rho' to drop_non_essential_vars_pop

dropvars = [v for v in ds.variables if v not in list(self.ROMS_variable_mapping.keys()) + gls_param + ['ocean_time', 'time', 'bulk_time', 's_rho', 'Cs_r', 'Cs_rho', 'hc', 'angle', 'Vtransform']

  1. Add a KeyError Exception under # Read sigma-coordinate transform parameters:

try: self.Cs_r = self.Dataset.variables['Cs_r'][:] except KeyError: self.Cs_r = self.Dataset.variables['Cs_rho'][:] # CROCO

Thanks, Diego

dpereiro91 avatar May 28 '25 11:05 dpereiro91