Skip to content

Commit

Permalink
Merge pull request #348 from aodn/2.5.9
Browse files Browse the repository at this point in the history
2.5.9
  • Loading branch information
ggalibert committed May 13, 2016
2 parents aeb5c4e + 647ec77 commit bcf31e5
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 299 deletions.
14 changes: 10 additions & 4 deletions GUI/updateViewMetadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,23 @@ function updateViewMetadata(parent, sample_data, mode)
dims = sample_data.dimensions;
lenDims = length(dims);
for k = 1:lenDims
dims{k} = rmfield(dims{k}, {'data', 'typeCastFunc'});
if isfield(dims{k}, 'flags')
dims{k} = rmfield(dims{k}, 'flags');
fieldsToBeRemoved = {'data', 'typeCastFunc', 'flags'};
iToBeRemoved = isfield(dims{k}, fieldsToBeRemoved);
if any(iToBeRemoved)
dims{k} = rmfield(dims{k}, fieldsToBeRemoved(iToBeRemoved));
end
dims{k} = orderfields(dims{k});
end

vars = sample_data.variables;
lenVars = length(vars);
for k = 1:lenVars
vars{k} = orderfields(rmfield(vars{k}, {'data', 'dimensions', 'flags', 'typeCastFunc'}));
fieldsToBeRemoved = {'data', 'dimensions', 'typeCastFunc', 'flags'};
iToBeRemoved = isfield(vars{k}, fieldsToBeRemoved);
if any(iToBeRemoved)
vars{k} = rmfield(vars{k}, fieldsToBeRemoved(iToBeRemoved));
end
vars{k} = orderfields(vars{k});
end

% create a cell array containing global attribute data
Expand Down
11 changes: 6 additions & 5 deletions GUI/viewMetadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,12 @@ function viewMetadata(parent, sample_data, updateCallback, repCallback, mode)

% create a button for replicate option
repButton = uicontrol(...
'Parent', panel,...
'Style', 'pushbutton',...
'String', 'Replicate',...
'Callback', @repButtonCallback...
);
'Parent', panel,...
'Style', 'pushbutton',...
'String', 'Replicate',...
'ToolTip', 'Replicate the content of the selected cell across all imported datasets',...
'Callback', @repButtonCallback...
);

