Пример #1
0
def write2db(dbfile):
    '''
    The function below aims at writing the resulting river inflow data
    and tide data into the database file
    ''' 
    #Update and write the resulting data into the database file
    create = True
    #dbfile = 'GalvestonObs.db'
    #dire1=os.path.dirname(os.path.abspath(__file__))
    dire1=os.getcwd()
    #dire1=os.path.dirname(dire2)
    folder = dire1+'/DATA/'
    #pdb.set_trace()
    ncfiles = [folder+'USGS_Rivers.nc',folder+'TCOONTide.nc']

    if create:
        print 'Creating database: %s'%dbfile
        netcdfio.createObsDB(dbfile)
    
    for nc in ncfiles:
        print 'Inserting metadata from: %s'%nc    
        netcdfio.netcdfObs2DB(nc,dbfile)

    print 'Done.'
    if os.path.isfile(folder+dbfile):
        os.remove(folder+dbfile) 
    copy_file(dbfile, folder)
Пример #2
0
def main(vartype, bbox, timestart, timeend, ncfile, dbfile=None):
    varlookup ={'CurrentsActive':'currents','WaterLevelActive':'water_surface_height_above_reference_datum',\
    'Salinity':'sea_water_salinity','Conductivity':'sea_water_electrical_conductivity'}

    # Find the stations
    staInfo = stationInfo(vartype)
    for vv in list(staInfo.keys()):
        if staInfo[vv]['lon'] >= bbox[0] and staInfo[vv]['lon'] <= bbox[
                1] and staInfo[vv]['lat'] >= bbox[2] and staInfo[vv][
                    'lat'] <= bbox[3]:
            print('Station %s inside lat-lon range.' % staInfo[vv]['name'])
        else:
            staInfo.pop(vv)

    ncdata = []
    for ID in list(staInfo.keys()):
        print('Getting %s data from %s' % (vartype, staInfo[ID]['name']))

        # Grab the station data
        data = getAllTime(ID, varlookup[vartype], timestart, timeend)

        ###
        if len(data) > 0:
            # Convert the output to the format required for the netcdf file
            if vartype == 'CurrentsActive':
                ncdatatmp = parseADCPdata(data, staInfo, ID)
            elif vartype == 'WaterLevelActive':
                ncdatatmp = parseWaterLev(data, staInfo, ID)

            ncdata += ncdatatmp

    # Write to the output netcdf
    globalatts = {'title':'US-IOOS observation data',\
        'history':'Created on '+datetime.ctime(datetime.now()),\
        'source':'http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/index.jsp'}
    netcdfio.writePointData2Netcdf(ncfile, ncdata, globalatts)

    # Write the metadata to a shapefile
    #shpfile = ncfile.split('.')[0]+'.shp'
    #netcdfio.pointNC2shp(ncfile,shpfile)

    # Update the database
    #createObsDB(dbfile)
    if not dbfile == None:
        print('Updating database: %s' % dbfile)
        netcdfio.netcdfObs2DB(ncfile, dbfile)
Пример #3
0
def main(vartype,bbox,timestart,timeend,ncfile,dbfile=None):
    varlookup ={'CurrentsActive':'currents','WaterLevelActive':'water_surface_height_above_reference_datum',\
    'Salinity':'sea_water_salinity','Conductivity':'sea_water_electrical_conductivity'}
    
    
    # Find the stations
    staInfo = stationInfo(vartype)
    for vv in staInfo.keys():
        if staInfo[vv]['lon']>=bbox[0] and staInfo[vv]['lon']<=bbox[1] and staInfo[vv]['lat']>=bbox[2] and staInfo[vv]['lat']<=bbox[3]:
            print 'Station %s inside lat-lon range.' % staInfo[vv]['name']
        else:
            staInfo.pop(vv)
    
    ncdata=[]
    for ID in staInfo.keys():
        print 'Getting %s data from %s' % (vartype,staInfo[ID]['name'])
        
        # Grab the station data
        data = getAllTime(ID,varlookup[vartype],timestart,timeend)
        
        ###
        if len(data)>0:
            # Convert the output to the format required for the netcdf file
            if vartype == 'CurrentsActive':
                ncdatatmp=parseADCPdata(data,staInfo,ID)
            elif vartype == 'WaterLevelActive':
                ncdatatmp=parseWaterLev(data,staInfo,ID)
        
            ncdata+=ncdatatmp
        
    # Write to the output netcdf
    globalatts = {'title':'US-IOOS observation data',\
        'history':'Created on '+datetime.ctime(datetime.now()),\
        'source':'http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/index.jsp'}    
    netcdfio.writePointData2Netcdf(ncfile,ncdata,globalatts)
        
    # Write the metadata to a shapefile
    #shpfile = ncfile.split('.')[0]+'.shp'
    #netcdfio.pointNC2shp(ncfile,shpfile)
    
    # Update the database
    #createObsDB(dbfile)
    if not dbfile == None:
        print 'Updating database: %s'%dbfile
        netcdfio.netcdfObs2DB(ncfile,dbfile)                
Пример #4
0
# Set the date range slightly larger just in case
tstart = datetime.strptime(timestart,'%Y%m%d')-timedelta(days=30)
tend = datetime.strptime(timeend,'%Y%m%d')+timedelta(days=30)

latlon = [lon0-dx,lon0+dx,lat0-dx,lat0+dx]

data = noaa.noaaish2nc(latlon,[tstart.year,tend.year],localdir,ncfile,shpfile)

###
# Step 2: Create a database and insert the netcdf metadata into it
###
print 'Creating database: %s'%dbfile
    
if os.path.exists(dbfile):
    print 'Overwriting old file...'
    os.unlink(dbfile)
    
netcdfio.createObsDB(dbfile)
    
ncfiles=[ncfile]
for nc in ncfiles:
    print 'Inserting metadata from: %s'%nc    
    netcdfio.netcdfObs2DB(nc,dbfile)

###
# Step 3: Create a SUNTANS format meteorological input file
###
[coords, output, nctime] = interpWeatherStations(latlon,timestart,timeend,dt*24.0,utmzone,dbfile,maxgap=100,showplot=False)
# Write to the suntans meteorological netcdf format
write2NC(metncfile,coords,output,nctime)