mirror of
https://github.com/Unidata/python-awips.git
synced 2025-02-23 22:57:56 -05:00
DAF examples added
This commit is contained in:
parent
323c752b33
commit
14a1ace2da
10 changed files with 675 additions and 0 deletions
82
examples/GISOperations.md
Normal file
82
examples/GISOperations.md
Normal file
|
@ -0,0 +1,82 @@
|
|||
{{{
|
||||
#!python
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
from shapely.geometry import Polygon,Point
|
||||
from datetime import datetime
|
||||
|
||||
#Initiate a new DataRequest
|
||||
#Get all of the states from the database
|
||||
print "Requesting all states from DAF"
|
||||
t1=datetime.utcnow()
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
request.setDatatype("maps")
|
||||
request.addIdentifier("geomField","the_geom")
|
||||
request.addIdentifier("table","mapdata.states")
|
||||
request.setParameters("state","fips","name")
|
||||
states = DataAccessLayer.getGeometryData(request, None)
|
||||
t2=datetime.utcnow()
|
||||
tdelta = t2-t1
|
||||
print 'DAF query to get all states took %i.%i seconds' %(tdelta.seconds,tdelta.microseconds)
|
||||
|
||||
#Create a polygon object...for example this is a polygon around Oklahoma City
|
||||
polygon = Polygon([(-97.82,35.63),(-97.21,35.63),(-97.21,35.15),(-97.82,35.15),(-97.82,35.63)])
|
||||
#Now lets filter the states down to the one that contains the above polygon
|
||||
#We will use the python built in filter method to accomplish this
|
||||
#the expression below goes through each state object, gets it's geometry, and calls
|
||||
#it's contains method. It in essence creates a new list, state_contain_polygon, with
|
||||
#only the states where the contains method evaluates to true.
|
||||
t1=datetime.utcnow()
|
||||
state_contain_polygon = filter(lambda state: state.getGeometry().contains(polygon),states)
|
||||
t2= datetime.utcnow()
|
||||
tdelta = t2-t1
|
||||
print '\nFilter state objects to one that contains polygon took %i.%i seconds' %(tdelta.seconds,tdelta.microseconds)
|
||||
print state_contain_polygon
|
||||
print "Polygon is in the state of",state_contain_polygon[0].getString('name')
|
||||
|
||||
#Lets also create a point object...this one is located in the state of Iowa
|
||||
point = Point(-93.62,41.60)
|
||||
#Now lets see what state our point is in
|
||||
t1=datetime.utcnow()
|
||||
state_contain_point = filter(lambda state: state.getGeometry().contains(point),states)
|
||||
t2= datetime.utcnow()
|
||||
tdelta = t2-t1
|
||||
print '\nFilter state objects to one that contains point took %i.%i seconds ' %(tdelta.seconds,tdelta.microseconds)
|
||||
print state_contain_point
|
||||
print "Point is in the state of",state_contain_point[0].getString('name')
|
||||
|
||||
#One last example...this time for an intersection. Lets find all of the states this polygon intersects
|
||||
#This polygon is the same as above just extended it further south to 33.15 degrees
|
||||
polygon2 = Polygon([(-97.82,35.63),(-97.21,35.63),(-97.21,33.15),(-97.82,33.15),(-97.82,35.63)])
|
||||
t1=datetime.utcnow()
|
||||
state_intersect_polygon = filter(lambda state: state.getGeometry().intersects(polygon2),states)
|
||||
t2= datetime.utcnow()
|
||||
tdelta = t2-t1
|
||||
print '\nFilter state objects to the ones that intersect polygon took %i.%i seconds ' %(tdelta.seconds,tdelta.microseconds)
|
||||
print state_intersect_polygon
|
||||
for state in state_intersect_polygon:
|
||||
print "Polygon intersects the state of",state.getString('name')
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Requesting all states from DAF
|
||||
DAF query to get all states took 21.915029 seconds
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Filter state objects to one that contains polygon took 0.382097 seconds
|
||||
[<ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x2bebdd0>]
|
||||
Polygon is in the state of Oklahoma
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Filter state objects to one that contains point took 0.2028 seconds
|
||||
[<ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x2beb9d0>]
|
||||
Point is in the state of Iowa
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Filter state objects to the ones that intersect polygon took 0.4032 seconds
|
||||
[<ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x2beb610>, <ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x2bebdd0>]
|
||||
Polygon intersects the state of Texas
|
||||
Polygon intersects the state of Oklahoma
|
||||
}}}
|
109
examples/GetGFEData.md
Normal file
109
examples/GetGFEData.md
Normal file
|
@ -0,0 +1,109 @@
|
|||
|
||||
{{{
|
||||
#!python
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
import numpy as np
|
||||
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
request.setDatatype("gfe")
|
||||
|
||||
# For GFE our locationNames are tied to the activated sites in GFE
|
||||
locationNames = DataAccessLayer.getAvailableLocationNames(request)
|
||||
print locationNames
|
||||
|
||||
request.setLocationNames('OUN')
|
||||
# For GFE data we use the addIdentifier method to add a constraint.
|
||||
# Our constraint is for the modelName attribute and this determines
|
||||
# which GFE database to query the data from. In this request we will
|
||||
# query the Official database.
|
||||
request.addIdentifier('modelName','Official')
|
||||
request.setParameters('PoP')
|
||||
|
||||
t = DataAccessLayer.getAvailableTimes(request)
|
||||
for each in t:
|
||||
print each.getRefTime(),each.getValidPeriod()
|
||||
|
||||
response = DataAccessLayer.getGridData(request, [t[0]])
|
||||
print response
|
||||
data = response[0]
|
||||
|
||||
print 'Units are in', data.getUnit()
|
||||
|
||||
lon,lat = data.getLatLonCoords()
|
||||
print lon
|
||||
|
||||
print 'Parameter we requested is',data.getParameter()
|
||||
|
||||
print data.getRawData()
|
||||
|
||||
}}}
|
||||
|
||||
{{{
|
||||
['OUN']
|
||||
}}}
|
||||
|
||||
{{{
|
||||
May 03 15 18:00:00 GMT (May 03 15 18:00:00 , May 03 15 21:00:00 )
|
||||
May 03 15 21:00:00 GMT (May 03 15 21:00:00 , May 04 15 00:00:00 )
|
||||
May 04 15 00:00:00 GMT (May 04 15 00:00:00 , May 04 15 08:00:00 )
|
||||
May 04 15 08:00:00 GMT (May 04 15 08:00:00 , May 04 15 12:00:00 )
|
||||
May 04 15 12:00:00 GMT (May 04 15 12:00:00 , May 04 15 18:00:00 )
|
||||
May 04 15 18:00:00 GMT (May 04 15 18:00:00 , May 05 15 00:00:00 )
|
||||
May 05 15 00:00:00 GMT (May 05 15 00:00:00 , May 05 15 06:00:00 )
|
||||
May 05 15 06:00:00 GMT (May 05 15 06:00:00 , May 05 15 12:00:00 )
|
||||
May 05 15 12:00:00 GMT (May 05 15 12:00:00 , May 05 15 18:00:00 )
|
||||
May 05 15 18:00:00 GMT (May 05 15 18:00:00 , May 06 15 00:00:00 )
|
||||
May 06 15 00:00:00 GMT (May 06 15 00:00:00 , May 06 15 12:00:00 )
|
||||
May 06 15 12:00:00 GMT (May 06 15 12:00:00 , May 06 15 18:00:00 )
|
||||
May 06 15 18:00:00 GMT (May 06 15 18:00:00 , May 07 15 00:00:00 )
|
||||
May 07 15 00:00:00 GMT (May 07 15 00:00:00 , May 07 15 12:00:00 )
|
||||
May 07 15 12:00:00 GMT (May 07 15 12:00:00 , May 08 15 00:00:00 )
|
||||
May 08 15 00:00:00 GMT (May 08 15 00:00:00 , May 08 15 12:00:00 )
|
||||
May 08 15 12:00:00 GMT (May 08 15 12:00:00 , May 09 15 00:00:00 )
|
||||
May 09 15 00:00:00 GMT (May 09 15 00:00:00 , May 09 15 12:00:00 )
|
||||
May 09 15 12:00:00 GMT (May 09 15 12:00:00 , May 10 15 00:00:00 )
|
||||
May 10 15 00:00:00 GMT (May 10 15 00:00:00 , May 10 15 12:00:00 )
|
||||
May 10 15 12:00:00 GMT (May 10 15 12:00:00 , May 11 15 00:00:00 )
|
||||
May 11 15 00:00:00 GMT (May 11 15 00:00:00 , May 11 15 12:00:00 )
|
||||
May 11 15 12:00:00 GMT (May 11 15 12:00:00 , May 12 15 00:00:00 )
|
||||
May 12 15 00:00:00 GMT (May 12 15 00:00:00 , May 12 15 12:00:00 )
|
||||
May 12 15 12:00:00 GMT (May 12 15 12:00:00 , May 12 15 13:00:00 )
|
||||
}}}
|
||||
|
||||
{{{
|
||||
[<ufpy.dataaccess.PyGridData.PyGridData object at 0x26f9690>]
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Units are in %
|
||||
}}}
|
||||
|
||||
{{{
|
||||
[[-101.30716705 -101.27905273 -101.25093842 ..., -95.05664062
|
||||
-95.02846527 -95.00028992]
|
||||
[-101.3058548 -101.27774811 -101.24964142 ..., -95.056633 -95.02845764
|
||||
-95.00028992]
|
||||
[-101.30455017 -101.27644348 -101.24834442 ..., -95.05661774
|
||||
-95.02845764 -95.00028992]
|
||||
...,
|
||||
[-101.02937317 -101.00249481 -100.97560883 ..., -95.05414581
|
||||
-95.02721405 -95.00027466]
|
||||
[-101.02817535 -101.001297 -100.97442627 ..., -95.05413055
|
||||
-95.02720642 -95.00027466]
|
||||
[-101.02697754 -101.00010681 -100.97324371 ..., -95.05412292
|
||||
-95.02719879 -95.00027466]]
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Parameter we requested is PoP
|
||||
}}}
|
||||
|
||||
{{{
|
||||
[[ 8. 8. 7. ..., 7. 7. 7.]
|
||||
[ 8. 7. 7. ..., 7. 7. 7.]
|
||||
[ 7. 7. 7. ..., 7. 7. 7.]
|
||||
...,
|
||||
[ 3. 3. 3. ..., 2. 2. 2.]
|
||||
[ 3. 3. 3. ..., 2. 2. 2.]
|
||||
[ 3. 3. 3. ..., 2. 2. 2.]]
|
||||
}}}
|
51
examples/GetGridNames.md
Normal file
51
examples/GetGridNames.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
== Using the DAF to get all of the available grids ==
|
||||
|
||||
{{{
|
||||
#!python
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
|
||||
#Initiate a new DataRequest
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
|
||||
#Set the datatype to grid so it knows what plugin to route the request too
|
||||
request.setDatatype("grid")
|
||||
|
||||
#getAvailableLocationNames method will return a list of all available models
|
||||
#LocationNames mean different things to different plugins beware...radar is icao,
|
||||
#satellite is sector, etc
|
||||
available_grids = DataAccessLayer.getAvailableLocationNames(request)
|
||||
for grid in available_grids:
|
||||
print grid
|
||||
}}}
|
||||
|
||||
And the output of the print grid statement would look something like this:
|
||||
|
||||
{{{
|
||||
#!div style="font-size: 90%;font-style:italic"
|
||||
{{{
|
||||
RUC236
|
||||
SREF216
|
||||
ENSEMBLE
|
||||
RTOFS-WestAtl
|
||||
AKwave10
|
||||
HiResW-NMM-AK
|
||||
QPE-KRF
|
||||
AK-NamDNG5
|
||||
GFS160
|
||||
FFG-TIR
|
||||
GFS254
|
||||
SPCGuide
|
||||
RFCqpf
|
||||
RTMA-Mosaic
|
||||
QPE-RFC-RSA
|
||||
UKMET40
|
||||
MPE-Local-MSR
|
||||
gefs
|
||||
WNAwave4
|
||||
GFS201
|
||||
QPE-XNAV-ALR
|
||||
AK-RTMA3
|
||||
GFS212
|
||||
...
|
||||
}}}
|
||||
}}}
|
63
examples/GetGridTimes.md
Normal file
63
examples/GetGridTimes.md
Normal file
File diff suppressed because one or more lines are too long
43
examples/GetObs.md
Normal file
43
examples/GetObs.md
Normal file
File diff suppressed because one or more lines are too long
50
examples/GetSatelliteIR.md
Normal file
50
examples/GetSatelliteIR.md
Normal file
|
@ -0,0 +1,50 @@
|
|||
|
||||
n
|
||||
#!/awips2/python/bin/python
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
import numpy as np
|
||||
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
request.setDatatype("satellite")
|
||||
request.setLocationNames("East CONUS")
|
||||
request.setParameters("Imager 6.7-6.5 micron IR (WV)")
|
||||
|
||||
t = DataAccessLayer.getAvailableTimes(request)
|
||||
print t[-1].getRefTime()
|
||||
|
||||
response = DataAccessLayer.getGridData(request, times=[t[-1]])
|
||||
print response
|
||||
data = response[0]
|
||||
|
||||
print 'Units are in', data.getUnit()
|
||||
lon,lat = data.getLatLonCoords()
|
||||
|
||||
print 'Parameter we requested is',data.getParameter()
|
||||
print data.getRawData()
|
||||
}}}
|
||||
|
||||
{{{
|
||||
May 04 15 18:45:19 GMT
|
||||
}}}
|
||||
|
||||
{{{
|
||||
[<ufpy.dataaccess.PyGridData.PyGridData object at 0x157d550>]
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Units are in None
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Parameter we requested is Imager 6.7-6.5 micron IR (WV)
|
||||
}}}
|
||||
|
||||
{{{
|
||||
[[ 186. 185. 186. ..., 180. 181. 181.]
|
||||
[ 186. 185. 186. ..., 180. 181. 181.]
|
||||
[ 186. 186. 185. ..., 180. 181. 181.]
|
||||
...,
|
||||
[ 0. 0. 0. ..., 145. 145. 145.]
|
||||
[ 0. 0. 0. ..., 145. 145. 145.]
|
||||
[ 0. 0. 0. ..., 145. 145. 144.]]
|
||||
}}}
|
69
examples/GetStates.md
Normal file
69
examples/GetStates.md
Normal file
|
@ -0,0 +1,69 @@
|
|||
{{{
|
||||
#!python
|
||||
#!/awips2/python/bin/python
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
|
||||
#Initiate a new DataRequest
|
||||
b = DataAccessLayer.newDataRequest()
|
||||
#Set the datatype to maps so it knows what plugin to route the request too
|
||||
b.setDatatype("maps")
|
||||
#setParameters indicates the columns from table that we want returned along with our geometry
|
||||
b.setParameters("state","fips")
|
||||
#Add a couple of identifiers to indicate the geomField and table we are querying
|
||||
b.addIdentifier("geomField","the_geom")
|
||||
b.addIdentifier("table","mapdata.states")
|
||||
|
||||
#getAvailableLocationNames method will return a list of all available locations
|
||||
#based off the table we have specified previously. LocationNames mean different
|
||||
#things to different plugins beware...radar is icao, satellite is sector, etc
|
||||
a = DataAccessLayer.getAvailableLocationNames(b)
|
||||
print a
|
||||
|
||||
#Use setLocationNames to set the states we want data from
|
||||
b.setLocationNames("Oklahoma","Texas","Kansas")
|
||||
|
||||
#Finally lets request some data. There are two types of data (Grid, Geometry) here we are
|
||||
#requesting geometry data and therefore use the getGeometryData method. We pass it our DataRequest object
|
||||
#that has all of our parameters and None for the DataTime object argument since maps are time agnostic
|
||||
#This returns a list of ufpy.dataaccess.PyGeometryData.PyGeometryData objects.
|
||||
c = DataAccessLayer.getGeometryData(b, None)
|
||||
print c
|
||||
|
||||
#Now lets loop through our list of PyGeometryData objects of states and look at some data
|
||||
for shape in c:
|
||||
#Lets print the locationname for this object
|
||||
print 'Location name is',shape.getLocationName()
|
||||
#getGeometry returns a shapely geometry object for this state. Using shapely allows
|
||||
#us to perform postgis type operations outside the database (contains,within,etc). If
|
||||
#not familiar with shapely recommend you look at the documentation available online.
|
||||
#This is a 3rd party python module so just Google search python shapely to find the docs
|
||||
mpoly = shape.getGeometry()
|
||||
#These next few items allow us to access the column data we requested when we set the
|
||||
#parameters
|
||||
print 'Parameters requested are',shape.getParameters()
|
||||
print 'state column is',shape.getString('state')
|
||||
print 'fips column is',shape.getString('fips')
|
||||
}}}
|
||||
|
||||
{{{
|
||||
['Alabama', 'Alaska', 'American Samoa', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Guam', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Puerto Rico', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virgin Islands', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']
|
||||
}}}
|
||||
|
||||
{{{
|
||||
[<ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x1ec4410>, <ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x1ec4510>, <ufpy.dataaccess.PyGeometryData.PyGeometryData object at 0x1ec4550>]
|
||||
}}}
|
||||
|
||||
{{{
|
||||
Location name is Texas
|
||||
Parameters requested are ['state', 'fips']
|
||||
state column is TX
|
||||
fips column is 48
|
||||
Location name is Kansas
|
||||
Parameters requested are ['state', 'fips']
|
||||
state column is KS
|
||||
fips column is 20
|
||||
Location name is Oklahoma
|
||||
Parameters requested are ['state', 'fips']
|
||||
state column is OK
|
||||
fips column is 40
|
||||
}}}
|
33
examples/ModelRunDict.md
Normal file
33
examples/ModelRunDict.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
== Using the DAF from Python to determine available model runs and available forecast steps for each model run ==
|
||||
|
||||
Apr 2, 2015 - Virgil Middendorf
|
||||
|
||||
The code below creates a Python Dictionary called ModelRunDict, where the keys are the available Model Run date/times (example key: Apr 02 15 06:00:00). Associated with each key, is a list array of Forecast Steps (in seconds after initialization) available for each Model Run.
|
||||
|
||||
{{{
|
||||
#!python
|
||||
# Getting the Model Run Date/Times and put them into a sorted dictionary, with latest run first.
|
||||
ModelRunDict = dict()
|
||||
ModelRunList = []
|
||||
ModelRunTimes = DataAccessLayer.getAvailableTimes(req, refTimeOnly=True)
|
||||
for ModelRunTime in ModelRunTimes:
|
||||
if not ModelRunDict.has_key(ModelRunTime.getRefTime()):
|
||||
ModelRunDateTimeObject = datetime.strptime(str(ModelRunTime.getRefTime()), '%b %d %y %H:%M:%S %Z')
|
||||
ModelRunList.append(ModelRunDateTimeObject)
|
||||
ModelRunList.sort(reverse=True)
|
||||
for ModelRun in ModelRunList:
|
||||
ModelRunDict[ModelRun.strftime('%b %d %y %H:%M:%S %Z') + "GMT"] = []
|
||||
|
||||
# Get the available forecast steps for each model run.
|
||||
availableTimes = DataAccessLayer.getAvailableTimes(req)
|
||||
for time in availableTimes:
|
||||
ModelRunDict[str(time.getRefTime())].append(time.getFcstTime())
|
||||
|
||||
# Printing out available model runs and forecast steps.
|
||||
for ModelRun in ModelRunDict.keys():
|
||||
print "Model Run = {}".format(ModelRun)
|
||||
for step in ModelRunDict[ModelRun]:
|
||||
print "Forecast Step: {} Hours".format(int(step)/3600)
|
||||
|
||||
}}}
|
||||
|
78
examples/RAPClipTemperature.md
Normal file
78
examples/RAPClipTemperature.md
Normal file
|
@ -0,0 +1,78 @@
|
|||
==== Below shows an example of only requesting data over a specific envelope (ie bounding box). This examples uses a request from the maps database to get the Envelope around the CWA of OUN for our request. This can be used to fine tune your request to only get the data you really need and speed up requests.====
|
||||
|
||||
==== You could do this same type of request using any other geometry. For example, you could query the states table and only pull out model data over a particular state. You can also create your own Shapely geometry from scratch and use it to define your envelope. ====
|
||||
|
||||
{{{
|
||||
#!python
|
||||
#!/awips2/python/bin/python
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
import numpy as np
|
||||
|
||||
# First we will request the OUN CWA from the maps database.
|
||||
# We will use this to create the envelope for our grid request.
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
request.setDatatype("maps")
|
||||
request.setParameters("cwa","wfo")
|
||||
request.addIdentifier("locationField","wfo")
|
||||
request.addIdentifier("geomField","the_geom")
|
||||
request.addIdentifier("table","mapdata.cwa")
|
||||
request.setLocationNames("OUN")
|
||||
response = DataAccessLayer.getGeometryData(request, None)
|
||||
oungeom = response[0].getGeometry()
|
||||
|
||||
# First let's get the nonclipped 850MB Temp so we can compare
|
||||
# the lat/lons and shape of the arrays
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
request.setDatatype("grid")
|
||||
request.setLocationNames('RUC130')
|
||||
request.setParameters("T")
|
||||
request.setLevels("850MB")
|
||||
t = DataAccessLayer.getAvailableTimes(request)
|
||||
response = DataAccessLayer.getGridData(request, times=[t[-1]])
|
||||
data = response[0]
|
||||
coords = data.getLatLonCoords()
|
||||
print coords[0].shape,coords[1].shape
|
||||
|
||||
# Since the only thing we are changing is adding an Envelope
|
||||
# we can reuse our previous request without having to make a
|
||||
# new one.
|
||||
# Now we will request only the grid points that are within the envelope (bbox)
|
||||
# of the OUN cwa by using the setEnvelope method
|
||||
print 'OUN Envelope is',oungeom.envelope
|
||||
request.setEnvelope(oungeom)
|
||||
response = DataAccessLayer.getGridData(request, times=[t[-1]])
|
||||
data = response[0]
|
||||
coords = data.getLatLonCoords()
|
||||
print coords[0].shape,coords[1].shape
|
||||
|
||||
# Let's say we want to get an area a little bit larger than our CWA. For this we can use
|
||||
# Shapely's buffer method to enlarge our envelope. In this example we will buffer the OUN
|
||||
# geometry by half a degree.
|
||||
ounbufferedgeom = oungeom.buffer(0.5)
|
||||
print 'OUN Envelope with buffer is',ounbufferedgeom.envelope
|
||||
request.setEnvelope(ounbufferedgeom)
|
||||
response = DataAccessLayer.getGridData(request, times=[t[-1]])
|
||||
data = response[0]
|
||||
coords = data.getLatLonCoords()
|
||||
print coords[0].shape,coords[1].shape
|
||||
}}}
|
||||
|
||||
{{{
|
||||
(175, 175) (175, 175)
|
||||
}}}
|
||||
|
||||
{{{
|
||||
OUN Envelope is POLYGON ((-100.0485000609999702 33.3954124450000336, -95.6716995239999619 33.3954124450000336, -95.6716995239999619 37.0016136170000323, -100.0485000609999702 37.0016136170000323, -100.0485000609999702 33.3954124450000336))
|
||||
}}}
|
||||
|
||||
{{{
|
||||
(32, 33) (32, 33)
|
||||
}}}
|
||||
|
||||
{{{
|
||||
OUN Envelope with buffer is POLYGON ((-100.5485000609999702 32.8954672430463262, -95.1716995239999619 32.8954672430463262, -95.1716995239999619 37.5016136170000323, -100.5485000609999702 37.5016136170000323, -100.5485000609999702 32.8954672430463262))
|
||||
}}}
|
||||
|
||||
{{{
|
||||
(39, 41) (39, 41)
|
||||
}}}
|
97
examples/RAPTemperature.md
Normal file
97
examples/RAPTemperature.md
Normal file
|
@ -0,0 +1,97 @@
|
|||
|
||||
{{{
|
||||
#!python
|
||||
import numpy as np
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
|
||||
#Initiate a new DataRequest
|
||||
request = DataAccessLayer.newDataRequest()
|
||||
#Set the datatype to grid so it knows what plugin to route the request too
|
||||
request.setDatatype("grid")
|
||||
|
||||
#Use setLocationNames to set the model we want data from
|
||||
request.setLocationNames('RUC130')
|
||||
#Next we set the variable and level of data we want
|
||||
request.setParameters("T")
|
||||
request.setLevels("850MB")
|
||||
|
||||
#getAvailableTimes allows us to query what times are available based off of the
|
||||
#model, parameter, and levels we have previously identified. These are of the type
|
||||
#dynamicserialize.dstypes.com.raytheon.uf.common.time.DataTime.DataTime.
|
||||
t = DataAccessLayer.getAvailableTimes(request)
|
||||
|
||||
#Finally lets request some data. There are two types of data (Grid, Geometry) here we are
|
||||
#requesting gridded data and therefore use the getGridData method. We pass it our DataRequest object
|
||||
#that has all of our model, parameter, and level information and also a list of DataTime objects we want
|
||||
#the data for. In this case just give us the data from the last DataTime in the above list (t[-1]). This returns
|
||||
#a list of ufpy.dataaccess.PyGridData.PyGridData objects.
|
||||
response = DataAccessLayer.getGridData(request, [t[-1]])
|
||||
print response
|
||||
|
||||
#Since we only asked for one DataTime we only have one PyGridData object. Lets pull this out
|
||||
#into a variable named data. Then we can use functions available from ufpy.dataaccess.PyGridData.PyGridData
|
||||
#objects (see module for more methods or details)
|
||||
data = response[0]
|
||||
|
||||
#Show the units of the data
|
||||
print 'Units are in', data.getUnit()
|
||||
|
||||
#Get LatLon coords of the gridded data, Returns a tuple <lon,lat> arrays
|
||||
lon,lat = data.getLatLonCoords()
|
||||
print lon
|
||||
|
||||
#In case we forget what we requested we can get the parameter
|
||||
print 'Parameter we requested is', data.getParameter()
|
||||
#And finally lets get the data itself. This returns an array of the raw data
|
||||
print data.getRawData()
|
||||
}}}
|
||||
|
||||
Our response object is a list of !PyGridData objects
|
||||
{{{
|
||||
[<ufpy.dataaccess.PyGridData.PyGridData object at 0x1d39910>]
|
||||
}}}
|
||||
|
||||
Output of our print statement getting the units
|
||||
{{{
|
||||
Units are in K
|
||||
}}}
|
||||
|
||||
print lon
|
||||
{{{
|
||||
[[-118.09392548 -117.93661499 -117.77923584 ..., -90.46847534
|
||||
-90.30672455 -90.14498901]
|
||||
[-118.06690216 -117.90976715 -117.75257111 ..., -90.47387695
|
||||
-90.31232452 -90.15077972]
|
||||
[-118.03994751 -117.88298798 -117.72595978 ..., -90.47927094
|
||||
-90.31790161 -90.15655518]
|
||||
...,
|
||||
[-114.21573639 -114.08406067 -113.9523468 ..., -91.24035645
|
||||
-91.10612488 -90.97190094]
|
||||
[-114.19696808 -114.06542206 -113.93383026 ..., -91.24407959
|
||||
-91.10997772 -90.97589111]
|
||||
[-114.17823792 -114.04681396 -113.91535187 ..., -91.24778748
|
||||
-91.11382294 -90.97986603]]
|
||||
}}}
|
||||
|
||||
Our print statement from getParameter()
|
||||
{{{
|
||||
Parameter we requested is T
|
||||
}}}
|
||||
|
||||
And finally our call to getRawData() gets a numpy array of the temperature values
|
||||
{{{
|
||||
[[ 283.88305664 284.50805664 285.25805664 ..., 280.88305664
|
||||
280.75805664 280.63305664]
|
||||
[ 284.38305664 285.00805664 285.75805664 ..., 281.00805664
|
||||
280.88305664 280.75805664]
|
||||
[ 284.50805664 285.13305664 285.75805664 ..., 281.13305664
|
||||
281.00805664 280.88305664]
|
||||
...,
|
||||
[ 285.38305664 285.63305664 285.88305664 ..., 286.88305664
|
||||
286.88305664 287.00805664]
|
||||
[ 285.25805664 285.50805664 285.75805664 ..., 287.00805664
|
||||
287.00805664 287.13305664]
|
||||
[ 285.13305664 285.50805664 285.75805664 ..., 287.25805664
|
||||
287.25805664 287.25805664]]
|
||||
}}}
|
||||
|
Loading…
Add table
Reference in a new issue