Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>try this:</p> <pre><code>import urllib2 import urllib url = 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_hd.pl' forecast_time = '06' #What time the forecast is (00, 06, 12, 18) forecast_hours = '09' #How many hours ahead to forecast (2 or 3 digits) forecast_date = '20120705' #What date the forecast is for yyyymmdd get_parameters = { 'subregion':'', 'toplat':90, #Top of bounding box (North) 'bottomlat':-90, #Bottom of bounding box (South) 'leftlon':-90, #Left of bounding box (West) 'rightlon':90, #Right of bounding box (East) } get_parameters['file'] = 'gfs.t' + forecast_time + 'z.mastergrb2f' + forecast_hours on_variables = [ 'lev_1000_mb', 'lev_975_mb', 'lev_950_mb', 'lev_925_mb', 'lev_900_mb', 'lev_850_mb', 'lev_800_mb', 'lev_750_mb', 'lev_700_mb', 'lev_650_mb', 'lev_600_mb', 'lev_550_mb', 'lev_500_mb', 'lev_450_mb', 'lev_400_mb', 'lev_350_mb', 'lev_300_mb', 'lev_250_mb', 'lev_200_mb', 'lev_150_mb', 'lev_100_mb', 'lev_70_mb', 'lev_30_mb', 'lev_20_mb', 'lev_10_mb', 'var_HGT', #Height (geopotential m) 'var_RH', #Relative humidity (%) 'var_TMP', #Temperature (K) 'var_UGRD', #East-West component of wind (m/s) 'var_VGRD', #North-South component of wind (m/s) 'var_VVEL' #Vertical Windspeed (Pa/s) ] get_parameters.update(dict((param, 'on') for param in on_variables)) #Select date and time get_parameters['dir'] = '/gfs.' + forecast_date + forecast_time + '/master' print('Downloading GRIB file for date '+forecast_date+' time ' +forecast_time + ', forecasting '+forecast_hours+' hours ahead...') req = urllib2.urlopen(url + '?' + urllib.urlencode(get_parameters), timeout = 300) # Theres bug in apache for non-used GET varaibles so we have to manually add them to the url ... local_filename = forecast_date + '_' + forecast_time + '_' + forecast_hours + '.grib' local_file = open('/home/dantayaga/bovine_aerospace/grib/data/' + local_filename, 'wb') local_file.write(req.read()) local_file.close() print('Requested grib data written to file ' + local_filename) </code></pre> <p>I've tested it with another file since the one you had in your original code, doesn't exist I get:</p> <blockquote> <p>Data file is not present: /pub/data/nccf/com/gfs/prod/gfs.2012070706/master27/gfs.t06z.mastergrb2f12</p> </blockquote> <p>try to use dictionaries, list, tuples or other complex data structures to store your parameters, this way you'll be able to detect subtle bugs much sooner, and reduce duplicate code. </p> <p><code>urllib2.urlopen</code> has an optional parameter called <code>data</code> thats used to pass parameter but unfortunately theres a bug in either apache or python since I keep getting <code>raise IncompleteRead(value)</code> </p> <p><a href="https://stackoverflow.com/questions/3670257/httplib-incomplete-read">httplib: incomplete read</a><br/> <a href="http://bugs.python.org/issue14044" rel="nofollow noreferrer">http://bugs.python.org/issue14044</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload