[pyngl-talk] Ngl.contour problem, with masked array python 3
Fearon, Dr. Matthew, Contractor, Code 7533
matthew.fearon.ctr at nrlmry.navy.mil
Tue Jul 23 13:56:08 MDT 2019
Hi,
I was able to solve this error. Since ERA5 is global data, I needed to set
Ngl.add_cyclic for the data and the longitudes so mapping was correct. I
guess the key error was "contour_wrap":
SystemError: <built-in function contour_wrap> returned NULL without setting
an error
Matt
From: pyngl-talk [mailto:pyngl-talk-bounces at ucar.edu] On Behalf Of Fearon,
Dr. Matthew, Contractor, Code 7533 via pyngl-talk
Sent: Saturday, July 20, 2019 1:02 PM
To: pyngl-talk at ucar.edu
Subject: [pyngl-talk] Ngl.contour problem, with masked array python 3
Hi,
I'm reading in ERA5 netcdf (e.g., for MSLP) with Nio and trying to plot with
Ngl.contour. I've done this hundreds of times with Python 2.7 (Nio,Ngl), but
now with my new Python 3 version, I'm getting the following error, which I
don't understand. It appears a masked_array is a problem? I probably missed
something obvious.
Thanks for the help,
Matt
Error:
NumPy arrays must be of type int, int32, float, float0, float32, or float64.
Traceback (most recent call last):
File "./mapice.py", line 324, in <module>
main()
File "./mapice.py", line 320, in main
contour(band1,band2,band3,reds,blues,greens,xlat,xlon,ny,nx,mname,eslp,elat,
elon)
File "./mapice.py", line 166, in contour
contour_plot = Ngl.contour(wks,eice,clres)
File
"/users/fearon/software/anaconda3/envs/pyn_env3/lib/python3.7/site-packages/
ngl/__init__.py", line 2830, in contour
rlist2,rlist3,pvoid())
SystemError: <built-in function contour_wrap> returned NULL without setting
an error
Code snippet
erasfc = Nio.open_file(src_path+'/'+filelist[it]+'_sfc.nc',"r")
if (it == 0):
elat = erasfc.variables['latitude'][:]
elon = erasfc.variables['longitude'][:]
etmp = erasfc.variables['msl']
eslp = (etmp[0,:,:]*etmp.scale_factor + etmp.add_offset) / 100.
print (etmp.scale_factor)
[0.22592911]]
print (etmp.add_offset)
[99425.54328544]
print (type(eslp))
<class 'numpy.ma.core.MaskedArray'>
print (eslp)
[[1009.1622356675263 1009.1622356675263 1009.1622356675263 ...
1009.1622356675263 1009.1622356675263 1009.1622356675263]
[1009.5146850823248 1009.5146850823248 1009.5146850823248 ...
1009.5146850823248 1009.5146850823248 1009.5146850823248]
[1009.8445415859185 1009.8445415859185 1009.8445415859185 ...
1009.8445415859185 1009.8445415859185 1009.8445415859185]
...
[1013.2334782666748 1013.2447747222774 1013.2538118867593 ...
1013.2018481909877 1013.2108853554698 1013.2244411021928]
[1012.5963581706925 1012.5986174618131 1012.6031360440542 ...
1012.5805431328491 1012.5873210062106 1012.5918395884515]
[1012.0428318461692 1012.0428318461692 1012.0428318461692 ...
1012.0428318461692 1012.0428318461692 1012.0428318461692]
#Line contour settings
clres = Ngl.Resources()
clres.nglFrame = False
clres.nglDraw = False
clres.sfXArray = elon
clres.sfYArray = elat
clres.cnFillOn = False
clres.cnFillDrawOrder = "PreDraw"
clres.cnLinesOn = True
clres.cnLineColor = "red"
clres.cnLineThicknessF = 5
clres.cnLineLabelsOn = False
clres.cnLineLabelFontHeightF = 0.010
clres.cnLineLabelPerimOn = False
clres.cnLineLabelBackgroundColor = -1
clres.cnInfoLabelOn = False
# clres.cnLevelSelectionMode = "ExplicitLevels"
# clres.cnLevels = [0.15]
# clres.cnMinLevelValF = 957
# clres.cnMaxLevelValF = 1002
# clres.cnLevelSpacingF = 2
# clres.cnLineLabelInterval = 1
contour_plot = Ngl.contour(wks,eice,clres)
Ngl.overlay(map_plot,contour_plot)]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20190723/20e6e664/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5442 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20190723/20e6e664/attachment-0001.p7s>
More information about the pyngl-talk
mailing list