% % create a button for adding metadata fields
% addButton = uicontrol(...
Expand Down
10 changes: 6 additions & 4 deletions NetCDF/exportNetCDF.m
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,12 @@
data = data - datenum('1950-01-01 00:00:00');
end

iNaNData = isnan(data);
if isnumeric(data) && any(any(iNaNData))
fprintf('%s\n', ['Warning : in ' sample_data.toolbox_input_file ...
', there are NaNs in ' dims{m}.name ' dimension (not CF).']);
if isnumeric(data)
iNaNData = isnan(data);
if any(any(iNaNData))
fprintf('%s\n', ['Warning : in ' sample_data.toolbox_input_file ...
', there are NaNs in ' dims{m}.name ' dimension (not CF).']);
end
end

data = typeCastFunction(data);
Expand Down
154 changes: 154 additions & 0 deletions Parser/convertECOrawVar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
function [name, comment, data, calibration] = convertECOrawVar(columnsInfo, sample)
%CONVERTECORAWVAR Processes data from a WetLabs ECO .raw file.
%
% This function is able to convert data retrieved from a .raw WetLabs ECO
% data file. This function is called from the different read???raw functions.
%
% Inputs:
% columnsInfo - ECO parameters infos.
% sample - ECO raw data.
%
% Outputs:
% name - IMOS parameter code.
% comment - any comment on the parameter.
% data - data converted to fit IMOS parameter unit.
% calibration - coefficients calibration used to convert data.
%
% Author: Guillaume Galibert <[email protected]>
%

%
% Copyright (c) 2009, eMarine Information Infrastructure (eMII) and Integrated
% Marine Observing System (IMOS).
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% * Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the distribution.
% * Neither the name of the eMII/IMOS nor the names of its contributors
% may be used to endorse or promote products derived from this software
% without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
narginchk(2, 2);

name = '';
comment = '';
data = [];
calibration = struct([]);

switch upper(columnsInfo.type)
case {'N/U', 'DATE', 'TIME'}
% ignored

case 'IENGR'
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;

case 'PAR' %umol/m2/s
name = 'PAR';
data = columnsInfo.im*10.^((sample-columnsInfo.a0)/columnsInfo.a1);
calibration(1).formula = 'value_engineering_units = calibration_im x 10^((counts - calibration_a0) x calibration_a1)';
calibration(1).im = columnsInfo.im;
calibration(1).a0 = columnsInfo.a0;
calibration(1).a1 = columnsInfo.a1;

case 'CHL' %ug/l (470/695nm)
name = 'CPHL';
comment = ['Artificial chlorophyll data computed from bio-optical ' ...
'sensor raw counts measurements. Originally expressed in ' ...
'ug/l, 1l = 0.001m3 was assumed.'];
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'PHYCOERYTHRIN' %ug/l (540/570nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
comment = 'Expressed in ug/l.';
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'PHYCOCYANIN' %ug/l (630/680nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
comment = 'Expressed in ug/l.';
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'URANINE' %ppb (470/530nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
comment = 'Expressed in ppb.';
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'RHODAMINE' %ug/l (540/570nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
comment = 'Expressed in ug/l.';
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'CDOM' %ppb
name = 'CDOM';
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'NTU'
name = 'TURB';
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

case 'LAMBDA' %m-1 sr-1
name = ['VSF' num2str(columnsInfo.measWaveLength)];
data = (sample - columnsInfo.offset)*columnsInfo.scale;
calibration(1).formula = 'value_engineering_units = (counts - calibration_dark_count) x calibration_scale_factor';
calibration(1).dark_count = columnsInfo.offset;
calibration(1).scale_factor = columnsInfo.scale;

otherwise
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
if isfield(columnsInfo, 'offset')
data = data - columnsInfo.offset;
calibration(1).dark_count = columnsInfo.offset;
end
if isfield(columnsInfo, 'scale')
data = data * columnsInfo.scale;
calibration(1).scale_factor = columnsInfo.scale;
end

end
end
100 changes: 10 additions & 90 deletions Parser/readBB9raw.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
sample_data.variables{end}.dimensions = [];

for i=2:nColumns
[name, comment, data] = getParamDetails(deviceInfo.columns{i}, samples{i});
[name, comment, data, calibration] = convertECOrawVar(deviceInfo.columns{i}, samples{i});

if ~isempty(data)
% dimensions definition must stay in this order : T, Z, Y, X, others;
Expand All @@ -132,6 +132,14 @@
sample_data.variables{end}.coordinates = 'TIME LATITUDE LONGITUDE NOMINAL_DEPTH';
sample_data.variables{end}.comment = comment;

if ~isempty(calibration)
fields = fielnames(calibration);
for j=1:length(fields)
attribute = ['calibration_' fields{j}];
sample_data.variables{end}.(attribute) = calibration.(fields{j});
end
end

% WQM uses SeaBird pressure sensor
if strncmp('PRES_REL', name, 8)
% let's document the constant pressure atmosphere offset previously
Expand All @@ -140,92 +148,4 @@
end
end
end

end

function [name, comment, data] = getParamDetails(columnsInfo, sample)
name = '';
comment = '';
data = [];

switch upper(columnsInfo.type)
case 'N/U'
% ignored

case 'IENGR'
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;

case 'PAR'
% not sure about what to do with this measurement from this
% instrument so for the time being won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
if isfield(columnsInfo, 'offset')
data = data - columnsInfo.offset;
end
if isfield(columnsInfo, 'scale')
data = data * columnsInfo.scale;
end

case 'CHL' %ug/l (470/695nm)
name = 'CPHL';
comment = ['Artificial chlorophyll data computed from bio-optical ' ...
'sensor raw counts measurements. Originally expressed in ' ...
'ug/l, 1l = 0.001m3 was assumed.'];
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'PHYCOERYTHRIN' %ug/l (540/570nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'PHYCOCYANIN' %ug/l (630/680nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'URANINE' %ppb (470/530nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'RHODAMINE' %ug/l (540/570nm)
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'CDOM' %ppb
name = 'CDOM';
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'NTU'
name = 'TURB';
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

case 'LAMBDA' %m-1 sr-1
name = ['VSF' num2str(columnsInfo.measWaveLength)];
data = sample;
data = (data - columnsInfo.offset)*columnsInfo.scale;

otherwise
% not identified by IMOS, won't be output in NetCDF
name = ['ECO3_' columnsInfo.type];
data = sample;
if isfield(columnsInfo, 'offset')
data = data - columnsInfo.offset;
end
if isfield(columnsInfo, 'scale')
data = data * columnsInfo.scale;
end

end
end
end
27 changes: 25 additions & 2 deletions Parser/readECODevice.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function deviceInfo = readECODevice( filename )
%READECODEVICE parses a .dev device file retrieved from a Wetlabs ECO Triplet instrument.
%READECODEVICE parses a .dev device file retrieved from a Wetlabs ECO instrument.
%
%
% Inputs:
Expand Down Expand Up @@ -116,8 +116,31 @@
case {'N/U', 'DKDC'}
% do nothing

% measurements with possible scale, offset and wavelengths infos
case 'PAR'
% measurements in counts with coefficients calibration
deviceInfo.columns{i}.type = upper(type);
im = [];
a1 = [];
a0 = [];

for j=j+1:nLines
if isempty(im), im = regexp(lines{j}, 'im=[\s]*([0-9\.]*)', 'tokens'); end
if isempty(a1), a1 = regexp(lines{j}, 'a1=[\s]*([0-9\.]*)', 'tokens'); end
if isempty(a0), a0 = regexp(lines{j}, 'a0=[\s]*([0-9\.]*)', 'tokens'); end
if ~isempty(im) && ~isempty(a1) && ~isempty(a0)
deviceInfo.columns{i}.im = str2double(im{1});
deviceInfo.columns{i}.a0 = str2double(a0{1});
deviceInfo.columns{i}.a1 = str2double(a1{1});
break;
end
end

if isempty(im) || isempty(a1) || isempty(a0)
error(['couldn''t read PAR coefficients calibration from ' filename]);
end

otherwise
% measurements with possible scale, offset and wavelengths infos
deviceInfo.columns{i}.type = upper(type);
format = '%*s\t%f\t%f\t%f\t%f';
output = cell(1, 4);
Expand Down
Loading

0 comments on commit bcf31e5

Please sign in to comment.