Skip to content

Commit

Permalink
Merge pull request #406 from aodn/2.5.23
Browse files Browse the repository at this point in the history
2.5.23
  • Loading branch information
ggalibert committed Dec 22, 2016
2 parents 13917e6 + 60e2139 commit 0c75724
Show file tree
Hide file tree
Showing 16 changed files with 595 additions and 84 deletions.
5 changes: 4 additions & 1 deletion FlowManager/autoQCManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
end
end

% we reset QC flags to 0
for k = 1:length(sample_data)
% reset QC flags to 0
type{1} = 'dimensions';
type{2} = 'variables';
for m = 1:length(type)
Expand All @@ -136,6 +136,9 @@
sample_data{k}.(type{m}){l}.flags(:) = 0;
end
end

% reset QC results
sample_data{k}.meta.QCres = {};
end

% run each data set through the chain
Expand Down
26 changes: 0 additions & 26 deletions Graph/TimeSeries/graphTimeSeriesGeneric.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,6 @@
end
end

% Set axis position so that 1D data and 2D data vertically matches on X axis
mainPanel = findobj('Tag', 'mainPanel');
last_pos_with_colorbar = get(mainPanel, 'UserData');
if isempty(last_pos_with_colorbar) % this is to avoid too many calls to colorbar()
cb = colorbar();
set(get(cb, 'YLabel'), 'String', 'TEST');
pos_with_colorbar = get(ax, 'Position');
last_pos_with_colorbar = pos_with_colorbar;
colorbar(cb, 'off');
set(mainPanel, 'UserData', last_pos_with_colorbar);
else
pos_with_colorbar = get(ax, 'Position');

if pos_with_colorbar(1) == last_pos_with_colorbar(1)
pos_with_colorbar(3) = last_pos_with_colorbar(3);
else
cb = colorbar();
set(get(cb, 'YLabel'), 'String', 'TEST');
pos_with_colorbar = get(ax, 'Position');
last_pos_with_colorbar = pos_with_colorbar;
colorbar(cb, 'off');
set(mainPanel, 'UserData', last_pos_with_colorbar);
end
end
set(ax, 'Position', pos_with_colorbar);

% set background to be grey
set(ax, 'Color', [0.75 0.75 0.75])

Expand Down
8 changes: 7 additions & 1 deletion Graph/TimeSeries/graphTimeSeriesTimeDepth.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@
% xPcolor = [time.data(1:end-1) - diff(time.data)/2; time.data(end) - (time.data(end)-time.data(end-1))/2];
% yPcolor = [depth.data(1:end-1) - diff(depth.data)/2; depth.data(end) - (depth.data(end)-depth.data(end-1))/2];

posWithoutCb = get(ax, 'Position');

