trondkr / model2roms

Model2roms is a Python toolbox for creating forcing files required to run Regional Ocean Modeling System (ROMS)
MIT License
57 stars 33 forks source link

WOAMONTHLY VARIABLE NAMES #9

Closed jkansong closed 3 years ago

jkansong commented 3 years ago

Hi Trond,

I used WOAMONTHLY for the climatology data but I had an error with the naming of the variables since WOA uses 'X' for 'longitude' and 'Y' for 'latitude' (I think). I thought I had fixed it by putting the following code snippet in configM2R.py

code from Trond to fix SODA3_5DAY

   if self.ocean_indata_type == 'SODA3_5DAY':
        self.lonname = "xt_ocean"
        self.latname = "yt_ocean"
        self.depthname = "st_ocean"
        self.lonname_u = "xu_ocean"
        self.latname_u = "yu_ocean"
        self.lonname_v = "xu_ocean"
        self.latname_v = "yu_ocean"
        self.timeobject = []
    # code added by Joseph for WOA data
    if self.ocean_indata_type == 'WOAMONTHLY':
        self.lonname = "X"
        self.latname = "Y"
        self.depthname = "Z" 

but I got another error about variable names shown later below.

===THE FOLLOWING WAS THE ERROR I HAD BEFORE ADDING THE CODE ABOVE:

Started Fri Nov 13 12:25:09 2020 => Conversions run for climatological months ==> The following variables will be interpolated: ['temperature', 'salinity'] =>All horisontal interpolations will be done using ESMF-ESMPy (module ESMF) =>Output files are written in format: NETCDF4

=>Output grid file is: /home/jkansong/roms/Projects/Ghana4th/input/roms_grd.nc Starting logfile for ESMF Creating init for grid object GH1 ---> Initialized GRD object for grid type ROMS

GRD file : opennetcdf opened file /home/jkansong/roms/Projects/Ghana4th/input/roms_grd.nc --->Setting up vertical coordinates using self.vtransform: 2 self.vstretching: 2 Creating init for grid object GH1 ---> Initialized GRD object for grid type FORCINGDATA

GRD file : opennetcdf opened file /home/jkansong/roms/DATASETS/WOAMONTHLY/temperature_monthly_1deg2001.nc ---> Assuming regular grid type for FORCINGDATA ---> Using dimension names longitude and latitude and depth Traceback (most recent call last): File "/home/jkansong/model2roms/runM2R.py", line 46, in run() File "/home/jkansong/model2roms/runM2R.py", line 29, in run model2roms.convertMODEL2ROMS(confM2R) File "/home/jkansong/model2roms/model2roms.py", line 412, in convertMODEL2ROMS confM2R.grdMODEL.createobject(confM2R) File "/home/jkansong/model2roms/grd.py", line 71, in createobject self.lon = self.cdf.variables[str(confM2R.lonname)][:] KeyError: 'longitude'

============================================================================

==BELOW IS THE ERROR I GOT AFTER TRYING TO FIX THE VARIABLE NAME ISSUE=== ==AND I THINK IT STILL HAS TO DO WITH VARIABLE NAMES ISSUE. STILL TRYING TO FIX IT BUT WANTED TO BRING IT TO YOUR ATTENTION. THANKS.=====

Started Fri Nov 13 12:32:29 2020 => Conversions run for climatological months ==> The following variables will be interpolated: ['temperature', 'salinity'] =>All horisontal interpolations will be done using ESMF-ESMPy (module ESMF) =>Output files are written in format: NETCDF4

=>Output grid file is: /home/jkansong/roms/Projects/Ghana4th/input/roms_grd.nc Starting logfile for ESMF Creating init for grid object GH1 ---> Initialized GRD object for grid type ROMS

GRD file : opennetcdf opened file /home/jkansong/roms/Projects/Ghana4th/input/roms_grd.nc --->Setting up vertical coordinates using self.vtransform: 2 self.vstretching: 2 Creating init for grid object GH1 ---> Initialized GRD object for grid type FORCINGDATA

