Exemplo n.º 1
0
# Make sure the WaveConnect py/lib folder is on the search path so
# modules can be retrieved.
import sys
from os import path
scriptLocation = path.dirname(path.abspath(__file__))
waveLibs = path.abspath(path.join(scriptLocation, '..', 'lib'))
sys.path.insert(0, waveLibs)

from wavecon import DBman
from wavecon.NDBC.DB import getBuoyID

from datetime import datetime
from geoalchemy import WKTSpatialElement

Wind = DBman.accessTable(None, template='tblwind')
session = DBman.startSession()

buoyID = getBuoyID(46022)

time = datetime.strptime("4/20/2010 4:20:00", "%m/%d/%Y %H:%M:%S")

windTest = Wind(buoyID, WKTSpatialElement('POINT(40.86 -124.08)'), time, 12.0,
                120.0)
print windTest

session.add(windTest)
session.commit()

for record in session.query(Wind).all():
    print record
Exemplo n.º 2
0
#  Imports from third party libraries
#------------------------------------------------------------------------------
from sqlalchemy import and_
from sqlalchemy.sql.expression import cast
from sqlalchemy.dialects.postgresql import ARRAY, DOUBLE_PRECISION
from geoalchemy import WKTSpatialElement

#------------------------------------------------------------------------------
#  Imports from WaveConnect libraries
#------------------------------------------------------------------------------
from wavecon import DBman

#------------------------------------------------------------------------------
#  Metadata, Object Classes and Other Constants
#------------------------------------------------------------------------------
BuoySource = DBman.accessTable(None, 'tblsource')
SourceTypeRecord = DBman.accessTable(None, 'tblsourcetype')
WindRecord = DBman.accessTable(None, 'tblwind')
WaveRecord = DBman.accessTable(None, 'tblwave')
SpectraRecord = DBman.accessTable(None, 'tblspectrabin')

_session = DBman.startSession()

# Import NDBC global variables
from .globals import BUOY_META


#------------------------------------------------------------------------------
#  Forming and Committing Database Records
#------------------------------------------------------------------------------
def formDatabaseRecords(NDBCrecords):
Exemplo n.º 3
0
Arquivo: DB.py Projeto: serc/wave
#------------------------------------------------------------------------------
from sqlalchemy import and_
from sqlalchemy.sql.expression import cast
from sqlalchemy.dialects.postgresql import ARRAY, DOUBLE_PRECISION
from geoalchemy import WKTSpatialElement

#------------------------------------------------------------------------------
#  Imports from WaveConnect libraries
#------------------------------------------------------------------------------
from wavecon import DBman


#------------------------------------------------------------------------------
#  Metadata, Object Classes and Other Constants
#------------------------------------------------------------------------------
BuoySource = DBman.accessTable(None, 'tblsource')
SourceTypeRecord = DBman.accessTable(None, 'tblsourcetype')
WindRecord = DBman.accessTable(None, 'tblwind')
WaveRecord = DBman.accessTable(None, 'tblwave')
SpectraRecord = DBman.accessTable(None, 'tblspectrabin')

_session = DBman.startSession()

# Import NDBC global variables
from .globals import BUOY_META


#------------------------------------------------------------------------------
#  Forming and Committing Database Records
#------------------------------------------------------------------------------
def formDatabaseRecords( NDBCrecords ):
Exemplo n.º 4
0
#------------------------------------------------------------------------------
from sqlalchemy import and_
from sqlalchemy.sql.expression import cast
from sqlalchemy.dialects.postgresql import ARRAY, DOUBLE_PRECISION
from geoalchemy import WKTSpatialElement

#------------------------------------------------------------------------------
#  Imports from WaveConnect libraries
#------------------------------------------------------------------------------
from wavecon import DBman


#------------------------------------------------------------------------------
#  Metadata, Object Classes and Other Constants
#------------------------------------------------------------------------------
SourceTypeRecord = DBman.accessTable(None, 'tblsourcetype')
Source = DBman.accessTable(None, 'tblsource')
CurrentRecord = DBman.accessTable(None, 'tblcurrent')
WaveRecord = DBman.accessTable(None, 'tblwave')
SpectraRecord = DBman.accessTable(None, 'tblspectrabin' )

_session = DBman.startSession()