h = pcolor(ax, double(xPcolor), double(yPcolor), double(var.data'));
set(h, 'FaceColor', 'flat', 'EdgeColor', 'none');
cb = colorbar();
cb = colorbar('peer', ax);

% reset position to what it was without the colorbar so that it aligns with
% 1D datasets
set(ax, 'Position', posWithoutCb);

% Attach the context menu to colorbar
hMenu = setTimeSerieColorbarContextMenu(var);
Expand Down
2 changes: 1 addition & 1 deletion Graph/TimeSeries/graphTimeSeriesTimeFrequency.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

h = pcolor(ax, double(xPcolor), double(yPcolor), double(var.data'));
set(h, 'FaceColor', 'flat', 'EdgeColor', 'none');
cb = colorbar();
cb = colorbar('peer',ax);

% Attach the context menu to colorbar
hMenu = setTimeSerieColorbarContextMenu(var);
Expand Down
2 changes: 1 addition & 1 deletion Graph/TimeSeries/graphTimeSeriesTimeFrequencyDirection.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
'Position' , posUi2(mainPanel, 50, 1, 50, 1, 0), ...
'String' ,'Time cursor');

cb = colorbar();
cb = colorbar('peer',ax);

% Attach the context menu to colorbar
hMenu = setTimeSerieColorbarContextMenu(myVar);
Expand Down
38 changes: 32 additions & 6 deletions Graph/graphTimeSeries.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [graphs lines vars] = graphTimeSeries( parent, sample_data, vars )
function [graphs, lines, vars] = graphTimeSeries( parent, sample_data, vars )
%GRAPHTIMESERIES Graphs the given data in a time series style using subplots.
%
% Graphs the selected variables from the given data set. Each variable is
Expand Down Expand Up @@ -186,20 +186,46 @@
col = col(mod(vars(k),length(col))+1,:);

% plot the variable
[lines(k,:) labels] = plotFunc(graphs(k), sample_data, k, col, xTickProp);
[lines(k,:), labels] = plotFunc(graphs(k), sample_data, k, col, xTickProp);

if ~isempty(labels)
% set x labels and ticks
xlabel(graphs(k), labels{1});

% set y label and ticks
try uom = [' (' imosParameters(labels{2}, 'uom') ')'];
try uom = ['(' imosParameters(labels{2}, 'uom') ')'];
catch e, uom = '';
end
yLabel = strrep([labels{2} uom], '_', ' ');
if length(yLabel) > 20, yLabel = [yLabel(1:17) '...']; end

% decide where to cut the Y label to display it on 1 or 2 lines
% depending on the number of words obtained from the variable name
yLabel = regexp(labels{2}, '\_', 'split');
if numel(yLabel) < 4
nthWordToCut = min(2, numel(yLabel));
elseif numel(yLabel) < 6
nthWordToCut = 3;
else
nthWordToCut = 4;
end
yLabel = {strjoin(yLabel(1:nthWordToCut), ' '), ...
strjoin(yLabel(nthWordToCut+1:end), ' ')};
yLabel = yLabel(~cellfun(@isempty, yLabel));

yLabel{end+1} = strrep(uom, '_', ' ');
iLength = 12; % arbitrary string cutoff length
%iLong = strlength(yLabel) > iLength; % only R2016b onwards
iLong = cellfun(@length, yLabel) > iLength;
yLabel(iLong) = cellfun(@(x) [x(1:iLength) '...'], yLabel(iLong), 'UniformOutput', false);
ylabel(graphs(k), yLabel);
end
end


function str = strjoin(strCell, sep)
%STRJOIN Join strings in a cell array.
% http://stackoverflow.com/questions/5292437/how-can-i-concatenate-strings-in-a-cell-array-with-spaces-between-them-in-matlab
% R2012b onwards
nCells = numel(strCell);
strCell(1:nCells-1) = strcat(strCell(1:nCells-1), {sep});
str = [strCell{:}];
end
end
103 changes: 95 additions & 8 deletions IMOS/finaliseData.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
end
end

% CF requires DEPTH/TIME coordinate variables must be monotonic (strictly increasing
% or decreasing)
sam = forceMonotonic(sam, mode);

% add empty QC flags for all variables
for k = 1:length(sam.variables)

Expand Down Expand Up @@ -181,27 +185,27 @@
% set the time coverage period from the data
switch mode
case 'profile'
time = getVar(sam.variables, 'TIME');
if time ~= 0
iTime = getVar(sam.variables, 'TIME');
if iTime ~= 0
if isempty(sam.time_coverage_start),
sam.time_coverage_start = sam.variables{time}.data(1);
sam.time_coverage_start = sam.variables{iTime}.data(1);
end
if isempty(sam.time_coverage_end),
sam.time_coverage_end = sam.variables{time}.data(end);
sam.time_coverage_end = sam.variables{iTime}.data(end);
end
else
if isempty(sam.time_coverage_start), sam.time_coverage_start = []; end
if isempty(sam.time_coverage_end), sam.time_coverage_end = []; end
end

case 'timeSeries'
time = getVar(sam.dimensions, 'TIME');
if time ~= 0
iTime = getVar(sam.dimensions, 'TIME');
if iTime ~= 0
if isempty(sam.time_coverage_start),
sam.time_coverage_start = sam.dimensions{time}.data(1);
sam.time_coverage_start = sam.dimensions{iTime}.data(1);
end
if isempty(sam.time_coverage_end),
sam.time_coverage_end = sam.dimensions{time}.data(end);
sam.time_coverage_end = sam.dimensions{iTime}.data(end);
end
else
if isempty(sam.time_coverage_start), sam.time_coverage_start = []; end
Expand All @@ -210,4 +214,87 @@

end

end

function sam = forceMonotonic(sam, mode)
% We make sure that DEPTH/TIME coordinate variables appear
% ordered and that there is no redundant value.
switch mode
case 'profile'
if strcmpi(sam.dimensions{1}.name, 'MAXZ'), return; end % this case produces non compliant files anyway

dimensionName = 'DEPTH'; % so far we only produce downcasts to be compliant
sortMode = 'ascend';
sortModeStr = 'increasingly';

case 'timeSeries'
dimensionName = 'TIME';
sortMode = 'ascend';
sortModeStr = 'increasingly';

end
iDim = getVar(sam.dimensions, dimensionName);

fixStr = ['Try to re-play and fix this dataset when possible using the ' ...
'manufacturer''s software before processing it with the toolbox.'];
currentDateStr = datestr(now_utc, readProperty('exportNetCDF.dateFormat'));

[sam.dimensions{iDim}.data, iSort] = sort(sam.dimensions{iDim}.data, sortMode);
if any(iSort ~= (1:length(sam.dimensions{iDim}.data))')
% We need to sort variables that are functions of this
% dimension accordingly
for k = 1:length(sam.variables)
iFunOfDim = sam.variables{k}.dimensions == iDim;
if any(iFunOfDim)
sam.variables{k}.data = sam.variables{k}.data(iSort,:); % data(iSort,:) works because we know that the sorted dimension is the first one!
end
end

sortedStr = [dimensionName ' values (and their corresponding measurements) had ' ...
'to be sorted ' sortModeStr];
disp(['Info : ' sortedStr ' in ' sam.toolbox_input_file '. ' fixStr]);
if isfield(sam.dimensions{iDim}, 'comment')
sam.dimensions{iDim}.comment = [sam.dimensions{iDim}.comment ' ' sortedStr '.'];
else
sam.dimensions{iDim}.comment = [sortedStr '.'];
end
if isfield(sam, 'history')
sam.history = sprintf('%s\n%s - %s', sam.history, currentDateStr, [sortedStr '.']);
else
sam.history = sprintf('%s - %s', currentDateStr, [sortedStr '.']);
end
end

iRedundantDim = [(diff(sam.dimensions{iDim}.data) == 0); false];
if any(iRedundantDim)
sam.dimensions{iDim}.data(iRedundantDim) = []; % removing first duplicate values

% We need to remove duplicates for variables that are functions of this
% dimension accordingly
for k = 1:length(sam.variables)
iFunOfDim = sam.variables{k}.dimensions == iDim;
if any(iFunOfDim)
extraDims = size(sam.variables{k}.data);
extraDims(iFunOfDim) = 1;
sam.variables{k}.data(repmat(iRedundantDim, extraDims)) = [];
extraDims(iFunOfDim) = length(sam.dimensions{iDim}.data);
sam.variables{k}.data = reshape(sam.variables{k}.data, extraDims);
end
end

redundantStr = [num2str(sum(iRedundantDim)) ' ' dimensionName ' first duplicate values ' ...
'(and their corresponding measurements) had to be discarded'];
disp(['Info : ' redundantStr ' in ' sam.toolbox_input_file '. ' fixStr]);
if isfield(sam.dimensions{iDim}, 'comment')
sam.dimensions{iDim}.comment = [sam.dimensions{iDim}.comment ' ' redundantStr '.'];
else
sam.dimensions{iDim}.comment = [redundantStr '.'];
end
if isfield(sam, 'history')
sam.history = sprintf('%s\n%s - %s', sam.history, currentDateStr, [redundantStr '.']);
else
sam.history = sprintf('%s - %s', currentDateStr, [redundantStr '.']);
end
end

end
Loading

0 comments on commit 0c75724

Please sign in to comment.