PYROMS MERRA-2 Example

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
Thronian

PYROMS MERRA-2 Example

#1 Unread post by Thronian »

Hi, I'm new towards pyroms which is one of the tools, using to help generate forcing files. Im currently running MERRA-2 in the examples, and managed to rewrite the python script.

I had rewrite one of the python script get_MERRA_albedo_from_nasa_opendap_dailyV1.py as I have PyDAP, change the server link to 'http://goldsmr4.gesdisc.eosdis.nasa.gov' while using setup_session to key in EarthData username and password to read data from OPENDAP url.

I test and ran that get script alone, setting year at 2016, however there's an error related to __array__() for nc.variable['lat'] as there are two occurrence of "lat" from line 56 and line 85. Any suggestions to resolve this error? :roll:

Error from terminal :?:
$sudo python get_MERRA_albedo_from_nasa_opendap_dailyV1.py 2016
Traceback (most recent call last):
File "get_MERRA_albedo_from_nasa_opendap_dailyV1.py", line 85, in <module>
nc.variables['lat'][:] = lat
File "netCDF4/_netCDF4.pyx", line 4933, in netCDF4._netCDF4.Variable.__setitem__
TypeError: __array__() takes exactly 1 argument (2 given)
get_MERRA_albedo_from_nasa_opendap_dailyV1.py
Edited the USERNAME and PASSWORD
(4.13 KiB) Downloaded 415 times

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: PYROMS MERRA-2 Example

#2 Unread post by kate »

I haven't run the MERRA scripts since we switched to using JRA55-do some time back.

The "lat" on line 56 is creating the variable and setting it based on what's in the first file. The use on line 85 is using the existing "lat" to write it into a second file.

You can search on the error message and find that others have gotten something like that. The Stackoverflow messages don't tell me the answer, unfortunately. In an ideal world, someone should rewrite this using xarray instead.

Thronian

Re: PYROMS MERRA-2 Example

#3 Unread post by Thronian »

Hi Kate, what is JRA-55 script? :o

:idea:
I think most probably have a solution is by adding a line
lat = np.array(lat)
to convert latitude at line 56 "lat = dataset['lat'][:]" to array using "np.array(lat)" similar to "gidx", would technically solve the problem for the __array__ error with 2 args.

However, another error occur as it runs. at a different lines which state that

Traceback (most recent call last):
File "get_MERRA_albedo_from_nasa_opendap_dailyV1.py", line 115, in <module>
svar[:,:,:len(lon)-gidx] = var[:,:,gidx:]
TypeError: object of type 'numpy.int64' has no len()

at line 115, i suspect that line 116 are probably having error as well same as per line 115.
line 115 ---> svar[:,:,:len(lon)-gidx] = var[:,:,gidx:]
line 116 ---> svar[:,:,len(lon)-gidx:] = var[:,:,:gidx]

Thronian

Re: PYROMS MERRA-2 Example

#4 Unread post by Thronian »

Hi, this is an update post to inform that the previous one comment are the wrong method, I had managed to run MERRA-2 Example, using Year 2016 and Month of January with a few modifications on Python code I have done throughout the .py files,

ALBEDO
If you have install pyDAP like me, I would recommend to go for my method for simpler scripting or also you can set up an ~$HOME/.netrc file to keep credentials safer and input in to the url using python netrc module. Below is the modification I had add and change accordingly,

#Converting array into numpy array...so that could be able to convert to 0 - 360 deg by addition, also will remove conflicts occur for prev comment,
$gidx = np.where(np.abs(lon) < 1.0e-10)[0][0]
+ lon = np.asarray(lon)
$lon = lon + 180
$lat = dataset['lat'][:]
+ lat = np.asarray(lat)
+ var = np.asarray(var)

#Customize range of months according to user,
+ for month in range(12) ..... according to how many months required,

#Ignoring warning at the line which error due to missing values,
+ np.seterr(divide='ignore', invalid='ignore')
$var_daily = (svar * mask).sum(axis=0) / mask.sum(axis=0)
+ np.setter(divide='warn', invalid='warn') #......to reset this warnings

OTHERS .py files will be the same modification as ALBEDO, just that did not add lines to ignore the warning from missing values during the loop of days in month.

TAIR
$var = np.asarray(dataset[invarname][:]) - 273.15
OR
$var = np.asarray(var) - 273.15

RAIN
$var = dataset[invarname1][:] + dataset[invarname2][:] + dataset[invarname3][:]
change to
$var = np.asarray(dataset[invarname1][:]) + np.asarray(dataset[invarname2][:]) + np.asarray(dataset[invarname3][:])

Attached are at your reference. Thanks and All the best! :D
Attachments
get_MERRA_Tair_from_nasa_opendap_3hoursV1.py
TAIR
(3.91 KiB) Downloaded 405 times
get_MERRA_rain_from_nasa_opendap_3hoursV1.py
RAIN
(4.06 KiB) Downloaded 451 times
get_MERRA_albedo_from_nasa_opendap_dailyV1.py
ALBEDO
(4.62 KiB) Downloaded 427 times

reba1
Posts: 11
Joined: Thu Feb 24, 2022 9:24 pm
Location: india

Re: PYROMS MERRA-2 Example

#5 Unread post by reba1 »

Hi all,


I need to configure the roms model for forecast run . The initial, clim and bdry files are from HYCOM data(real-time data) using pyroms.I need to add the forcing files from GFS data.Can you share the script or idea how to create make_frc.py for GFS .
Any help will be highly appreciated

Post Reply