Last active
November 26, 2018 18:49
-
-
Save drf5n/b62049c358c51d1412850aa21798a295 to your computer and use it in GitHub Desktop.
Using nctoolbox to access and plot a slice of Hycom Reanalysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% This uses the Matlab NCToolbox to access HYCOM data and plot a salinity field | |
% | |
% NCToolbox is available from https://github.com/nctoolbox/nctoolbox | |
% HYCOM is available from https://hycom.org/ | |
% | |
% Dig down from HYCOM to find a DODS Data URL | |
% | |
% This is setup to look for the 2012 GOFS 3.0 Reanalysis | |
% | |
% Google for Hycom opendap | |
% https://hycom.org/dataserver/ | |
% Choose GOFS 3.0 Reanalysis from the sidebar: | |
% https://hycom.org/dataserver/gofs-3pt0/reanalysis | |
% Choose the 1995-08-01 → 2012-12-31 dataset: | |
% https://hycom.org/data/glbu0pt08/expt-19pt1 | |
% choose "Access Data Here" button: to get the list of years | |
% http://tds.hycom.org/thredds/GLBu0.08/expt_19.1.html | |
% choose the 2012 dataset to get the TDS page showing different format | |
% http://tds.hycom.org/thredds/GLBu0.08/expt_19.1.html?dataset=GLBu0.08-expt_19.1-2012 | |
% Choose the OpenDAP UI: | |
% http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_19.1/2012.html | |
% Copy the "Data URL" | |
% http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_19.1/2012 | |
% | |
uri = 'http://tds.hycom.org/thredds/dodsC/GLBu0.08/expt_19.1/2012' | |
nc = ncgeodataset(uri) % get a ncgeodataset handle | |
nc.variables % list the variables | |
sv = nc{'salinity'}; % get a ncgeovariable handle | |
sv.attributes | |
svg = sv.grid_interop(:,:,:,:) % get the time,z,lon,lat grid info | |
datestr(sv.timeextent(),29) % find out it ranges from 2012-01-01 to 2012-12-31 | |
% do some plotting like https://github.com/nctoolbox/nctoolbox/blob/master/demos/geodemo_3.m | |
[toi,junk] =near(svg.time,datenum(2012,06,01)) % find the index nearest a particular date | |
doi = 1; | |
pcolorjw(svg.lon,svg.lat,double(sv.data(toi,doi,:,:))); % plot | |
title({sprintf('Hycom %s @ %.0fm',... | |
sv.attribute('long_name'),svg.z(doi));... | |
uri;datestr(svg.time(toi))},'interpreter','none'); | |
% add colorbar with units | |
hcb = colorbar; | |
title(hcb,sv.attribute('units')); | |
print('hycom_salinity_nctoolbox','-dpng') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above Matlab code produces this figure of HYCOM surface salinity for 2012-06-01.
The code uses the NCToolbox (https://github.com/nctoolbox/nctoolbox) within Matlab on the OpenDAP data available from https://hycom.org/data/glbu0pt08/expt-19pt1 .