OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
245 stars 120 forks source link

AttributeError: 'Reader' object has no attribute 'sigma' #630

Closed TomValderrama closed 2 years ago

TomValderrama commented 3 years ago

Hi,

I am a new user of opendrift. I'm using outputs from croco model for the particle simulation. I'm having the next error:

19:09:09 DEBUG opendrift.models.basemodel: Adding 17 config items from basemodel 19:09:09 DEBUG opendrift.models.basemodel: Adding 4 config items from basemodel 19:09:09 DEBUG opendrift.models.basemodel: Adding 34 config items from basemodel 19:09:09 INFO opendrift.models.basemodel: OpenDriftSimulation initialised (version 1.5.6) 19:09:09 DEBUG opendrift.models.basemodel: Adding 13 config items from oceandrift 19:09:09 DEBUG opendrift.models.basemodel: Overwriting config item seed:z 19:09:09 INFO opendrift.readers.reader_ROMS_native: Opening dataset: enero2019.nc 19:09:09 INFO opendrift.readers.reader_ROMS_native: Opening file with Dataset 19:09:09 WARNING opendrift.readers.reader_ROMS_native: Vtransform not found, using 1 19:09:09 INFO opendrift.readers.reader_ROMS_native: 'gls_cmu0' 19:09:09 INFO opendrift.readers.reader_ROMS_native: Did not find complete set of GLS parameters Traceback (most recent call last): File "/data1/tomas/ejemplo.py", line 21, in mosa_native = reader_ROMS_native.Reader(filename_nc) File "/data1/tomas/opendrift/readers/reader_ROMS_native.py", line 196, in init self.sigma = self.sigma.data AttributeError: 'Reader' object has no attribute 'sigma'

II don't know if I should rename the depth variables, create a 'sigma' variable using the s_rho dimension and the "h" variables, or is there another solution. As a context previously I had to add the variables from my grid file to my croco output file. Beforehand thank you very much.

knutfrode commented 3 years ago

Hi,

Is this a 2D or 3D file? Can you please post the output from ncdump?

TomValderrama commented 3 years ago

Hi,

Is this a 2D or 3D file? Can you please post the output from ncdump? Is a 3D file. The output from ncdump is as follows:

