Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Munoz committed Nov 14, 2019
0 parents commit 18d0992
Show file tree
Hide file tree
Showing 66 changed files with 5,882 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# salinity-correction-toolbox
Set of matlab scripts to identify correction coefficients for salinity data taken from CTD rossette and glider

The plot_socib_rv_adcp is a set of python scripts and functions developed at SOCIB to plot the data collected by a SBE911+ CTD mounted onboard the SOCIB Research Vessel. They are able to plot the main variables stored into the cnv files and plot them interpolate the profiles over the longitude dimension.

## Prerequisites:
The following libraries need to be added into salinity-correction-toolbox/ext/ directory:

- SOCIB Glider Toolbox v1.0.0 - https://github.com/socib/glider_toolbox
- GSW - https://github.com/TEOS-10/GSW-Matlab
- m_map - https://www.eoas.ubc.ca/~rich/map.html
- mexcdf - https://github.com/dcherian/tools/tree/master/netcdf/mexcdf/snctools
- seawater - http://www.cmar.csiro.au/datacentre/ext_docs/seawater.htm


## The following features are already implemented in the toolbox:
ctd-correction-pack
glider-correction-pack


## The following features are planned or in development:


## Legacy
This toolbox is based on the previous code developed at SOCIB by Dr Krissy Reeve and Dr John T. Allen.

## Copyright

Copyright (C) 2013-2018 ICTS SOCIB - Servei d'observació i predicció costaner de les Illes Balears http://www.socib.es

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function set_ancillary_paths(DeploymentInfo)

global MainPath
global Path
global OPERATIONAL_MODE
global ONLINE_MODE
global TEST_MODE


Path.main = MainPath.main;
Path.dataCtdL1Thredds = MainPath.dataCtdL1Thredds;
Path.dataInsituSalinityRaw = MainPath.dataPortasal;
Path.dataCtd = [MainPath.dataCtd,DeploymentInfo.researchVesselName,'/', DeploymentInfo.instrumentName,'/rawArchive/',DeploymentInfo.deploymentYear,'/',DeploymentInfo.deploymentName,'/'];
Path.dataCTDInsituCalHistory = MainPath.dataCTDInsituCalHistory;

switch OPERATIONAL_MODE
case 1 % when working in the office network
Path.figs = [];
Path.dataOut = [];
case 0 % when NOT working in the office network
Path.figs = []; % paths to figures
Path.dataOut = []; % paths to data
end

switch ONLINE_MODE
case 0 % when NOT working with internet connetion
case 1 % when working with internet connetion
end

switch TEST_MODE
case 0 % when NOT testing
Path.figs = [Path.main,'out/prod/figs/']; % paths to figures
Path.dataOut = [Path.main,'out/prod/data/']; % paths to data
case 1 % when testing
Path.figs = [Path.main,'out/test/figs/']; % paths to figures
Path.dataOut = [Path.main,'out/test/data/']; % paths to data
end

Path.code = [Path.main,'src/']; % path to the source code
Path.libraries = [Path.main,'ext/']; % path to external libraries
Path.resources = [Path.main,'res/']; % path to resources like configuration files and ancillary images

% paths through data folders
Path.dataCtdBtl = [Path.dataCtd,'BOTTLE/'];
Path.dataCtdBinAvgHalfm = [Path.dataCtd,'PROCESSED_SOCIB_halfm/'];
Path.dataCtdBtlMat = [Path.dataOut,'ctd_btl_mat/'];
Path.dataInsituSalinityConverted = [Path.dataOut,'insitu_salinity_mat/'];

Path.dataCorrectionFiles = [Path.dataOut,'correction_data/correction_files/'];
Path.dataCorrectedMat = [Path.dataCorrectionFiles,'corrected_mat/'];
Path.dataCorrectedMat5mBinAvg = [Path.dataCorrectedMat,'corrected_mat_5m_bin_avg/'];
Path.dataCorrectedMatHalfmBinAvg = [Path.dataCorrectedMat,'corrected_mat_halfm_bin_avg/'];
Path.dataCorrectedMatHalfmBinAvgAll = [Path.dataCorrectedMat,'ctd_all_data_halfm_corrected/'];
Path.dataCorrectedNc = [Path.dataCorrectionFiles,'corrected_nc/'];
Path.dataCorrectedNc5mBinAvg = [Path.dataCorrectedNc,'corrected_nc_5m_bin_avg/'];
Path.dataCorrectedNcHalfmBinAvg = [Path.dataCorrectedNc,'corrected_nc_halfm_bin_avg/'];
Path.dataCorrectionCoefficients = [Path.dataOut,'correction_data/correction_coefficients/'];
Path.dataCorrectionCoefficientsMat = [Path.dataCorrectionCoefficients,'correction_coefficients_mat/'];
Path.dataCorrectionCoefficientsNc = [Path.dataCorrectionCoefficients,'correction_coefficients_nc/'];