GRD file : opennetcdf opened file /home/jkansong/roms/DATASETS/WOAMONTHLY/temperature_monthly_1deg2001.nc ---> Assuming regular grid type for FORCINGDATA ---> Using dimension names X and Y and Z NetCDF Error: variable longitude in /home/jkansong/roms/DATASETS/WOAMONTHLY/temperature_monthly_1deg2001.nc : NetCDF: Variable not found Traceback (most recent call last): File "/home/jkansong/model2roms/runM2R.py", line 46, in run() File "/home/jkansong/model2roms/runM2R.py", line 29, in run model2roms.convertMODEL2ROMS(confM2R) File "/home/jkansong/model2roms/model2roms.py", line 412, in convertMODEL2ROMS confM2R.grdMODEL.createobject(confM2R) File "/home/jkansong/model2roms/grd.py", line 85, in createobject self.esmfgrid_u = ESMF.Grid(filename=self.grdfilename, filetype=ESMF.FileFormat.GRIDSPEC, File "/home/jkansong/anaconda3/envs/model2roms/lib/python3.9/site-packages/ESMF/util/decorators.py", line 64, in new_func return func(*args, *kwargs) File "/home/jkansong/anaconda3/envs/model2roms/lib/python3.9/site-packages/ESMF/api/grid.py", line 345, in init self._struct = ESMP_GridCreateFromFile(filename, filetype, File "/home/jkansong/anaconda3/envs/model2roms/lib/python3.9/site-packages/ESMF/util/decorators.py", line 76, in new_func return func(args, **kwargs) File "/home/jkansong/anaconda3/envs/model2roms/lib/python3.9/site-packages/ESMF/interface/cbindings.py", line 720, in ESMP_GridCreateFromFile raise NameError('ESMC_GridCreateFromFile() failed with rc = '+str(rc)) NameError: ESMC_GridCreateFromFile() failed with rc = -1

trondkr commented 3 years ago

I think your WOAMONTHLY files are missing geographic information. Model2roms is failing here:

self.esmfgrid_u = ESMF.Grid(filename=self.grdfilename, filetype=ESMF.FileFormat.GRIDSPEC, is_sphere=True, coord_names=[str(confM2R.lonname_u), str(confM2R.latname_u)], add_mask=False)

Here, ESMF is looking for the variable self.lonname_v = "longitude" defined in configM2R.py in your grid file. You need to have longitude and latitude in your forcing files as well as in your grid file to have model2roms perform correctly.

I have not used WOAMONTHLY in years and have not updated its code either. For testing, I suggest you use GLORYS (link) or SODA data that have been thoroughly tested with model2roms. Or you need to obtain WOAMONTHLY data that has correct longitude and latitude information. Also, make sure you define correctly the latitude and longitude names in configM2R.py

jkansong commented 3 years ago

Okay, thanks for the response. For some reason I've had trouble downloading SODA3 data; I'll try GLORYS. Hopefully I'll have some success.

-Joseph

On Fri, Nov 13, 2020 at 2:45 PM Trond Kristiansen notifications@github.com wrote:

I think your WOAMONTHLY files are missing geographic information. Model2roms is failing here:

self.esmfgrid_u = ESMF.Grid(filename=self.grdfilename, filetype=ESMF.FileFormat.GRIDSPEC, is_sphere=True, coord_names=[str(confM2R.lonname_u), str(confM2R.latname_u)], add_mask=False)

Here, ESMF is looking for the variable self.lonname_v = "longitude" defined in configM2R.py in your grid file. You need to have longitude and latitude in your forcing files as well as in your grid file to have model2roms perform correctly.

I have not used WOAMONTHLY in years and have not updated its code either. For testing, I suggest you use GLORYS (link) https://resources.marine.copernicus.eu/?option=com_csw&task=results or SODA data that have been thoroughly tested with model2roms. Or you need to obtain WOAMONTHLY data that has correct longitude and latitude information. Also, make sure you define correctly the latitude and longitude names in configM2R.py

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/trondkr/model2roms/issues/9#issuecomment-726804131, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABX7MWZ2PPDBNXVBTWSCQMLSPVBB3ANCNFSM4TURRSXA .

-- Joseph K. Ansong, PhD Assist. Research Scientist, University of Michigan, Department of Earth & Environmental Sciences, 2534 C.C. Little Building, 1100 North University Avenue, Ann Arbor, MI 48109 USA