netcdf enero2019 { dimensions: time = UNLIMITED ; // (31 currently) s_rho = 42 ; eta_rho = 603 ; xi_rho = 505 ; xi_u = 504 ; eta_v = 602 ; one = 1 ; bath = 1 ; eta_psi = 602 ; xi_psi = 504 ; eta_u = 603 ; xi_v = 505 ; variables:

float salt(time, s_rho, eta_rho, xi_rho) ; salt:long_name = "averaged salinity" ; salt:units = "PSU" ; salt:field = "salinity, scalar, series" ; salt:standard_name = "sea_water_salinity" ; salt:coordinates = "lat_rho lon_rho" ; float temp(time, s_rho, eta_rho, xi_rho) ; temp:long_name = "averaged potential temperature" ; temp:units = "Celsius" ; temp:field = "temperature, scalar, series" ; temp:standard_name = "sea_water_potential_temperature" ; temp:coordinates = "lat_rho lon_rho" ; float u(time, s_rho, eta_rho, xi_u) ; u:long_name = "averaged u-momentum component" ; u:units = "meter second-1" ; u:field = "u-velocity, scalar, series" ; u:standard_name = "sea_water_x_velocity_at_u_location" ; u:coordinates = "lat_u lon_u" ; float ubar(time, eta_rho, xi_u) ; ubar:long_name = "averaged vertically integrated u-momentum component" ; ubar:units = "meter second-1" ; ubar:field = "ubar-velocity, scalar, series" ; ubar:standard_name = "barotropic_sea_water_x_velocity_at_u_location" ; ubar:coordinates = "lat_u lon_u" ; float v(time, s_rho, eta_v, xi_rho) ; v:long_name = "averaged v-momentum component" ; v:units = "meter second-1" ; v:field = "v-velocity, scalar, series" ; v:standard_name = "sea_water_y_velocity_at_v_location" ; v:coordinates = "lat_v lon_v" ; float vbar(time, eta_v, xi_rho) ; vbar:long_name = "averaged vertically integrated v-momentum component" ; vbar:units = "meter second-1" ; vbar:field = "vbar-velocity, scalar, series" ; vbar:standard_name = "barotropic_sea_water_y_velocity_at_v_location" ; vbar:coordinates = "lat_v lon_v" ; float zeta(time, eta_rho, xi_rho) ; zeta:long_name = "averaged free-surface" ; zeta:units = "meter" ; zeta:field = "free-surface, scalar, series" ; zeta:standard_name = "sea_surface_height" ; zeta:coordinates = "lat_rho lon_rho" ; double angle(eta_rho, xi_rho) ; angle:long_name = "angle between xi axis and east" ; angle:units = "degree" ; double depthmax(one) ; depthmax:long_name = "Deep bathymetry clipping depth" ; depthmax:units = "meter" ; double depthmin(one) ; depthmin:long_name = "Shallow bathymetry clipping depth" ; depthmin:units = "meter" ; double dmde(eta_rho, xi_rho) ; dmde:long_name = "eta derivative of inverse metric factor pm" ; dmde:units = "meter" ; double dndx(eta_rho, xi_rho) ; dndx:long_name = "xi derivative of inverse metric factor pn" ; dndx:units = "meter" ; double el(one) ; el:long_name = "domain length in the ETA-direction" ; el:units = "meter" ; double f(eta_rho, xi_rho) ; f:long_name = "Coriolis parameter at RHO-points" ; f:units = "second-1" ; double h(eta_rho, xi_rho) ; h:long_name = "Final bathymetry at RHO-points" ; h:units = "meter" ; double hraw(bath, eta_rho, xi_rho) ; hraw:long_name = "Working bathymetry at RHO-points" ; hraw:units = "meter" ; double lat_psi(eta_psi, xi_psi) ; lat_psi:long_name = "latitude of PSI-points" ; lat_psi:units = "degree_north" ; double lat_rho(eta_rho, xi_rho) ; lat_rho:long_name = "latitude of RHO-points" ; lat_rho:units = "degree_north" ; double lat_u(eta_u, xi_u) ; lat_u:long_name = "latitude of U-points" ; lat_u:units = "degree_north" ; double lat_v(eta_v, xi_v) ; lat_v:long_name = "latitude of V-points" ; lat_v:units = "degree_north" ; double alpha(eta_rho, xi_rho) ; alpha:long_name = "Weights between coarse and fine grids at RHO-points" ; double lon_psi(eta_psi, xi_psi) ; lon_psi:long_name = "longitude of PSI-points" ; lon_psi:units = "degree_east" ; double lon_rho(eta_rho, xi_rho) ; lon_rho:long_name = "longitude of RHO-points" ; lon_rho:units = "degree_east" ; double lon_u(eta_u, xi_u) ; lon_u:long_name = "longitude of U-points" ; lon_u:units = "degree_east" ; double lon_v(eta_v, xi_v) ; lon_v:long_name = "longitude of V-points" ; lon_v:units = "degree_east" ; double mask_psi(eta_psi, xi_psi) ; mask_psi:long_name = "mask on PSI-points" ; mask_psi:option_0 = "land" ; mask_psi:option_1 = "water" ; double mask_rho(eta_rho, xi_rho) ; mask_rho:long_name = "mask on RHO-points" ; mask_rho:option_0 = "land" ; mask_rho:option_1 = "water" ; double mask_u(eta_u, xi_u) ; mask_u:long_name = "mask on U-points" ; mask_u:option_0 = "land" ; mask_u:option_1 = "water" ; double mask_v(eta_v, xi_v) ; mask_v:long_name = "mask on V-points" ; mask_v:option_0 = "land" ; mask_v:option_1 = "water" ; double pm(eta_rho, xi_rho) ; pm:long_name = "curvilinear coordinate metric in XI" ; pm:units = "meter-1" ; double pn(eta_rho, xi_rho) ; pn:long_name = "curvilinear coordinate metric in ETA" ; pn:units = "meter-1" ; char spherical(one) ; spherical:long_name = "Grid type logical switch" ; spherical:option_T = "spherical" ; double x_psi(eta_psi, xi_psi) ; x_psi:long_name = "x location of PSI-points" ; x_psi:units = "meter" ; double x_rho(eta_rho, xi_rho) ; x_rho:long_name = "x location of RHO-points" ; x_rho:units = "meter" ; double x_u(eta_u, xi_u) ; x_u:long_name = "x location of U-points" ; x_u:units = "meter" ; double x_v(eta_v, xi_v) ; x_v:long_name = "x location of V-points" ; x_v:units = "meter" ; double xl(one) ; xl:long_name = "domain length in the XI-direction" ; xl:units = "meter" ; double y_psi(eta_psi, xi_psi) ; y_psi:long_name = "y location of PSI-points" ; y_psi:units = "meter" ; double y_rho(eta_rho, xi_rho) ; y_rho:long_name = "y location of RHO-points" ; y_rho:units = "meter" ; double y_u(eta_u, xi_u) ; y_u:long_name = "y location of U-points" ; y_u:units = "meter" ; double y_v(eta_v, xi_v) ; y_v:long_name = "y location of V-points" ; y_v:units = "meter" ; float ocean_time(time) ; ocean_time:long_name = "averaged time since initialization" ; ocean_time:field = "time, scalar, series" ; ocean_time:standard_name = "time" ; ocean_time:axis = "T" ; ocean_time:units = "seconds since 2000-01-01 00:00:00" ;

// global attributes: :rst_file = "roms_rst_20190101.nc" ; :his_file = "roms_his_20190101.nc" ; :avg_file = "roms_avg_20190101.nc" ; :grd_file = "roms_MIC_grd_v8b.nc" ; :ini_file = "roms_rst_20181231.nc" ; :frc_file = "roms_frc_GFS_6940.nc" ; :VertCoordType = "NEW" ; :skpp = "2005" ; :theta_s = 7. ; :theta_s_expl = "S-coordinate surface control parameter" ; :theta_b = 2. ; :theta_b_expl = "S-coordinate bottom control parameter" ; :Tcline = 200. ; :Tcline_expl = "S-coordinate surface/bottom layer width" ; :Tcline_units = "meter" ; :hc = 200. ; :hc_expl = "S-coordinate parameter, critical depth" ; :hc_units = "meter" ;

knutfrode commented 3 years ago

As this is a 3D-file, then the vertical sigma-coordinate should also be needed, but is missing here. Perhaps this is also in your grid-file? If so, can you copy it over to the main file(s)?

Alternatively, the ROMS-reader could also be updated to read sigma from grid-file, if available there.

TomValderrama commented 3 years ago

I add al de variables from grid to the main file. Here is the ncdump output of this file:

netcdf roms_MIC_grd_v8b { dimensions: xi_u = 504 ; eta_u = 603 ; xi_v = 505 ; eta_v = 602 ; xi_rho = 505 ; eta_rho = 603 ; xi_psi = 504 ; eta_psi = 602 ; one = 1 ; two = 2 ; four = 4 ; bath = 1 ; variables: double xl(one) ; xl:long_name = "domain length in the XI-direction" ; xl:units = "meter" ; double el(one) ; el:long_name = "domain length in the ETA-direction" ; el:units = "meter" ; double depthmin(one) ; depthmin:long_name = "Shallow bathymetry clipping depth" ; depthmin:units = "meter" ; double depthmax(one) ; depthmax:long_name = "Deep bathymetry clipping depth" ; depthmax:units = "meter" ; char spherical(one) ; spherical:long_name = "Grid type logical switch" ; spherical:option_T = "spherical" ; double angle(eta_rho, xi_rho) ; angle:long_name = "angle between xi axis and east" ; angle:units = "degree" ; double h(eta_rho, xi_rho) ; h:long_name = "Final bathymetry at RHO-points" ; h:units = "meter" ; double hraw(bath, eta_rho, xi_rho) ;

hraw:long_name = "Working bathymetry at RHO-points" ; hraw:units = "meter" ; double alpha(eta_rho, xi_rho) ; alpha:long_name = "Weights between coarse and fine grids at RHO-points" ; double f(eta_rho, xi_rho) ; f:long_name = "Coriolis parameter at RHO-points" ; f:units = "second-1" ; double pm(eta_rho, xi_rho) ; pm:long_name = "curvilinear coordinate metric in XI" ; pm:units = "meter-1" ; double pn(eta_rho, xi_rho) ; pn:long_name = "curvilinear coordinate metric in ETA" ; pn:units = "meter-1" ; double dndx(eta_rho, xi_rho) ; dndx:long_name = "xi derivative of inverse metric factor pn" ; dndx:units = "meter" ; double dmde(eta_rho, xi_rho) ; dmde:long_name = "eta derivative of inverse metric factor pm" ; dmde:units = "meter" ; double x_rho(eta_rho, xi_rho) ; x_rho:long_name = "x location of RHO-points" ; x_rho:units = "meter" ; double x_u(eta_u, xi_u) ; x_u:long_name = "x location of U-points" ; x_u:units = "meter" ; double x_v(eta_v, xi_v) ; x_v:long_name = "x location of V-points" ; x_v:units = "meter" ; double x_psi(eta_psi, xi_psi) ; x_psi:long_name = "x location of PSI-points" ; x_psi:units = "meter" ; double y_rho(eta_rho, xi_rho) ; y_rho:long_name = "y location of RHO-points" ; y_rho:units = "meter" ; double y_u(eta_u, xi_u) ; y_u:long_name = "y location of U-points" ; y_u:units = "meter" ;

    double y_v(eta_v, xi_v) ;
            y_v:long_name = "y location of V-points" ;
            y_v:units = "meter" ;
    double y_psi(eta_psi, xi_psi) ;
            y_psi:long_name = "y location of PSI-points" ;
            y_psi:units = "meter" ;
    double lon_rho(eta_rho, xi_rho) ;
            lon_rho:long_name = "longitude of RHO-points" ;
            lon_rho:units = "degree_east" ;
    double lon_u(eta_u, xi_u) ;
            lon_u:long_name = "longitude of U-points" ;
            lon_u:units = "degree_east" ;
    double lon_v(eta_v, xi_v) ;
            lon_v:long_name = "longitude of V-points" ;
            lon_v:units = "degree_east" ;
    double lon_psi(eta_psi, xi_psi) ;
            lon_psi:long_name = "longitude of PSI-points" ;
            lon_psi:units = "degree_east" ;
    double lat_rho(eta_rho, xi_rho) ;
            lat_rho:long_name = "latitude of RHO-points" ;
            lat_rho:units = "degree_north" ;
    double lat_u(eta_u, xi_u) ;
            lat_u:long_name = "latitude of U-points" ;
            lat_u:units = "degree_north" ;
    double lat_v(eta_v, xi_v) ;
            lat_v:long_name = "latitude of V-points" ;
            lat_v:units = "degree_north" ;
    double lat_psi(eta_psi, xi_psi) ;
            lat_psi:long_name = "latitude of PSI-points" ;
            lat_psi:units = "degree_north" ;
    double mask_rho(eta_rho, xi_rho) ;
            mask_rho:long_name = "mask on RHO-points" ;
            mask_rho:option_0 = "land" ;
            mask_rho:option_1 = "water" ;
    double mask_u(eta_u, xi_u) ;
            mask_u:long_name = "mask on U-points" ;
            mask_u:option_0 = "land" ;

mask_u:option_1 = "water" ; double mask_v(eta_v, xi_v) ; mask_v:long_name = "mask on V-points" ; mask_v:option_0 = "land" ; mask_v:option_1 = "water" ; double mask_psi(eta_psi, xi_psi) ; mask_psi:long_name = "mask on PSI-points" ; mask_psi:option_0 = "land" ; mask_psi:option_1 = "water" ;

// global attributes: :title = "Lagos - Aysen Model" ; :date = "29-Jul-2009" ; :type = "ROMS grid file" ; data:

xl = _ ;

el = _ ;

depthmin = _ ;

depthmax = _ ;

spherical = "T" ;

knutfrode commented 3 years ago

Yes, it seems that there is a dimension s_rho, but no variable with the same name. Could you please try to change line 113 of reader_ROMS_native.py from

if 's_rho' not in self.Dataset.variables:

to

if 's_rho' not in self.Dataset.dimensions:

Then sigma should be calculated as:

self.sigma = (np.arange(num_sigma)+.5-num_sigma)/num_sigma

If that works, I can update the reader. If it does not work, it seems you have to add a variable with name s_rho to the file.

TomValderrama commented 2 years ago

Hello, I have been thinking that the problem I have is updating the software. I am currently working on a server that has version 1.5.6. I have run the commands I use to update OpenDrift on my computer, and they have not worked for me. conda update -n base -c defaults conda conda env update -f environment.yml Is there a way to carry out this update without having to delete the directory and install OpenDrift again?

gauteh commented 2 years ago

By which method have you installed opendrift? If it is alternative 1 in the guide you also have to pull the latest version using git, either to latest master or to a specific version.

gauteh commented 2 years ago

Need more information, closing for now.