[Met_help] [rt.rap.ucar.edu #84841] History for Post-plot of MET
Julie Prestopnik via RT
met_help at ucar.edu
Wed Apr 25 08:54:16 MDT 2018
----------------------------------------------------------------
Initial Request
----------------------------------------------------------------
good morning,
I am currently plotting MET with basemap of python, I have one problem with MET v6.0:bm = get_basemap(temp)from netCDF4 import Dataset
ValueError: 'var' object does not contain coordinate attributes
how can i add the coordinate attributes to an exisited value.
###############################
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
from wrf import getvar, interplevel, to_np, get_basemap, latlon_coords
ncfile1 = Dataset('mode_obj.nc','r')
data = Dataset('./data.nc', 'w', format='NETCDF4_CLASSIC')
var = ncfile1.variables['fcst_clus_id']####this value have none coordinate attributes
latf = ncfile1.variables['lat']
lonf = ncfile1.variables['lon']
nlats = len(ncfile1.dimensions["lat"])
nlons = len(ncfile1.dimensions["lon"])
lat = data.createDimension("lat", nlats)###
lat = latf
lon = data.createDimension("lon", nlons)
lon = lonf
latitudes = data.createVariable('latitude', np.int32,('lat','lon'))
print(latitudes)
latitudes[:]=latf[:]
#print(latitudes)
longitudes = data.createVariable('longitude', np.int32,('lat','lon'))
longitudes[:] = lonf[:]
temp = data.createVariable('temp', np.int32,('lat','lon'))
temp[:]=var[:]
# Get the lat/lon coordinates
#lats, lons = latlon_coords(temp)
# Get the basemap object
bm = get_basemap(temp)#####
# Create the figure
fig = plt.figure(figsize=(12,9))
ax = plt.axes()
# Convert the lat/lon coordinates to x/y coordinates in the projection space
x, y = bm(to_np(lonf), to_np(latf))
levels = [-1,0,1,2]
contours = bm.contour(x, y, to_np(temp), levels=levels, colors="black")
plt.clabel(contours, inline=1, fontsize=10, fmt="%i")
plt.savefig('a.png')
----------------------------------------------------------------
Complete Ticket History
----------------------------------------------------------------
Subject: Post-plot of MET
From: Julie Prestopnik
Time: Fri Apr 20 08:58:36 2018
Hi. I see you are having difficulty interacting with MET output and
Python. Could you please send the full Traceback output along with
the
command line that you are using to run your script?
Also, please upload the your Python script and your NetCDF data to our
ftp site
using the following instructions and let us know once you have done
that so
that we can get the files and take a closer look.
http://www.dtcenter.org/met/users/support/met_help.php#ftp
Thanks!
Julie
On Thu, Apr 19, 2018 at 11:32 PM, 刘冲 via RT <met_help at ucar.edu> wrote:
>
> Thu Apr 19 23:32:57 2018: Request 84841 was acted upon.
> Transaction: Ticket created by liuchongcn at 126.com
> Queue: met_help
> Subject: Post-plot of MET
> Owner: Nobody
> Requestors: liuchongcn at 126.com
> Status: new
> Ticket <URL:
https://rt.rap.ucar.edu/rt/Ticket/Display.html?id=84841 >
>
>
> good morning,
> I am currently plotting MET with basemap of python, I have one
problem
> with MET v6.0:bm = get_basemap(temp)from netCDF4 import Dataset
> ValueError: 'var' object does not contain coordinate attributes
> how can i add the coordinate attributes to an exisited value.
> ###############################
> import numpy as np
> import matplotlib.pyplot as plt
> from matplotlib.cm import get_cmap
> from wrf import getvar, interplevel, to_np, get_basemap,
latlon_coords
>
>
> ncfile1 = Dataset('mode_obj.nc','r')
> data = Dataset('./data.nc', 'w', format='NETCDF4_CLASSIC')
> var = ncfile1.variables['fcst_clus_id']####this value have none
> coordinate attributes
> latf = ncfile1.variables['lat']
> lonf = ncfile1.variables['lon']
> nlats = len(ncfile1.dimensions["lat"])
> nlons = len(ncfile1.dimensions["lon"])
> lat = data.createDimension("lat", nlats)###
> lat = latf
> lon = data.createDimension("lon", nlons)
> lon = lonf
> latitudes = data.createVariable('latitude', np.int32,('lat','lon'))
> print(latitudes)
> latitudes[:]=latf[:]
> #print(latitudes)
> longitudes = data.createVariable('longitude',
np.int32,('lat','lon'))
> longitudes[:] = lonf[:]
> temp = data.createVariable('temp', np.int32,('lat','lon'))
> temp[:]=var[:]
>
> # Get the lat/lon coordinates
> #lats, lons = latlon_coords(temp)
> # Get the basemap object
> bm = get_basemap(temp)#####
>
> # Create the figure
> fig = plt.figure(figsize=(12,9))
> ax = plt.axes()
>
> # Convert the lat/lon coordinates to x/y coordinates in the
projection
> space
> x, y = bm(to_np(lonf), to_np(latf))
> levels = [-1,0,1,2]
> contours = bm.contour(x, y, to_np(temp), levels=levels,
colors="black")
> plt.clabel(contours, inline=1, fontsize=10, fmt="%i")
>
> plt.savefig('a.png')
>
------------------------------------------------
Subject: Post-plot of MET
From: 刘冲
Time: Fri Apr 20 20:56:31 2018
Hello, I have put my Python script and your NetCDF data to the ftp
site. PATH is
"/incoming/irap/met_help/Liu_data"
following is python show:
(python3.6) [cliu at c03n02 result_d02]$ python test-data.py
<type 'netCDF4._netCDF4.Variable'>
float32 lat(lat, lon)
long_name: latitude
units: degrees_north
standard_name: latitude
unlimited dimensions:
current shape = (69, 84)
filling on, default _FillValue of 9.96920996839e+36 used
<type 'netCDF4._netCDF4.Variable'>
int32 latitude(lat, lon)
unlimited dimensions:
current shape = (69, 84)
filling on, default _FillValue of -2147483647 used
Traceback (most recent call last):
File "test-data.py", line 41, in <module>
lata, lona = latlon_coords(temp)
File
"/users1j/cliu/soft/anaconda2/envs/python3.6/lib/python2.7/site-
packages/wrf/util.py", line 3408, in latlon_coords
raise ValueError("'var' object does not contain coordinate "
ValueError: 'var' object does not contain coordinate attributes
---------------------------------------------------------------------------------
My mode commad is ' mode WRFPRS_d02.51_CHEM
CMORPH_r_d02_3HLY_20170610_03.grb
../tutorial/6.0/tutorial/config/MODEConfig_tutorial -outdir
result_d02/chem/ -v 2'
Thanks for your help!
------------------------------------------------------------------------------------
At 2018-04-20 22:58:36, "Julie Prestopnik via RT" <met_help at ucar.edu>
wrote:
>Hi. I see you are having difficulty interacting with MET output and
>Python. Could you please send the full Traceback output along with
the
>command line that you are using to run your script?
>
>Also, please upload the your Python script and your NetCDF data to
our ftp site
>using the following instructions and let us know once you have done
that so
>that we can get the files and take a closer look.
>
>http://www.dtcenter.org/met/users/support/met_help.php#ftp
>
>Thanks!
>
>Julie
>
>
>On Thu, Apr 19, 2018 at 11:32 PM, 刘冲 via RT <met_help at ucar.edu>
wrote:
>
>>
>> Thu Apr 19 23:32:57 2018: Request 84841 was acted upon.
>> Transaction: Ticket created by liuchongcn at 126.com
>> Queue: met_help
>> Subject: Post-plot of MET
>> Owner: Nobody
>> Requestors: liuchongcn at 126.com
>> Status: new
>> Ticket <URL:
https://rt.rap.ucar.edu/rt/Ticket/Display.html?id=84841 >
>>
>>
>> good morning,
>> I am currently plotting MET with basemap of python, I have one
problem
>> with MET v6.0:bm = get_basemap(temp)from netCDF4 import Dataset
>> ValueError: 'var' object does not contain coordinate attributes
>> how can i add the coordinate attributes to an exisited value.
>> ###############################
>> import numpy as np
>> import matplotlib.pyplot as plt
>> from matplotlib.cm import get_cmap
>> from wrf import getvar, interplevel, to_np, get_basemap,
latlon_coords
>>
>>
>> ncfile1 = Dataset('mode_obj.nc','r')
>> data = Dataset('./data.nc', 'w', format='NETCDF4_CLASSIC')
>> var = ncfile1.variables['fcst_clus_id']####this value have none
>> coordinate attributes
>> latf = ncfile1.variables['lat']
>> lonf = ncfile1.variables['lon']
>> nlats = len(ncfile1.dimensions["lat"])
>> nlons = len(ncfile1.dimensions["lon"])
>> lat = data.createDimension("lat", nlats)###
>> lat = latf
>> lon = data.createDimension("lon", nlons)
>> lon = lonf
>> latitudes = data.createVariable('latitude', np.int32,('lat','lon'))
>> print(latitudes)
>> latitudes[:]=latf[:]
>> #print(latitudes)
>> longitudes = data.createVariable('longitude',
np.int32,('lat','lon'))
>> longitudes[:] = lonf[:]
>> temp = data.createVariable('temp', np.int32,('lat','lon'))
>> temp[:]=var[:]
>>
>> # Get the lat/lon coordinates
>> #lats, lons = latlon_coords(temp)
>> # Get the basemap object
>> bm = get_basemap(temp)#####
>>
>> # Create the figure
>> fig = plt.figure(figsize=(12,9))
>> ax = plt.axes()
>>
>> # Convert the lat/lon coordinates to x/y coordinates in the
projection
>> space
>> x, y = bm(to_np(lonf), to_np(latf))
>> levels = [-1,0,1,2]
>> contours = bm.contour(x, y, to_np(temp), levels=levels,
colors="black")
>> plt.clabel(contours, inline=1, fontsize=10, fmt="%i")
>>
>> plt.savefig('a.png')
>>
------------------------------------------------
Subject: Post-plot of MET
From: Julie Prestopnik
Time: Mon Apr 23 11:12:37 2018
Hi. I see that the error is not coming from MET, but rather is coming
from
the wrf-python package in util.py code. From your test-data.py script
it
looks like you are creating a variable called "temp" that you are
passing
to a latlon_coords function from the wrf-python package, which is then
returning the error you are seeing.
Information for the support for the wrf-python can be found here:
http://wrf-python.readthedocs.io/en/latest/support.html
I have never used the wrf-python package and am not familiar with what
you
are experiencing. Hopefully, the support for wrf-python will be able
to
help you further.
Julie
On Fri, Apr 20, 2018 at 8:56 PM, 刘冲 via RT <met_help at ucar.edu> wrote:
>
> <URL: https://rt.rap.ucar.edu/rt/Ticket/Display.html?id=84841 >
>
> Hello, I have put my Python script and your NetCDF data to the ftp
site.
> PATH is
>
>
> "/incoming/irap/met_help/Liu_data"
>
>
> following is python show:
> (python3.6) [cliu at c03n02 result_d02]$ python test-data.py
> <type 'netCDF4._netCDF4.Variable'>
> float32 lat(lat, lon)
> long_name: latitude
> units: degrees_north
> standard_name: latitude
> unlimited dimensions:
> current shape = (69, 84)
> filling on, default _FillValue of 9.96920996839e+36 used
>
> <type 'netCDF4._netCDF4.Variable'>
> int32 latitude(lat, lon)
> unlimited dimensions:
> current shape = (69, 84)
> filling on, default _FillValue of -2147483647 used
>
> Traceback (most recent call last):
> File "test-data.py", line 41, in <module>
> lata, lona = latlon_coords(temp)
> File
"/users1j/cliu/soft/anaconda2/envs/python3.6/lib/python2.7/site-
packages/wrf/util.py",
> line 3408, in latlon_coords
> raise ValueError("'var' object does not contain coordinate "
> ValueError: 'var' object does not contain coordinate attributes
>
> ------------------------------------------------------------
> ---------------------
> My mode commad is ' mode WRFPRS_d02.51_CHEM
CMORPH_r_d02_3HLY_20170610_03.grb
> ../tutorial/6.0/tutorial/config/MODEConfig_tutorial -outdir
> result_d02/chem/ -v 2'
> Thanks for your help!
> ------------------------------------------------------------
> ------------------------
>
>
> At 2018-04-20 22:58:36, "Julie Prestopnik via RT"
<met_help at ucar.edu>
> wrote:
> >Hi. I see you are having difficulty interacting with MET output
and
> >Python. Could you please send the full Traceback output along with
the
> >command line that you are using to run your script?
> >
> >Also, please upload the your Python script and your NetCDF data to
our
> ftp site
> >using the following instructions and let us know once you have done
that
> so
> >that we can get the files and take a closer look.
> >
> >http://www.dtcenter.org/met/users/support/met_help.php#ftp
> >
> >Thanks!
> >
> >Julie
> >
> >
> >On Thu, Apr 19, 2018 at 11:32 PM, 刘冲 via RT <met_help at ucar.edu>
wrote:
> >
> >>
> >> Thu Apr 19 23:32:57 2018: Request 84841 was acted upon.
> >> Transaction: Ticket created by liuchongcn at 126.com
> >> Queue: met_help
> >> Subject: Post-plot of MET
> >> Owner: Nobody
> >> Requestors: liuchongcn at 126.com
> >> Status: new
> >> Ticket <URL:
https://rt.rap.ucar.edu/rt/Ticket/Display.html?id=84841 >
> >>
> >>
> >> good morning,
> >> I am currently plotting MET with basemap of python, I have one
problem
> >> with MET v6.0:bm = get_basemap(temp)from netCDF4 import Dataset
> >> ValueError: 'var' object does not contain coordinate attributes
> >> how can i add the coordinate attributes to an exisited value.
> >> ###############################
> >> import numpy as np
> >> import matplotlib.pyplot as plt
> >> from matplotlib.cm import get_cmap
> >> from wrf import getvar, interplevel, to_np, get_basemap,
latlon_coords
> >>
> >>
> >> ncfile1 = Dataset('mode_obj.nc','r')
> >> data = Dataset('./data.nc', 'w', format='NETCDF4_CLASSIC')
> >> var = ncfile1.variables['fcst_clus_id']####this value have none
> >> coordinate attributes
> >> latf = ncfile1.variables['lat']
> >> lonf = ncfile1.variables['lon']
> >> nlats = len(ncfile1.dimensions["lat"])
> >> nlons = len(ncfile1.dimensions["lon"])
> >> lat = data.createDimension("lat", nlats)###
> >> lat = latf
> >> lon = data.createDimension("lon", nlons)
> >> lon = lonf
> >> latitudes = data.createVariable('latitude',
np.int32,('lat','lon'))
> >> print(latitudes)
> >> latitudes[:]=latf[:]
> >> #print(latitudes)
> >> longitudes = data.createVariable('longitude',
np.int32,('lat','lon'))
> >> longitudes[:] = lonf[:]
> >> temp = data.createVariable('temp', np.int32,('lat','lon'))
> >> temp[:]=var[:]
> >>
> >> # Get the lat/lon coordinates
> >> #lats, lons = latlon_coords(temp)
> >> # Get the basemap object
> >> bm = get_basemap(temp)#####
> >>
> >> # Create the figure
> >> fig = plt.figure(figsize=(12,9))
> >> ax = plt.axes()
> >>
> >> # Convert the lat/lon coordinates to x/y coordinates in the
projection
> >> space
> >> x, y = bm(to_np(lonf), to_np(latf))
> >> levels = [-1,0,1,2]
> >> contours = bm.contour(x, y, to_np(temp), levels=levels,
colors="black")
> >> plt.clabel(contours, inline=1, fontsize=10, fmt="%i")
> >>
> >> plt.savefig('a.png')
> >>
>
>
------------------------------------------------
More information about the Met_help
mailing list