import pyGDP import os dataSetURI = 'http://cida.usgs.gov/thredds/dodsC/new_gmo' elevDataURI = 'http://ags.cr.usgs.gov/ArcGIS/services/NED_1/MapServer/WMSServer' attribute = 'GAGE_ID' shapefile = 'upload:bas_ref_west_conus' out_dir = 'gdp_data_hcdn_ref_west' gis_file = 'gis/bas_ref_west_conus.zip' def tryUpload(gdp, file): # upload the file to geoserver try: gdp.uploadShapeFile(file) except Exception: pass else: print 'Shapefile uploaded sucessfully.' variables = ['pr', 'tas', 'tasmax', 'tasmin', 'wind'] # create output dir if not os.path.exists(out_dir): os.makedirs(out_dir) # init class to download data gdp = pyGDP.pyGDPwebProcessing() # upload the file to geoserver tryUpload(gdp, gis_file) # use the commented out lines for interactive analysis # shapefiles = gdp.getShapefiles() # attributes = gdp.getAttributes(shapefile) variables = gdp.getDataType(dataSetURI) values = gdp.getValues(shapefile, attribute) for variable in variables: # re-try the upload just to be safe, I think they clean things out # periodically tryUpload(gis_file) subdir = os.path.join(out_dir, variable) if not os.path.exists(subdir): os.makedirs(subdir) timeRange = gdp.getTimeRange(dataSetURI, variable) print variable for t in timeRange: print ' ' + t for value in values: output_file = os.path.join(subdir, value + '.csv') if not(os.path.exists(output_file)): print ' Retrieving %s...' % (output_file) prelim_output = gdp.submitFeatureWeightedGridStatistics(shapefile, dataSetURI, variable, timeRange[0],timeRange[1], attribute, value, gmlIDs=None,verbose=False) os.rename(prelim_output, output_file) print ' Done.' print 'No more data to download.'