
{"id":178,"date":"2017-05-24T19:52:09","date_gmt":"2017-05-24T19:52:09","guid":{"rendered":"http:\/\/www.seaviewdata.org\/?page_id=178"},"modified":"2017-10-13T20:36:41","modified_gmt":"2017-10-13T20:36:41","slug":"accessing-thredds-data","status":"publish","type":"page","link":"https:\/\/www.seaviewdata.org\/index.php\/accessing-thredds-data\/","title":{"rendered":"Accessing THREDDS Data"},"content":{"rendered":"<h2><\/h2>\n<ul>\n<li><a href=\"#opendap_help\">What is THREDDS and OPeNDAP?<\/a><\/li>\n<li><a href=\"#matlab_help\">For Matlab Users<\/a><\/li>\n<li><a href=\"#python_help\">For Python Users<\/a><\/li>\n<li><a href=\"#r_help\">For R Users<\/a><\/li>\n<li><a href=\"#odv_help\">For ODV Users<\/a><\/li>\n<\/ul>\n<h3> <a name=\"opendap_help\"><\/a>What is THREDDS and OPeNDAP?<\/h3>\n<p>OPeNDAP is a network protocol that is widely used in the Earth Science community to subset and access NetCDF data over the Internet.  SeaView uses a THREDDS server to distribute content from its collections using the OPeNDAP protocol.<\/p>\n<p>One of the big advantages to accessing data through the THREDDS server is the sophisticated sub sampling capabilities of OPeNDAP.  This is important when trying to navigate large, diverse collections like the ones that SeaView assembles.  Another advantage to using the this method is the number of environments that support access to data through OPeNDAP.  Here we briefly demonstrate accessing data through ODV, Matlab, Python, and R.  A more complete list of client support can be found <a href=\"https:\/\/www.opendap.org\/support\/OPeNDAP-clients\" target=\"_blank\">here<\/a>.  The THREDDS server allows users to browse what data are available and access the portions of the collections they are interested in on the platform of their choice.<\/p>\n<p>More information about THREDDS can be found on the <a href=\"http:\/\/www.unidata.ucar.edu\/software\/thredds\/current\/tds\/TDS.html\" target=\"_blank\">UCAR website<\/a>.  Questions and feedback for the SeaView team are encouraged and can be made through our <a href=\"\/index.php\/contact-us\">Contact Page<\/a>.<\/p>\n<link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.4.0\/styles\/default.min.css\">\n<link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.4.0\/styles\/idea.min.css\">\n<script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.4.0\/highlight.min.js\"><\/script><br \/>\n<script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.4.0\/languages\/matlab.min.js\"><\/script><br \/>\n<script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.4.0\/languages\/r.min.js\"><\/script><br \/>\n<script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<h3> <a name=\"matlab_help\"><\/a>Resources for MATLAB Users<\/h3>\n<p><a href=\"http:\/\/www.mathworks.com\/products\/matlab\" target=\"_blank\">MATLAB<\/a> provides <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/network-common-data-form.html\" target=\"_blank\">built in netCDF support<\/a> as of version R2011a.  This includes basic access to netCDF data through OPeNDAP.  Below is an example of how to investigate the metadata of the Pioneer collection and load the lat, lon, time, and temperature variables.<\/p>\n<pre><code class=\"matlab\">\r\n% Pull in the netCDF data from the follwing url\r\nurl = 'http:\/\/www.seaviewdata.org\/thredds\/dodsC\/Pioneer\/CCHDO_BCO-DMO_R2R_ctd_Pioneer_Collection.nc';\r\n\r\n% Load all the metadata into the variable 'metadata'\r\nmetadata = ncinfo(url);\r\n\r\n% Variable names aren't always meaningful - display the\r\n% associated long names and units\r\nnames = {metadata.Variables.Name};\r\nattributes = {metadata.Variables.Attributes};\r\nlong_names = cellfun(@(x) x(1).Value, attributes, 'UniformOutput', false);\r\nunits = cellfun(@(x) char(double(strcmp(x(2).Name, 'units'))*x(2).Value), attributes, 'UniformOutput', false);   \r\nto_display = [names; long_names; units];\r\nfprintf('%s\\t%s\\t%s\\n', to_display{:});\r\n\r\n% Load specific variables\r\n% Variable names and dimensions can be found in metadata\r\nlatitude = ncread(url, 'latitude');\r\nlongitude = ncread(url, 'longitude');\r\ndate_time = ncread(url, 'date_time');\r\ndepth = ncread(url, 'metavar9'); % Variable with long name 'Bot. Depth'\r\n<\/code><\/pre>\n<p>&nbsp;<br \/>\nOther resources for MATLAB users:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.mathworks.com\/products\/statistics.html\" target=\"_blank\">Statistical analysis with MATLAB<\/a><\/li>\n<li><a href=\"https:\/\/www.mathworks.com\/products\/mapping\/code-examples.html\" target=\"_blank\">Code examples for geospatial mapping with MATLAB<\/a><\/li>\n<p>&nbsp;<\/p>\n<h3> <a name=\"python_help\"><\/a>Resources for python Users<\/h3>\n<p>Python users can interact with the THREDDS server using the <a href=\"http:\/\/pydap.readthedocs.io\/en\/latest\/\" target=\"_blank\">PyDAP library<\/a>.  Pydap is easily installed through pip or Anaconda.  Below is a basic example of how to look at the metadata of the Pioneer collection as well as load the time, lat, lon, and temperature variables into python arrays.<\/p>\n<pre><code class=\"python\">\r\n#!\/usr\/bin\/env python\r\n# Install the pydap libraries\r\n# $ pip install pydap \r\n\r\nfrom pydap.client import open_url\r\n\r\nurl = 'http:\/\/www.seaviewdata.org\/thredds\/dodsC\/Pioneer\/CCHDO_BCO-DMO_R2R_ctd_Pioneer_Collection.nc'\r\ndataset=open_url(url)\r\n\r\n# Get a list of variables in the collection\r\nprint(dataset.keys())\r\n\r\n# Variable names aren't always meaningful - get\r\n# associated 'long_name' and 'units'\r\nfor var in dataset:\r\n    long_name = var.attributes['long_name']\r\n\r\n    # Variable may not have units, eg 'Cruise'\r\n    if ('units' in var.attributes):\r\n        units = var.attributes['units']\r\n        print(var.name + \"\\t\" + long_name + \"\\t\" + units)\r\n    else:\r\n        print(var.name + \"\\t\" + long_name)\r\n\r\n# Grab variables of interest\r\ntime = dataset['date_time'][:]\r\nlatitude = dataset['latitude'][:]\r\nlongitude = dataset['longitude'][:]\r\ntemp = dataset['var24'][:]  # Variable associated with 'Temperature'\r\n<\/code><\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<h3> <a name=\"r_help\"><\/a>Resources for R Users<\/h3>\n<p>R users can interact with the THREDDS server using the ncdf4 library.  Below is a basic example of how to look at the metadata of the Pioneer collection as well as load the variable associated with temperature in the collection.<\/p>\n<pre><code class=\"r\">\r\n# Install the required packages:\r\n# To install ncdf for linux, use the command: install.packages(\"ncdf4\")\r\n# To install ncdf for Windows, you need to install a precompiled version by:\r\n# Menu->Packages->Install Package(s) from local zip files and select ncdf4.zip\r\n\r\n# Load the packages:\r\n\r\nlibrary(\"ncdf4\")\r\n\r\n# Load collection into data handle\r\ndata <- nc_open(\"http:\/\/www.seaviewdata.org\/thredds\/dodsC\/Pioneer\/CCHDO_BCO-DMO_R2R_ctd_Pioneer_Collection.nc\")\r\n\r\n# Look at the header column information\r\nprint(data)\r\n\r\n# Grab temperature, for example\r\ntemp <- ncvar_get(data, \"var24\")\r\n\r\n# Close the handle when you are done\r\nnc_close(data)\r\n<\/code><\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<h3> <a name=\"odv_help\"><\/a>Resources for ODV Users<\/h3>\n<p>ODV users can download ODV collections on the download pages.  In addition to the data, collections have styling and processing information within them.  Users can also access data from these ODV collections directly from the THREDDS server from within ODV.  To do this, navigate to the <a href=\"\">SeaView THREDDS Server<\/a> and select a collection in which to explore.  At the top of each collection landing page is a url to the data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.34.19-PM-1024x727.png\" alt=\"\" width=\"810\" height=\"575\" class=\"alignnone size-large wp-image-181\" srcset=\"https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.34.19-PM-1024x727.png 1024w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.34.19-PM-300x213.png 300w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.34.19-PM-768x546.png 768w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.34.19-PM-90x65.png 90w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.34.19-PM.png 933w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>Within ODV remote collections can be accessed through this url.  Navigate to <i>File > Open Remote<\/i> and insert this url into the text box that appears.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.32.49-PM-1024x691.png\" alt=\"\" width=\"810\" height=\"547\" class=\"alignnone size-large wp-image-180\" srcset=\"https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.32.49-PM-1024x691.png 1024w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.32.49-PM-300x202.png 300w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.32.49-PM-768x518.png 768w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.32.49-PM-120x80.png 120w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.32.49-PM.png 932w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>Select 'Okay' and follow any steps to confirm variables to be imported.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.33.18-PM-1024x694.png\" alt=\"\" width=\"810\" height=\"549\" class=\"alignnone size-large wp-image-182\" srcset=\"https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.33.18-PM-1024x694.png 1024w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.33.18-PM-300x203.png 300w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.33.18-PM-768x521.png 768w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.33.18-PM-120x80.png 120w, https:\/\/www.seaviewdata.org\/wp-content\/uploads\/2017\/05\/Screen-Shot-2017-05-23-at-4.33.18-PM.png 931w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is THREDDS and OPeNDAP? For Matlab Users For Python Users For R Users For ODV Users What is THREDDS and OPeNDAP? OPeNDAP is a network protocol that is widely used in the Earth Science community to subset and access NetCDF data over the Internet. SeaView uses a THREDDS<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"template-fullwidth.php","meta":{"footnotes":""},"class_list":["post-178","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/pages\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":9,"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/pages\/178\/revisions"}],"predecessor-version":[{"id":231,"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/pages\/178\/revisions\/231"}],"wp:attachment":[{"href":"https:\/\/www.seaviewdata.org\/index.php\/wp-json\/wp\/v2\/media?parent=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}