Example #1
0
def USGS2netcdf(ncfile, meta, time, discharge):
    """
    Convert the USGS files to netcdf4 format
    """

    shpfile = ncfile[:-2] + 'shp'

    varname = 'discharge'
    longname = 'Stream Discharge Rate'
    units = 'm3 s-1'

    ncdict = []
    ii = -1
    for tt, dd in zip(time, discharge):
        ii += 1
        timeout = othertime.MinutesSince(tt, basetime=datetime(1970, 1, 1))
        ncdict=netcdfio.createObsDict(varname,longname,units,[dd],[timeout],\
                      [meta['Latitude'][ii]],[meta['Longitude'][ii]],[0.0],[meta['Station ID'][ii]],[meta['StationName'][ii]],ncdict=ncdict )

    ## Global atts
    globalatts = {'Title': 'USGS stream gage discharge data'}
    # Write to a netcdf file
    netcdfio.writePointData2Netcdf(ncfile, ncdict, globalatts)
    # Write to a shape file
    netcdfio.pointNC2shp(ncfile, shpfile)
Example #2
0
def USGSgh2netcdf(ncfile, meta, time, gauge_height):
    """
    Convert the USGS files to netcdf4 format
    """

    shpfile = ncfile[:-2] + 'shp'

    varname = 'gauge_height'
    longname = 'Gauge height'
    units = 'm'

    ncdict = []
    ii = -1
    for tt, dd in zip(time, gauge_height):
        ii += 1
        timeout = othertime.MinutesSince(tt, basetime=datetime(1970, 1, 1))
        #ncdict=netcdfio.createObsDict(varname,longname,units,[dd],[timeout],\
        #              [meta['Latitude'][ii]],[meta['Longitude'][ii]],[0.0],[meta['Station ID'][ii]],[meta['StationName'][ii]],ncdict=ncdict )
        ncdict=netcdfio.createObsDict(varname,longname,units,[dd],[timeout],\
                      [meta['Latitude'][ii]],[meta['Longitude'][ii]],[meta['elevation'][ii]],[meta['Station ID'][ii]],[meta['StationName'][ii]],ncdict=ncdict )

    ## Global atts
    globalatts = {'Title': 'USGS gauge height data'}
    # Write to a netcdf file
    ## write to a single netcdf file with multi groups
    netcdfio.writePointData2Netcdf(ncfile, ncdict, globalatts)
    ## write to multi netcdf files
    #netcdfio.writePointData2Netcdf_new(ncfile,ncdict,globalatts)
    # Write to a shape file
    netcdfio.pointNC2shp(ncfile, shpfile)
Example #3
0
def USGS2netcdf(ncfile,meta,time,discharge):
    """
    Convert the USGS files to netcdf4 format
    """

    
    shpfile = ncfile[:-2]+'shp'
    
    varname = 'discharge'
    longname = 'Stream Discharge Rate'
    units = 'm3 s-1'
    
    ncdict=[]
    ii=-1
    for tt,dd in zip(time,discharge):
        ii+=1
        timeout = othertime.MinutesSince(tt,basetime=datetime(1970,1,1))
        ncdict=netcdfio.createObsDict(varname,longname,units,[dd],[timeout],\
                      [meta['Latitude'][ii]],[meta['Longitude'][ii]],[0.0],[meta['Station ID'][ii]],[meta['StationName'][ii]],ncdict=ncdict )
                      
    ## Global atts
    globalatts={'Title':'USGS stream gage discharge data'}
    # Write to a netcdf file
    netcdfio.writePointData2Netcdf(ncfile,ncdict,globalatts)
    # Write to a shape file
    netcdfio.pointNC2shp(ncfile,shpfile)


