2017-04-25 1 views
2

enter image description here Espérons que ce soit quelque chose que je suis naïvement négliger, mais je n'arrive pas à comprendre pourquoi mon tracé de pcolor ne montre aucune de mes données. J'ai 2D lat/lon, avec un pas de temps de 2D concentrations de glace de mer. Tous les conseils seraient appréciés ce que je suis en train ci-dessous:2d lat/lon data pourquoi mon graphique de pcolor ne dessine pas les données

from netCDF4 import Dataset 
import numpy as np 
import matplotlib.pyplot as plt 
from mpl_toolkits.basemap import Basemap 

# ifile='upper_box.nc' # doesn't produce any plot 
ifile='1979_sfc_out.nc' 

fh = Dataset(ifile,mode='r') 
lons=fh.variables['lon'][:] 
lats=fh.variables['lat'][:] 
seaice=fh.variables['SEAICE'][:] 

seaice_units = fh.variables['SEAICE'].units 
fh.close() 

# set basemap instance, specifying our desired map and projection settings 

lon_0 = lons.mean() 
lat_0 = lats.mean() 

m = Basemap(width=5000000,height=3500000, 
      resolution='l',projection='stere',\ 
      lat_ts=40,lat_0=lat_0,lon_0=lon_0) 

# Plot Data 
# one timestep 
seaice_firstTimestep = seaice[0,:,:] 
cs = m.pcolor(lons,lats,seaice_firstTimestep) 

# Add Grid Lines 
#m.drawparallels(np.arange(-80., 81., 10.), labels=[1,0,0,0], fontsize=10) 
#m.drawmeridians(np.arange(-180., 181., 10.), labels=[0,0,0,1], fontsize=10) 

# Add Coastlines, States, and Country Boundaries 
m.drawcoastlines() 
m.drawstates() 
m.drawcountries() 

# Add Colorbar 
cbar = m.colorbar(cs, location='bottom', pad="10%") 
cbar.set_label(seaice_units) 

# Add Title 
plt.title('Sea ice upper box') 

plt.show() 

Mes données est là et la portée du colorbar est correcte:

>>> seaice_firstTimestep[70:80,70:80] 
array([[ 0.  , 0.  , 0.  , 0.  , 0.  , 
     0.  , 0.  , 0.  , 0.  , 0.90625 ], 
     [ 0.  , 0.  , 0.  , 0.  , 0.  , 
     0.  , 0.  , 0.9140625, 0.9140625, 0.9140625], 
     [ 0.  , 0.9375 , 0.9375 , 0.9296875, 0.9296875, 
     0.921875 , 0.9140625, 0.9140625, 0.9140625, 0.9140625], 
     [ 0.953125 , 0.9453125, 0.9375 , 0.9375 , 0.921875 , 
     0.921875 , 0.9140625, 0.9140625, 0.9140625, 0.9140625], 
     [ 0.9453125, 0.9453125, 0.9453125, 0.9375 , 0.9296875, 
     0.921875 , 0.9140625, 0.9140625, 0.9140625, 0.9140625], 
     [ 0.9453125, 0.9453125, 0.9453125, 0.9453125, 0.9375 , 
     0.9296875, 0.921875 , 0.921875 , 0.921875 , 0.921875 ], 
     [ 0.9453125, 0.953125 , 0.953125 , 0.9453125, 0.9375 , 
     0.9375 , 0.9296875, 0.9296875, 0.9296875, 0.9296875], 
     [ 0.953125 , 0.953125 , 0.953125 , 0.9453125, 0.9453125, 
     0.9375 , 0.9375 , 0.9375 , 0.9375 , 0.9375 ], 
     [ 0.9453125, 0.953125 , 0.953125 , 0.9453125, 0.9453125, 
     0.9453125, 0.9453125, 0.9453125, 0.9453125, 0.9453125], 
     [ 0.9453125, 0.9453125, 0.953125 , 0.9453125, 0.9453125, 
     0.9453125, 0.9453125, 0.9453125, 0.9453125, 0.9453125]], dtype=float32) 
>>> 

Mon ncdump est ici, peut-être qu'il ne sait pas où situer la concentration de glace de mer, car mes dimensions sont x, y et non lat/lon?

netcdf \1979_sfc_out { 
dimensions: 
     x = 83 ; 
     y = 94 ; 
     time = UNLIMITED ; // (8736 currently) 
     nv4 = 4 ; 
variables: 
     float time(time) ; 
       time:axis = "T" ; 
       time:long_name = "time" ; 
       time:standard_name = "time" ; 
       time:units = "hours since 1979-1-2 00:00:00" ; 
       time:calendar = "standard" ; 
     float x(x) ; 
       x:axis = "x" ; 
       x:long_name = "X-coordinate in Cartesian system" ; 
       x:standard_name = "projection_x_coordinate" ; 
       x:units = "meters" ; 
     float y(y) ; 
       y:axis = "y" ; 
       y:long_name = "Y-coordinate in Cartesian system" ; 
       y:standard_name = "projection_y_coordinate" ; 
       y:units = "meters" ; 
     float lon(y, x) ; 
       lon:units = "degrees_east" ; 
       lon:valid_range = -180., 180. ; 
       lon:standard_name = "longitude" ; 
       lon:bounds = "lon_bnds" ; 
     float lat(y, x) ; 
       lat:units = "degrees_north" ; 
       lat:valid_range = -90., 90. ; 
       lat:standard_name = "latitude" ; 
       lat:bounds = "lat_bnds" ; 
     float lon_bnds(y, x, nv4) ; 
       lon_bnds:units = "degreesE" ; 
     float lat_bnds(y, x, nv4) ; 
       lat_bnds:units = "degreesN" ; 
     char mapping ; 
       mapping:false_easting = 0. ; 
       mapping:false_northing = 0. ; 
       mapping:grid_mapping_name = "polar_stereographic" ; 
       mapping:latitude_of_projection_origin = 90. ; 
       mapping:standard_parallel = 64. ; 
       mapping:straight_vertical_longitude_from_pole = -152. ; 
       mapping:semi_major_axis = 6370000. ; 
       mapping:semi_minor_axis = 6370000. ; 
     float SEAICE(time, y, x) ; 
       SEAICE:_FillValue = -9999.f ; 
       SEAICE:units = "fraction" ; 
       SEAICE:long_name = "Ice concentration (ice=1;no ice=0)" ; 
       SEAICE:grid_mapping = "mapping" ; 
       SEAICE:coordinates = "lon lat" ; 
     float U10(time, y, x) ; 
       U10:_FillValue = -9999.f ; 
       U10:units = "m/s" ; 
       U10:long_name = "U-component of wind at 10m height" ; 
       U10:grid_mapping = "mapping" ; 
       U10:coordinates = "lon lat" ; 
     float V10(time, y, x) ; 
       V10:_FillValue = -9999.f ; 
       V10:units = "m/s" ; 
       V10:long_name = "V-component of wind at 10m height" ; 
       V10:grid_mapping = "mapping" ; 
       V10:coordinates = "lon lat" ; 

Répondre

1

Avant de dessiner, vous devez convertir votre grille lat-lot à la projection quelque chose lat-lon comme ici:

m = Basemap(width=5000000,height=3500000, 
      resolution='l',projection='stere',\ 
      lat_ts=40,lat_0=lat_0,lon_0=lon_0) 

LON,LAT = m(lons,lats) 

Utilisez ensuite une nouvelle LAT, LON tout en traçant en fonction de la projection:

cs = m.pcolor(LON,LAT,seaice_firstTimestep)

Pour plus d'informations lire ce manuel: https://matplotlib.org/basemap/users/mapcoords.html