% path through figures folders
Path.figsTSdiagsAllCruisesThreddsL1 = [Path.figs,'ts_diag_all_cruises_thredds_L1/'];
Path.figsTSdiagsSingleCruisesThreddsL1 = [Path.figsTSdiagsAllCruisesThreddsL1,'single_cruises/'];
Path.figsTSdiagsSingleCruisesThreddsL1Zoom = [Path.figsTSdiagsSingleCruisesThreddsL1,'zoom/'];
Path.figsTSdiagsComparedCruisesThreddsL1 = [Path.figsTSdiagsAllCruisesThreddsL1,'compared_cruises/'];
Path.figsResidualsInsituSalinity = [Path.figs,'residuals_insitu_salinity/'];
Path.figsTSdiagsWithWithoutCorrections = [Path.figs,'ts_diag_with_without_corrections/'];
Path.figsTSdiagsCorrectedReference = [Path.figs,'ts_diag_corrected_reference/'];
Path.figsTSdiagsCorrectedReferenceHalfmSingle = [Path.figsTSdiagsCorrectedReference,'halfm_single/'];
Path.figsTSdiagsCorrectedReferenceHalfmAll = [Path.figsTSdiagsCorrectedReference,'halfm_all/'];

end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

% set_main_paths;
% [deploymentName, ncL1FileName, DIR, instrumentName] = stage_0_select_datasets;
% set_ancillary_paths(deploymentName, instrumentName);
% create_out_directories;

choice = {'PHASE 1. Load Cruise Data', ...
'PHASE 2. Preliminary Results', ...
'PHASE 3. Default Salinity Correction', ...
'PHASE 3a. Manual Salinity Correction', ...
'PHASE 4. Apply Correction Results', ...
'PHASE 5. Write L1_corr Data Files'};

choiceFunction = {'[CtdBtl, InsituSal, DIR, ncL1FileName, DeploymentInfo] = phase_1_select_cruise_data', ...
'phase_2_preliminary_results(DIR)', ...
'[unique_sensor, rmX] = phase_3_salinity_corrections(DIR, DeploymentInfo, choice(3))', ...
'[unique_sensor, rmX] = phase_3_salinity_corrections(DIR, DeploymentInfo, choice(4))', ...
'fnameOutPath = phase_4_apply_salinity_correction_results(DeploymentInfo, DIR, ncL1FileName, unique_sensor)', ...%'Stage_7a_mbtl_insitu_SAL_matchup()', ... %original argument: manual_outlier_removal set to 0 or 1
'write_L1_corr_data_files(fnameOutPath)'};

d = dialog('Position',[80 250 550 410],'Name','CTD Salinity Correction Pack');
firstButtonY = 365;
firstButtonWidth = 350;
firstButtonX = 10;
firstBttonHeight = 40;
% txt = uicontrol('Parent',d,...
% 'Style','text',...
% 'Position',[20 80 210 40],...
% 'String','Select a color');
[x,~]=imread('LogoSocib.png');
I2=imresize(x, [102 113]);
socibLogo=uicontrol('Parent',d,...
'units','pixels',...
'position',[10 30 113 102],...
'cdata',I2);

[x,~]=imread('ctdSocib.jpg');
I2=imresize(x, [202 140]);
ctdLogo=uicontrol('Parent',d,...
'units','pixels',...
'position',[380 162 140 202],...
'cdata',I2);

[x,~]=imread('jericoLogo.jpg');
I2=imresize(x, [102 183]);
jericoLogo=uicontrol('Parent',d,...
'units','pixels',...
'position',[150 30 183 102],...
'cdata',I2);


[~,n] = size(choice);
count = 0;
for i = 1:n
stage(i) = uicontrol('Parent',d,...
'Position',[firstButtonX firstButtonY - count firstButtonWidth firstBttonHeight],...
'String',choice(i),...
'fontSize',12, ...
'Callback',choiceFunction{i}, ...
'Interruptible', 'on');
count = count + 45;
end









28 changes: 28 additions & 0 deletions lib/ctd-salinity-correction-pack/src/phase_1/listncfiles.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function listncfiles

global MainPath

fprintf(1,'Connecting to SOCIB Data Discovery API...\n');
JsonQuery = webread('http://apps.socib.es/DataDiscovery/list-deployments?');

