Testing Glider DAC access in Python


In [1]:
import numpy as np
import matplotlib.pyplot as plt
import netCDF4
import numpy.ma as ma
import seawater
%matplotlib inline

This is a url from Kerfooot's TDS server, using the multidimensional NetCDF datasets created by a private ERDDAP instance. These multidimensonal datasets are also available from ERDDAP, along with a flattened NetCDF representation and a ragged NetCDF representation.

The glider ERDDAP is here: http://erddap.marine.rutgers.edu/erddap

The glider TDS is here: http://tds.marine.rutgers.edu:8080/thredds/catalog/cool/glider/all/catalog.html


In [2]:
url = 'http://tds.marine.rutgers.edu:8080/thredds/dodsC/cool/glider/all/ru22-20130924T2010.ncCFMA.nc3.nc'

In [3]:
nc = netCDF4.Dataset(url)
ncv = nc.variables

In [4]:
ncv.keys()


Out[4]:
[u'trajectory',
 u'wmo_id',
 u'profile_id',
 u'time',
 u'latitude',
 u'longitude',
 u'time_uv',
 u'lat_uv',
 u'lon_uv',
 u'u',
 u'v',
 u'precise_time',
 u'depth',
 u'pressure',
 u'temperature',
 u'conductivity',
 u'salinity',
 u'density',
 u'precise_lat',
 u'precise_lon',
 u'platform_meta',
 u'instrument_ctd',
 u'precise_time_qc',
 u'depth_qc',
 u'pressure_qc',
 u'temperature_qc',
 u'conductivity_qc',
 u'salinity_qc',
 u'density_qc',
 u'precise_lat_qc',
 u'precise_lon_qc',
 u'time_qc',
 u'latitude_qc',
 u'longitude_qc',
 u'time_uv_qc',
 u'lat_uv_qc',
 u'lon_uv_qc',
 u'u_qc',
 u'v_qc']

In [5]:
lon = ncv['longitude'][:]
lat = ncv['latitude'][:]

In [6]:
import iris

In [7]:
t = iris.load_cube(url,'sea_water_temperature')


/home/usgs/anaconda/lib/python2.7/site-packages/iris/fileformats/cf.py:269: UserWarning: Missing CF-netCDF ancillary data variable u'lat_qc', referenced by netCDF variable u'precise_lat'
  warnings.warn(message % (name, nc_var_name))
/home/usgs/anaconda/lib/python2.7/site-packages/iris/fileformats/cf.py:269: UserWarning: Missing CF-netCDF ancillary data variable u'lon_qc', referenced by netCDF variable u'precise_lon'
  warnings.warn(message % (name, nc_var_name))

In [8]:
print t


sea_water_temperature / (Celsius)   (-- : 1; -- : 3294; -- : 680)
     Auxiliary coordinates:
          latitude                      x       x          -
          longitude                     x       x          -
          time                          x       x          -
          depth                         x       x          x
     Attributes:
          Conventions: Unidata Dataset Discovery v1.0, COARDS, CF-1.6
          DODS.dimName: wmo_id_strlen
          DODS.strlen: 7
          Easternmost_Easting: -74.2846128922
          Metadata_Conventions: Unidata Dataset Discovery v1.0, COARDS, CF-1.6
          Northernmost_Northing: 37.7880349112
          Southernmost_Northing: 37.0371716345
          Westernmost_Easting: -75.5659652921
          _ChunkSize: 1
          acknowledgment: This deployment supported by NOAA U.S. IOOS
          actual_range: [  9.8394  23.0101]
          cdm_data_type: TrajectoryProfile
          cdm_profile_variables: time_uv,lat_uv,lon_uv,u,v,profile_id,time,latitude,longitude
          cdm_trajectory_variables: trajectory,wmo_id
          colorBarMaximum: 32.0
          colorBarMinimum: 0.0
          comment: Glider operatored by the Rutgers University Coastal Ocean Observation Lab,...
          contributor_name: Scott Glenn, Oscar Schofield, Josh Kohut, David Aragon, Tina Haskins, Chip...
          contributor_role: Principal Investigator, Principal Investigator, Principal Investigator,...
          creator_email: kerfoot@marine.rutgers.edu
          creator_name: John Kerfoot
          creator_url: http://rucool.marine.rutgers.edu
          date_created: 2014-10-03T15:53:28Z
          date_issued: 2014-10-03T15:53:28Z
          defaultDataQuery: &trajectory=ru22-20130924T2010
          defaultGraphQuery: longitude,latitude,time&.draw=linesAndMarkers&.marker=2|5&.color=0xFFF...
          featureType: TrajectoryProfile
          format_version: IOOS_Glider_NetCDF_v2.0.nc
          geospatial_lat_max: 37.7880349112
          geospatial_lat_min: 37.0371716345
          geospatial_lat_units: degrees_north
          geospatial_lon_max: -74.2846128922
          geospatial_lon_min: -75.5659652921
          geospatial_lon_units: degrees_east
          geospatial_vertical_max: 91.53
          geospatial_vertical_min: 1.0
          geospatial_vertical_positive: down
          geospatial_vertical_units: m
          history: 2014-10-03T15:53:28Z /home/kerfoot/slocum/matlab/spt/export/nc/IOOS/DAC/writeIoosGliderFlatNc.m
