Skip to content
Brita Irving edited this page Mar 19, 2021 · 9 revisions

Welcome to the data_analysis_tools wiki!

MATLAB functions useful in various applications

makefig.m

utility script used to create standard figure. Figure characteristics can easily be set such as position, fontsize, fontname, etc.

makefig_subplots.m

utility script used to create standard figure with multiple subplots. Axes positions and characteristics very adaptable.

standard_printfig_highrespng.m

utility script used to save figures in a standard format.

manual_timeSeries_QC.m

Script to manually QC data in timeseries format. Useful for any timeseries data but created for moored oceanographic datasets.

gsw_rho_irving.m

gsw_rho.m adapted to pass through pressure, temperature, and practical salinity (must be in specific data structure format). If uncertainties are passed through, calls gsw_errorprop_irving.m

gsw_errorprop_irving.m

Calculate uncertainties for TEOS-10 potential temperature (pt), conservative temperature (CT), absolute salinity (SA), and density (rho) using the error propagation equations from Dai & Zhang 2018.

mooring_calibration_discrete_samples.m

In-situ discrete calibrations

Discrete bottle samples collected in-situ are used to calculate absolute offsets and correct for sensor drift. Ideally, in-situ discrete samples would be taken throughout the deployment at the exact location and depth of the sensor. The next best scenario is in-situ discrete bottle samples collected at the time of deployment and recovery at the exact location and depth of the sensor. The reality often does not meet our best case scenarios. Since moorings are often deployed on ships of opportunity where sampling equipment, personnel, and time are limited, discrete samples can be few and far between. The availability of in-situ discrete samples for calibration is further reduced in the Arctic where seasonal sea ice and remoteness limit ship activity.

In this toolbox, available in-situ discrete samples have been combined into a single table that is read into MATLAB. Loose criteria to match discrete samples in time and space with moored data are used to select which discrete samples are available, and then the user chooses whether to use any of the available discrete samples to correct the moored sensor data. CTD cast data and all available discrete samples are plotted to aid the user in selected calibration points. The user can choose 1) select a single discrete sample, 2) interpolate discrete samples to sensor depth, or 3) average of multiple discrete samples to use as calibration point. Examples of a plots that the user looks at to select in-situ discrete samples used for calibration points. Density and salinity are shown to see if water mass characteristics are the same as those sampled by the moored sensor.

I've included a template (Mooring_CalibrationSamples_template.xlsx) to help you utilize this script. Code to read in file:

%% Read calibration cast information from excel file.
% This code assumes column names are the same as in Mooring_CalibrationSamples_template.xlsx
limit = 1; 
day_int = 5;
rcfgs = detectImportOptions(cfg.path.calfile,'sheet','CalibrationSampleData','DatetimeType','text');
rcfgs.VariableUnitsRange = 'A2';
rcfgs.VariableTypes{3} = 'datetime'; % HH:MM:SS
idx_dble = find(strcmp(rcfgs.VariableNames,'DepSM'),1):find(strcmp(rcfgs.VariableNames,'Comments'),1);
rcfgs.VariableTypes(idx_dble) = {'double'};
cfg.calcasts = readtable(cfg.path.calfile,rcfgs);
cfg.calcasts.Time = datestr(cfg.calcasts.Time,'HH:MM:SS');
cfg.calcasts.dnum = datenum(strcat(num2str(cfg.calcasts.Date),cfg.calcasts.Time),'yyyymmddHH:MM:SS');
cfg.calcasts.dstr = datestr(cfg.calcasts.dnum);
cfg.calcasts.dtime = datetime(cfg.calcasts.dnum,'ConvertFrom','datenum');
cfg.calcasts.density = sw_dens(cfg.calcasts.Salinity,cfg.calcasts.Temp,cfg.calcasts.Pressure);
%% Pull out nearby casts within +/- day_int
if limit
  idx_between = isbetween(cfg.calcasts.dtime,cfg.mooring.deploydate-day_int,cfg.mooring.recoverdate+day_int);
  cfg.calcasts = cfg.calcasts(idx_between,:);
end

%% Add unique identifier by combining cruise and station name
% In case cruises have the same station name, combine them.
cfg.calcasts.cruise_station = strcat(cfg.calcasts.CRUISE,'_',cfg.calcasts.StationID);
% Replace all miscellaneous characters
cfg.calcasts.cruise_station = strrep(cfg.calcasts.cruise_station,'-','_');
cfg.calcasts.cruise_station = strrep(cfg.calcasts.cruise_station,' ','');
cfg.calcasts.cruise_station = strrep(cfg.calcasts.cruise_station,'.','_');
cfg.calcasts.cruise_station = strrep(cfg.calcasts.cruise_station,'/','_');

References

Dai, H., & Zhang, X. (2018). Uncertainties in climatological seawater density calculations. Journal of Geophysical Research: Oceans, 123, 2192–2212. https://doi.org/10.1002/2017JC013427 https://agupubs.onlinelibrary.wiley.com/doi/abs/10.1002/2017JC013427