#------------------------------------------------------------------------------
#  Forming and Committing Database Records
#------------------------------------------------------------------------------
def CurrentDBrecordGenerator(current_data, model_run_id):
  records = (
    {
      'curid': uuid4(),
Exemplo n.º 5
0
from wavecon import DBman
from wavecon.config import DBconfig as _DBconfig

from pydap.client import open_url

#---------------------------------------------------------------------
#  Metadata and Other Constants
#---------------------------------------------------------------------

HF_CURRENT_META = {
    '6km': {
        'url': 'http://sdf.ndbc.noaa.gov/thredds/dodsC/hfradar_uswc_6km'
    }
}

Source = DBman.accessTable(_DBconfig, 'tblsource')
SourceType = DBman.accessTable(_DBconfig, 'tblsourcetype')
CurrentRecord = DBman.accessTable(_DBconfig, 'tblcurrent')

_session = DBman.startSession(_DBconfig)


#---------------------------------------------------------------------
#  Data Retrieval
#---------------------------------------------------------------------
def fetchRecords(north,
                 south,
                 west,
                 east,
                 startTime,
                 stopTime,
Exemplo n.º 6
0
from numpy import *  #math support
from geoalchemy import WKTSpatialElement
from os import path, system, remove
strptime = datetime.datetime.strptime

################################
# IMPORT DATABASE FUNCTIONS
################################
DBman_path = path.abspath('.') + '/../lib/'
sys.path.insert(0, DBman_path)
from wavecon import DBman

################################
# CREATE DATABASE OBJECTS
################################
srctype = DBman.accessTable(None, 'tblsourcetype')
src = DBman.accessTable(None, 'tblsource')
spec = DBman.accessTable(None, 'tblspectrabin')
wave = DBman.accessTable(None, 'tblwave')

################################
# PARSE COMMAND LINE ARGUMENTS
################################
north = sys.argv[1]  #50
south = sys.argv[2]  #35
east = sys.argv[3]  #-120
west = sys.argv[4]  #-130
starttime = sys.argv[5]  #YYYY/MM/DD
stoptime = sys.argv[6]  #YYYY/MM/DD
tmpdir = sys.argv[7]  #/Users/naftali/Desktop/tmp
locale = 'EKA'
Exemplo n.º 7
0
delta = datetime.timedelta(.25)  # 6 hour increment
if (stoptime == starttime):
    stoptime = starttime + datetime.timedelta(1)

################################
# FILENAME PARAMETERS
################################
tmpfile = tmpdir + '/tmp.grb'
baseurl = 'http://nomads.ncdc.noaa.gov/data/namanl/'
filename1 = 'namanl_218_'
filename2 = '_000.grb'

################################
# CREATE DATABASE OBJECTS
################################
srctype = DBman.accessTable(None, 'tblsourcetype')
src = DBman.accessTable(None, 'tblsource')
wind = DBman.accessTable(None, 'tblwind')

################################
# ADD NAM12 TO tblSourceType
################################
session = DBman.startSession()
srctypename = 'NAM12'
existing = session.query(srctype)\
    .filter( srctype.sourcetypename == srctypename )
if (existing.first() == None):
    record = srctype(srctypename)
    session.add(record)
    session.commit()
srctypeid = session.query(srctype)\
Exemplo n.º 8
0
#!/usr/bin/env python

# Make sure the WaveConnect py/lib folder is on the search path so
# modules can be retrieved.
import sys
from os import path, system
scriptLocation = path.dirname(path.abspath(__file__))
waveLibs = path.abspath(path.join(scriptLocation, '..', 'lib'))
sys.path.insert(0, waveLibs)

from wavecon.config import DBconfig
from wavecon import DBman
from wavecon.NDBC.DB import getBuoyID

from datetime import datetime
from geoalchemy import WKTSpatialElement

Wind = DBman.accessTable(DBconfig, 'tblwind', 'tblwind')
session = DBman.startSession(DBconfig)

records = session.query(Wind).all()

if len(records) == 0:
    dbTest = path.abspath(path.join(scriptLocation, 'dbtest.py'))
    system('pythonw {0}'.format(dbTest))
    records = session.query(Wind).all()

record = records[0]

print record
Exemplo n.º 9
0
# Make sure the WaveConnect py/lib folder is on the search path so
# modules can be retrieved.
import sys
from os import path, system
scriptLocation = path.dirname(path.abspath(__file__))
waveLibs = path.abspath(path.join(scriptLocation, '..', 'lib'))
sys.path.insert(0, waveLibs)


from wavecon.config import DBconfig
from wavecon import DBman
from wavecon.NDBC.DB import getBuoyID

from datetime import datetime
from geoalchemy import WKTSpatialElement

Wind = DBman.accessTable(DBconfig, 'tblwind', 'tblwind')
session = DBman.startSession(DBconfig)

records = session.query(Wind).all()

if len(records) == 0:
  dbTest = path.abspath(path.join(scriptLocation, 'dbtest.py'))
  system('pythonw {0}'.format(dbTest))
  records = session.query(Wind).all()

record = records[0]

print record
Exemplo n.º 10
0
Arquivo: HFRadar.py Projeto: serc/wave
sys.path.insert( 0, waveLibs )
"""

from wavecon import DBman
from wavecon.config import DBconfig as _DBconfig

from pydap.client import open_url


# ---------------------------------------------------------------------
#  Metadata and Other Constants
# ---------------------------------------------------------------------

HF_CURRENT_META = {"6km": {"url": "http://sdf.ndbc.noaa.gov/thredds/dodsC/hfradar_uswc_6km"}}

Source = DBman.accessTable(_DBconfig, "tblsource")
SourceType = DBman.accessTable(_DBconfig, "tblsourcetype")
CurrentRecord = DBman.accessTable(_DBconfig, "tblcurrent")

_session = DBman.startSession(_DBconfig)


# ---------------------------------------------------------------------
#  Data Retrieval
# ---------------------------------------------------------------------
def fetchRecords(north, south, west, east, startTime, stopTime, resolution, verbose=False):

    records = getData(north, south, west, east, startTime, stopTime, resolution)
    return records

Exemplo n.º 11
0
delta = datetime.timedelta(.25) # 6 hour increment
if (stoptime==starttime):
  stoptime=starttime+datetime.timedelta(1)

################################
# FILENAME PARAMETERS
################################
tmpfile = tmpdir + '/tmp.grb'
baseurl = 'http://nomads.ncdc.noaa.gov/data/namanl/'
filename1 = 'namanl_218_'
filename2 = '_000.grb'

################################
# CREATE DATABASE OBJECTS
################################
srctype = DBman.accessTable( None, 'tblsourcetype' )
src = DBman.accessTable( None, 'tblsource')
wind = DBman.accessTable( None, 'tblwind' ) 

################################
# ADD NAM12 TO tblSourceType
################################
session = DBman.startSession()     
srctypename = 'NAM12'
existing = session.query(srctype)\
    .filter( srctype.sourcetypename == srctypename )
if ( existing.first() == None ):
    record = srctype(srctypename)                              
    session.add(record)
    session.commit()
srctypeid = session.query(srctype)\
Exemplo n.º 12
0
from numpy import * #math support
from geoalchemy import WKTSpatialElement
from os import path,system,remove
strptime = datetime.datetime.strptime

################################
# IMPORT DATABASE FUNCTIONS
################################
DBman_path = path.abspath('.')+'/../lib/'
sys.path.insert( 0, DBman_path )
from wavecon import DBman

################################
# CREATE DATABASE OBJECTS
################################
srctype = DBman.accessTable( None, 'tblsourcetype' )
src = DBman.accessTable( None, 'tblsource')
spec = DBman.accessTable( None, 'tblspectrabin' )
wave = DBman.accessTable( None, 'tblwave')

################################
# PARSE COMMAND LINE ARGUMENTS
################################
north =     sys.argv[1]       #50
south =     sys.argv[2]       #35
east =      sys.argv[3]       #-120
west =      sys.argv[4]       #-130
starttime = sys.argv[5]       #YYYY/MM/DD
stoptime =  sys.argv[6]       #YYYY/MM/DD
tmpdir =    sys.argv[7]       #/Users/naftali/Desktop/tmp
locale = 'EKA'
Exemplo n.º 13
0
Arquivo: dbtest.py Projeto: serc/wave
# Make sure the WaveConnect py/lib folder is on the search path so
# modules can be retrieved.
import sys
from os import path
scriptLocation = path.dirname(path.abspath( __file__ ))
waveLibs = path.abspath(path.join( scriptLocation, '..', 'lib' ))
sys.path.insert( 0, waveLibs )


from wavecon import DBman
from wavecon.NDBC.DB import getBuoyID

from datetime import datetime
from geoalchemy import WKTSpatialElement

Wind = DBman.accessTable(None, template = 'tblwind')
session = DBman.startSession()

buoyID = getBuoyID( 46022 )

time = datetime.strptime( "4/20/2010 4:20:00","%m/%d/%Y %H:%M:%S" )

windTest = Wind( buoyID, WKTSpatialElement('POINT(40.86 -124.08)'), time, 12.0, 120.0 )
print windTest

session.add(windTest)
session.commit()

for record in session.query(Wind).all():
  print record