Package noaadata :: Module test_pydap
[hide private]
[frames] | no frames]

Source Code for Module noaadata.test_pydap

 1  #!/usr/bin/env python 
 2  ''' 
 3  Try out pydap to fetch the current water level from the NOAA Co-ops 
 4  server.  This is a really slow way to pull one data point! 
 5  ''' 
 6  import dap.client 
 7  dataset=dap.client.open('http://opendap.co-ops.nos.noaa.gov/dods/IOOS/Raw_Water_Level') 
 8  # 
 9  print 'Dataset keys:' 
10  for item in dataset.keys(): print '  ',item 
11  seq = dataset['WATERLEVEL_RAW_PX'] 
12  filt_seq=seq.filter('_STATION_ID="1615680"&_BEGIN_DATE="20060101"&_END_DATE="20060101"&_DATUM="MLLW"')  
13  print 'filter keys:' 
14  for item in filt_seq.keys(): print '  ',item 
15  # 
16  # Print the results.  To just get field, do this... 
17  # 
18  print 'Just the WL_VALUE field:',filt_seq['WL_VALUE'][:][-1] 
19  # 
20  # Fetch all the fields. 
21  #print 'One data point:' 
22  for item in filt_seq.keys(): 
23      print '  ',item,':',filt_seq[item][:][-1]  
24  print  'or...' 
25  data = filt_seq._get_data() 
26  print 'Found this many waterlevel points:',len(data) 
27  print data[-1] 
28