#####
## Example call
#
####
## Input variables
#stationids = ['08066500',\
#            '08078000',\
#            '08067500',\
#            '08076000',\
#            '08075000',\
#            '08074500',\
#            '08076500',\
#            '08073600',\
#            '08075770']
#            
#starttime = '2000-01-01'
#endtime = '2012-01-01'
#ncfile = 'C:/Projects/GOMGalveston/DATA/River/USGS_Rivers_20002012.nc'
####
#
#getUSGSnwis(stationids,starttime,endtime,ncfile)
Example #4
0
def noaaish2nc(latlon, yearrange, localdir, ncfile, shpfile):
    """ Reads in the noaa data and spits it out to a netcdf file"""

    varnames = ['Tair', 'Pair', 'Uwind', 'Vwind', 'RH', 'rain', 'cloud']
    # Read in the semi-processed data
    timestart = yearrange[0]
    timeend = yearrange[1]

    data = readall(latlon, [timestart, timeend], localdir)

    data = dataQC(data, varnames)

    # Create the dictionary format necessary to parse the data to a grouped netcdf file
    ncdict = []
    for dd in data:
        for vv in dd.keys():
            if vv in varnames:
                # Start building the dictionary
                if np.size(dd['Longitude']) > 0 or np.size(dd['Latitude']) > 0:
                    if dd[vv].has_key('Height'):
                        ele = dd[vv]['Height']
                    else:
                        ele = 0.0
                    coords = [{'Name':'longitude','Value':dd['Longitude'],'units':'degrees East'},\
                    {'Name':'latitude','Value':dd['Latitude'],'units':'degrees North'},\
                    {'Name':'elevation','Value':ele,'units':'metres','positive':'up'},\
                    {'Name':'time','Value':dd[vv]['Time'],'units':'minutes since 1970-01-01 00:00:00'}]

                    attribs = {'StationID':dd['StationID'],'StationName':dd['StationName'],'Data':dd[vv]['Data'],\
                    'coordinates':'time, elevation, longitude, latitude','long_name':dd[vv]['Longname'],\
                    'units':dd[vv]['Units'],'coords':coords}
                    ncdict.append({vv: attribs})
                else:
                    print 'Station: %s missing coordinate info - skipping' % dd[
                        'StationName']

    globalatts = {'title':'NCDC/NWS integrated surface hourly observation data',\
    'history':'Created on '+datetime.ctime(datetime.now()),\
    'source':'ftp://ftp.ncdc.noaa.gov/pub/data/ish/'}

    # Write the output to a netcdf file
    netcdfio.writePointData2Netcdf(ncfile, ncdict, globalatts)

    # Write the metadata to a shapefile
    netcdfio.pointNC2shp(ncfile, shpfile)

    return ncdict
def noaaish2nc(latlon,yearrange,localdir,ncfile,shpfile):
    
    """ Reads in the noaa data and spits it out to a netcdf file"""
    
    varnames = ['Tair','Pair','Uwind','Vwind','RH','rain','cloud']
    # Read in the semi-processed data
    timestart=yearrange[0]
    timeend=yearrange[1]

    data = readall(latlon,[timestart,timeend],localdir) 
    
    data = dataQC(data,varnames)
       
    # Create the dictionary format necessary to parse the data to a grouped netcdf file
    ncdict=[]
    for dd in data: 
        for vv in dd.keys():
            if vv in varnames:
                # Start building the dictionary
                if np.size(dd['Longitude'])>0 or np.size(dd['Latitude'])>0:
                    if dd[vv].has_key('Height'):
                        ele = dd[vv]['Height']
                    else:
                        ele=0.0
                    coords = [{'Name':'longitude','Value':dd['Longitude'],'units':'degrees East'},\
                    {'Name':'latitude','Value':dd['Latitude'],'units':'degrees North'},\
                    {'Name':'elevation','Value':ele,'units':'metres','positive':'up'},\
                    {'Name':'time','Value':dd[vv]['Time'],'units':'minutes since 1970-01-01 00:00:00'}]
                    
                    attribs = {'StationID':dd['StationID'],'StationName':dd['StationName'],'Data':dd[vv]['Data'],\
                    'coordinates':'time, elevation, longitude, latitude','long_name':dd[vv]['Longname'],\
                    'units':dd[vv]['Units'],'coords':coords} 
                    ncdict.append({vv:attribs})
                else:
                    print 'Station: %s missing coordinate info - skipping'%dd['StationName']
    
    globalatts = {'title':'NCDC/NWS integrated surface hourly observation data',\
    'history':'Created on '+datetime.ctime(datetime.now()),\
    'source':'ftp://ftp.ncdc.noaa.gov/pub/data/ish/'}            
    
    # Write the output to a netcdf file
    netcdfio.writePointData2Netcdf(ncfile,ncdict,globalatts)
    
    # Write the metadata to a shapefile
    netcdfio.pointNC2shp(ncfile,shpfile)
    
    return ncdict