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
url = 'http://tds.marine.rutgers.edu:8080/thredds/dodsC/cool/glider/all/ru22-20130924T2010.ncCFMA.nc3.nc'
nc = netCDF4.Dataset(url)
ncv = nc.variables
ncv.keys()
[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']
lon = ncv['longitude'][:]
lat = ncv['latitude'][:]
import iris
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))
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
lon=t.coord(axis='X')
lat=t.coord(axis='Y')
z = t.coord(axis='Z')
tvar = t.coord(axis='T')
shape(t)
(1, 3294, 680)
tvals= t[0,::5,::2].data
tvals=ma.masked_where(tvals==-999.,tvals)
pcolormesh(flipud(tvals.T));colorbar()
<matplotlib.colorbar.Colorbar instance at 0x7f2548545e60>
dist, pha = seawater.extras.dist(lat.points[0],lon.points[0],units='km')
d = np.cumsum(dist)
d = np.insert(d,0,0)
print shape(d)
(3294,)
x = (d*np.ones([680,1])).T
zval = z.points
shape(zval)
(1, 3294, 680)
print shape(x[::5,::2])
print shape(zval[0,::5,::2])
print shape(tvals)
(659, 340) (659, 340) (659, 340)
shape(x)
(3294, 680)
pcolormesh(x[::5,::2],zval[0,::5,::2],tvals)
<matplotlib.collections.QuadMesh at 0x7f253f9db690>