Skip to content

Commit

Permalink
feat(IMOS): metadata extraction queries
Browse files Browse the repository at this point in the history
Includes some repeatable patterns of query/meta data access.

`IMOS.meta.beam_face_config` - discover the beam face config of an ADCP.
`IMOS.meta.site_bathymetry` - discover the local bathymetry.
`IMOS.meta.velocity_variables` - discover all velocity variables in a
dataset.
  • Loading branch information
ocehugo committed Apr 1, 2021
1 parent d994c7f commit fc362f0
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Util/+IMOS/+meta/beam_face_config.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function [beam_face_config] = beam_face_config(sample_data)
% function [beam_face_config] = beam_face_config(sample_data)
%
% Get the beam face config of an ADCP.
%
% Inputs:
%
% sample_data [struct] - the toolbox dataset.
%
% Outputs:
%
% beam_face_config [char] - 'up','down' or empty.
%
% Example:
%
% %basic usage
%
%
% author: hugo.oliveira@utas.edu.au
%
try
beam_face_config = sample_data.meta.adcp_info.beam_face_config;
return
catch
try
bin_dist = IMOS.get_data(sample_data.dimensions,'HEIGHT_ABOVE_SENSOR');
catch
try
bin_dist = IMOS.get_data(sample_data.dimensions,'DIST_ALONG_BEAMS');
catch
beam_face_config = '';
return
end
end
if all(bin_dist>0)
beam_face_config = 'up';
elseif all(bin_dist<0)
beam_face_config = 'down';
else
beam_face_config = '';
end
end

end
68 changes: 68 additions & 0 deletions Util/+IMOS/+meta/site_bathymetry.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function [depth] = site_bathymetry(sample_data, oper)
%function [depth] = site_bathymetry(sample_data, oper)
%
% Disambiguate the site bathymetry from a sample
%
% Inputs:
%
% sample_data [struct] - the toolbox struct
% oper [function handle] - a function handle to operate on
% the different estimates if any.
% Default: @min
%
% Outputs:
%
% depth [numeric] - the bathymetry value
%
%
% Example:
% sample_data.site_nominal_depth = [];
% sample_data.site_depth_at_deployment = [];
% assert(isempty(IMOS.meta.get_site_bathymetry(sample_data)))
% sample_data.site_nominal_depth = 20;
% assert(IMOS.meta.get_site_bathymetry(sample_data)==20)
% sample_data.site_depth_at_deployment = 10;
% assert(IMOS.meta.get_site_bathymetry(sample_data)==10)
%
% author: hugo.oliveira@utas.edu.au
%
%
narginchk(1, 2)

if ~isstruct(sample_data)
errormsg('Not a struct')
end

if nargin == 1
oper = @min;
else

if ~isfunctionhandle(oper)
errormsg('Second argument not a function handle')
end

end

try
b1 = sample_data.site_depth_at_deployment;
catch
b1 = [];
end

try
b2 = sample_data.site_nominal_depth;
catch
b2 = [];
end

if isempty(b1)
b1 = b2;
end

if isempty(b2)
b2 = b1;
end

depth = oper(b1, b2);

end
53 changes: 53 additions & 0 deletions Util/+IMOS/+meta/velocity_variables.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function [vnames] = velocity_variables(sample_data)
% function [vnames] = velocity_variables(sample_data)
%
% Get the velocity variable names (UCUR,VCUR,and variants)
% from a dataset.
%
% Inputs:
%
% sample_data [struct] - the toolbox dataset.
%
% Outputs:
%
% vnames [cell{str}] - A cell with velocity variable names.
%
% Example:
%
% %basic usage
% dims = IMOS.gen_dimensions('adcp');
% vars = IMOS.gen_variables(dims,{'VEL1','VEL2','UCUR','VCUR'});
% x.variables = vars;
% vnames = IMOS.meta.velocity_variables(x);
% assert(isempty(setdiff(vnames,{'UCUR','VCUR','VEL1','VEL2'})));
% x.variables = IMOS.gen_variables(dims,{'UCUR_MAG','VCUR_MAG','WCUR'});
% vnames = IMOS.meta.velocity_variables(x);
% assert(isempty(setdiff(vnames,{'UCUR_MAG','VCUR_MAG','WCUR'})));
%
% % ambiguity is not handled.
% x.variables = IMOS.gen_variables(dims,{'UCUR','UCUR_MAG'});
% vnames = IMOS.meta.velocity_variables(x);
% assert(isempty(setdiff(vnames,{'UCUR','UCUR_MAG'})))
%
%
% author: hugo.oliveira@utas.edu.au
%
narginchk(1,1);
try
varcell = sample_data.variables;
catch
errormsg('No variable fieldname available.')
end
avail_variables = IMOS.get(varcell,'name');
allowed_variables = {'UCUR_MAG','UCUR','VCUR_MAG','VCUR','WCUR','WCUR_2','ECUR','VEL1','VEL2','VEL3','VEL4'};
vnames=cell(1,numel(allowed_variables));
c=0;
for k= 1:numel(avail_variables)
vname = avail_variables{k};
if inCell(allowed_variables,vname)
c=c+1;
vnames{c} = vname;
end
end
vnames=vnames(1:c);
end

0 comments on commit fc362f0

Please sign in to comment.