fprintf(1,'Listing available netCDF files from thredds...\n\n');
for i = 1:length(JsonQuery) % keep only deploymnts info from RV CTD. id 172 and 448 and 640 belong to SCB-SBE9001 and SCB-SBE9002 and UTM-SBE9001
if JsonQuery{i}.platform.jsonInstrumentList.id == 172 || JsonQuery{i}.platform.jsonInstrumentList.id == 448 || JsonQuery{i}.platform.jsonInstrumentList.id == 640 || JsonQuery{i}.platform.jsonInstrumentList.id == 642 || JsonQuery{i}.platform.jsonInstrumentList.id == 650
FilteredJsonQuery{i,:} = JsonQuery{i};
fprintf(1,[char(JsonQuery{i}.name),'\n']);
end
end

FilteredJsonQuery = FilteredJsonQuery(~cellfun('isempty',FilteredJsonQuery)); % remove empty cells

for i = 1:length(FilteredJsonQuery) % create cell arrays with list of opendap and file server links to nc files
ncFilesListOpendap{i} = FilteredJsonQuery{i}.platform.jsonInstrumentList.ncOpendapLink;
ncFilesListFileServer{i} = FilteredJsonQuery{i}.platform.jsonInstrumentList.ncFileCatalogLink;
end

NcFilesList.opendap = ncFilesListOpendap;
NcFilesList.fileServer = ncFilesListFileServer;
save([MainPath.dataCtdL1Thredds, 'NcFilesList.mat'], 'NcFilesList');


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function [CtdBtl, InsituSal, DIR, ncL1FileName, DeploymentInfo] = phase_1_select_cruise_data

set_main_paths('salinity_ctd');

[ncL1FileName, DIR, DeploymentInfo] = stage_0_select_datasets;

ctd_sc_set_ancillary_paths(DeploymentInfo);

create_out_directories;

InsituSal = stage_4_read_insitu_salinity_data(DeploymentInfo);

CtdBtl = stage_6a_read_dotbtl_files(DeploymentInfo);

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function [ncL1FileName, DIR, DeploymentInfo] = stage_0_select_datasets

global MainPath
global ONLINE_MODE

DataPname = MainPath.dataCtdL1Thredds;

if ONLINE_MODE == 0
DIR = dir(fullfile(DataPname,'*.nc')); %list of accessible files in downloaded files folder
elseif ONLINE_MODE == 1
%listncfiles; % list accessible files in thredds
NcFilesList = load(fullfile(DataPname,'NcFilesList.mat'));
NcFilesList = NcFilesList.NcFilesList;
RANGE = length(NcFilesList.fileServer);
for i = 1:RANGE
NcFilesListSplit(i).name = strsplit(char(NcFilesList.fileServer(i)),'/');
DIR(i).name = NcFilesListSplit(i).name{10};
DIR(i).pathToFile = NcFilesList.fileServer(i);
end

end

% list of files to select deployment
for i = 1:length(DIR)
%list(i,:) = DIR(i).name;
list{i} = DIR(i).name;
end
[indx,tf] = listdlg('ListString',list,'SelectionMode','single','ListSize',[450,650]);

if ONLINE_MODE == 0
%ncL1FileName = char(list(indx,:));
ncL1FileName = char(list{indx});
elseif ONLINE_MODE == 1
%download file from thredds
% URL = char(NcFilesList.fileServer(indx));
% ncL1FileName = char(list(indx,:));
URL = char(NcFilesList.fileServer(indx));
ncL1FileName = char(list{indx});
urlwrite(URL,[DataPname, ncL1FileName]);
end

deploymentName = regexprep(ncL1FileName,'L1_','','ignorecase'); %remove L1 from file name to be used as parameter to locate further files (btl, insituSal, etc)
deploymentName = deploymentName(1:end-3);
deploymentYear = deploymentName(end-9:end-6);

dum = strsplit(deploymentName,'_');

DeploymentInfo.deploymentCode = dum{1};
DeploymentInfo.researchVesselName = strrep(dum{2},'-','_');
DeploymentInfo.instrumentName = upper(dum{3});
DeploymentInfo.deploymentDate = dum{4};
DeploymentInfo.deploymentName = deploymentName;
DeploymentInfo.deploymentYear = deploymentYear;

% deploymentYear = deploymentName(30:33);

% if ~isnan(strfind(deploymentName,'scb-sbe9002'));
% instrumentName = 'SCB-SBE9002';
% elseif ~isnan(strfind(deploymentName,'scb-sbe9001'));
% instrumentName = 'SCB-SBE9001';
% elseif ~isnan(strfind(deploymentName,'utm-sbe9001'));
% instrumentName = 'UTM-SBE9001';
% elseif ~isnan(strfind(deploymentName,'nat-sbe9001'));
% instrumentName = 'NAT-SBE9001';
% end

end

Loading

0 comments on commit 18d0992

Please sign in to comment.