示例#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
# 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)