2014-10-11T14:34:46Z...
          id: ru22-20130924T2010_f070_8f49_1646
          infoUrl: http://rucool.marine.rutgers.edu
          institution: Rutgers University
          instrument: instrument_ctd
          ioos_category: Temperature
          keywords: AUVS > Autonomous Underwater Vehicles, Oceans > Ocean Pressure > Water...
          keywords_vocabulary: GCMD Science Keywords
          license: This data may be redistributed and used without restriction.  Data provided...
          naming_authority: edu.rutgers.marine
          observation_type: measured
          platform: platform
          platform_type: Slocum Glider
          processing_level: Timestamp and gps positions checked for validity.
          project: MARACOOS
          publisher_email: kerfoot@marine.rutgers.edu
          publisher_name: John Kerfoot
          publisher_url: http://rucool.marine.rutgers.edu
          sea_name: Mid-Atlantic Bight
          source: Observational data from a profiling glider
          sourceUrl: (local files)
          standard_name_vocabulary: CF-v25
          subsetVariables: trajectory,wmo_id,time_uv,lat_uv,lon_uv,u,v,profile_id,time,latitude,l...
          summary: U.S. IOOS Mid-Atlantic Regional Consortium of Ocean Observing Systems (MARACOOS)...
          time_coverage_end: 2013-10-17T00:19:33Z
          time_coverage_start: 2013-09-24T20:18:47Z
          title: ru22-20130924T2010

In [9]:
lon=t.coord(axis='X')

In [10]:
lat=t.coord(axis='Y')

In [11]:
z = t.coord(axis='Z')

In [12]:
tvar = t.coord(axis='T')

In [13]:
shape(t)


Out[13]:
(1, 3294, 680)

In [14]:
tvals= t[0,::5,::2].data

In [15]:
tvals=ma.masked_where(tvals==-999.,tvals)

In [16]:
pcolormesh(flipud(tvals.T));colorbar()


Out[16]:
<matplotlib.colorbar.Colorbar instance at 0x7f2548545e60>

In [17]:
dist, pha = seawater.extras.dist(lat.points[0],lon.points[0],units='km')

In [18]:
d = np.cumsum(dist)
d = np.insert(d,0,0)

In [19]:
print shape(d)


(3294,)

In [20]:
x = (d*np.ones([680,1])).T

In [21]:
zval = z.points

In [22]:
shape(zval)


Out[22]:
(1, 3294, 680)

In [23]:
print shape(x[::5,::2])
print shape(zval[0,::5,::2])
print shape(tvals)


(659, 340)
(659, 340)
(659, 340)

In [24]:
shape(x)


Out[24]:
(3294, 680)

In [25]:
pcolormesh(x[::5,::2],zval[0,::5,::2],tvals)


Out[25]:
<matplotlib.collections.QuadMesh at 0x7f253f9db690>