Ex 01: Source QueriesΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# das2py example 01:  Data queries using catalog Source nodes
#
# The lowest level nodes in a das2 catalog are usually Source nodes which
# describe where and how to get data.  Without source nodes the catalog
# wouldn't be very useful.  The most common source node type is HttpStreamSrc,
# which can describe many HTTP GET based data service including das2 servers
# and HAPI servers.  A future Source derived class will provide access to
# static file collections.
#
# There are currently three types of data querys supported by das2py and the
# das2 catalog system, each of which is useful for a different purpose.
#
#  0.  Get example data using Source.example()
#
#      All data sources are required to provide at least one default set of
#      data for testing and evaluation purposes.  Named examples may be
#      requeseted if desired.  Other than the example name (which is optional)
#      no arguments are required.
#
#  1.  Protocol specific queries using Source.protoQuery()
#
#      Using protoQuery() directly means that application code is tied to a
#      specific GET API and will break if the server definition changes (for
#      example due to upgrades).  Even with these low level queries, automatic
#      failover to redundant servers is still supported.
#
#  2.  Source public API queries using Source.query()
#
#      These use the more generic use the public interface API of the source.
#      The Source node contains information to translate public API queries
#      into the specific protocol strings that must be issued to the server.
#      As new server versions are developed the underlying protocol may change,
#      but these query parameters can remain fixed.
#
# The code below provides examples of all three working query types.
#
#   For the curious a fourth query type that will handle contacting multiple
#   heterogenous data sources using permanent IDs such as DOIs is prototyped
#   in the file: future/exNN_collection_queries.py .

import das2

# 0. Getting example data.  All valid das2 catalog Source definitions are
#    required to provide at least one example dateset.

src = das2.get_source('site:/uiowa/cassini/rpws/hires_midfreq_waveform/das2')
for name, summary in src.examples(): print(name, "|", summary)
lDatasets = src.get()  # Gets the first example if no arguments are provide
print(lDatasets[0])


# 1. Protocol specific query (discouraged, but sometimes necessary).  If the
#    data are moved to a different server with a different API, this code will
#    break.

src = das2.get_source('site:/uiowa/cassini/rpws/hires_midfreq_waveform/das2')
print( src.protoInfo() )
print( " ")

dQuery = {
   'start_time':'2008-223T09:06', 'end_time':'2008-223T09:13',
   'params':'--80khz'
}
lDatasets = src.protoGet(dQuery)
print(lDatasets[0])

# 2. Public interface query.  This interface exists to make it easier to
#    associate data navigation operations with the query parameters.  This
#    is the recommended interface for most uses.

src = das2.get_source('site:/uiowa/cassini/rpws/hires_midfreq_waveform/das2')
print(src.info())     # Automated GUI's use src.params() instead

dQuery = { 'time':('2008-223T09:06', '2008-223T09:13'), 'band':'80 kHz' }
lDatasets = src.get(dQuery)
print(lDatasets[0])

# Actually using the datasets returned via these queries is the subject of
# subsequent examples.