Commit db5fb66b authored by Pierre Cazenave's avatar Pierre Cazenave
Browse files

Merge branch 'dev' of gitlab.ecosystem-modelling.pml.ac.uk:fvcom/fvcom-toolbox into dev

parents 182f7aab 332fa52d
......@@ -176,10 +176,10 @@ for obc_idx = 1:Mobj.nObs
Nested.nObs = Nested.nObs + 1;
Nested.obc_type(cumulative_node_idx) = conf.Nested_type(obc_idx);
if ftbverbose
% figure(1)
% scatter(Nested.x(Nested.read_obc_nodes{cumulative_node_idx}), Nested.y(Nested.read_obc_nodes{cumulative_node_idx}), 20, Nested.weight_node{cumulative_node_idx}, 'filled')
% scatter(Nested.xc(Nested.read_obc_elems{cumulative_elem_idx}), Nested.yc(Nested.read_obc_elems{cumulative_elem_idx}), 20, Nested.weight_cell{cumulative_elem_idx}, 'filled')
if ftbverbose && conf.Nested_type(obc_idx) ~= 1
% figure(1)
% scatter(Nested.x(Nested.read_obc_nodes{cumulative_node_idx}), Nested.y(Nested.read_obc_nodes{cumulative_node_idx}), 20, Nested.weight_node{cumulative_node_idx}, 'filled')
% scatter(Nested.xc(Nested.read_obc_elems{cumulative_elem_idx}), Nested.yc(Nested.read_obc_elems{cumulative_elem_idx}), 20, Nested.weight_cell{cumulative_elem_idx}, 'filled')
fprintf('Original open boundary %d\n', obc_idx)
end
......@@ -210,12 +210,12 @@ for obc_idx = 1:Mobj.nObs
end
end
if ftbverbose
% figure(1)
% scatter(Nested.x(Nested.read_obc_nodes{cumulative_node_idx}), Nested.y(Nested.read_obc_nodes{cumulative_node_idx}), 20, Nested.weight_node{cumulative_node_idx}, 'filled')
% if lev ~= conf.levels(obc_idx)
% scatter(Nested.xc(Nested.read_obc_elems{cumulative_elem_idx}), Nested.yc(Nested.read_obc_elems{cumulative_elem_idx}), 20, Nested.weight_cell{cumulative_elem_idx}, 'filled')
% end
if ftbverbose && conf.Nested_type(obc_idx) ~= 1
% figure(1)
% scatter(Nested.x(Nested.read_obc_nodes{cumulative_node_idx}), Nested.y(Nested.read_obc_nodes{cumulative_node_idx}), 20, Nested.weight_node{cumulative_node_idx}, 'filled')
% if lev ~= conf.levels(obc_idx)
% scatter(Nested.xc(Nested.read_obc_elems{cumulative_elem_idx}), Nested.yc(Nested.read_obc_elems{cumulative_elem_idx}), 20, Nested.weight_cell{cumulative_elem_idx}, 'filled')
% end
fprintf('Nested level %d\n', lev)
end
......
......@@ -283,13 +283,13 @@ for r = riv_idx
% m^{3}s^{-1} and max_discharge is 2000 m^{3}s^{-1}, then you split
% over 5 nodes.
nsplit = ceil(max(tmp_struct.river_flux) / max_discharge);
tmp_struct.river_flux = tmp_struct.river_flux / nsplit;
% Scale the data by nsplit.
for e = 1:length(enames)
if isfield(Mobj, enames{e})
tmp_struct.(enames{e}) = tmp_struct.(enames{e}) / nsplit;
end
end
% for e = 1:length(enames)
% if isfield(Mobj, enames{e})
% tmp_struct.(enames{e}) = tmp_struct.(enames{e}) / nsplit;
% end
% end
% We can keep the original node, but we need to find the
% remaining nsplit-1 nodes.
......
......@@ -65,6 +65,10 @@ if ftbverbose
fprintf('\nbegin : %s\n', subname)
end
if nargin == 0
error('Not enough input arguments. See HELP %s', subname)
end
% Run jobs on multiple workers if we have that functionality. Not sure if
% it's necessary, but check we have the Parallel Toolbox first.
wasOpened = false;
......@@ -159,13 +163,19 @@ for vv = 1:length(varlist);
tic
parfor zi = 1:fz
% Get the current depth layer's data and mask out the NaN
% values.
hytempzcurrent = hytempz(:, :, zi);
% Strip out NaNs so we can extrapolate with TriScatteredInterp.
nanmask = ~isnan(hytempzcurrent);
plonclean = plon(nanmask);
platclean = plat(nanmask);
hytempzclean = hytempzcurrent(nanmask);
% Set up the interpolation object and interpolate the
% current variable to the FVCOM unstructured grid.
% changed to do linear extrapolations
% this should work ok for biology but probably not so well
% for physical variables. Before it was 'natural' and no
% extrapolation
ft = scatteredInterpolant(plon, plat, reshape(hytempz(:, :, zi), [], 1), 'nearest','linear');
ft = scatteredInterpolant(plonclean, platclean, ...
hytempzclean, 'natural', 'nearest');
fvtemp(:, zi) = ft(flon, flat);
end
else
......
......@@ -157,14 +157,14 @@ if isfield(conf.nest,'levels')
Nweight_node = unique(nest.weight_node); % these are sorted increasing
Nweight_cell = unique(nest.weight_cell); % these are sorted increasing
nlevs = unique(conf.nest.levels);
if nlevs==conf.nest.levels
if length(Nweight_node)==conf.nest.levels
warning(['conf.nest.levels have been provided but it has the same number of levels',...
'as the original file. Nothing has changed unless you have provided new weights'])
else
% Decide how many levels to keep
warning(['Chopping levels from nesting file. Assuming unique weight values for',...
'each nesting level. If there are repeated values, this function will not work'])
levels2keepN = Nweight_node(end:-1:end-nlevs+1); % these are now decreasing in order
levels2keepN = Nweight_node(end:-1:end-nlevs); % these are now decreasing in order
levels2keepC = Nweight_cell(end:-1:end-nlevs+1); % these are now decreasing in order
% remove nodes and cells from each variable
nodeid = netcdf.inqDimID(nc2read,'node');
......
function [varlist] = read_fabm_variables(conf)
% For a given configuration, read the ersem variables required to run the
% model
%
% [varlist] = get_fabm_variables(conf)
%
% DESCRIPTION:
% The conf struct contains the parameters needed to locate the restart
% file. We only need the variable names...
%
% INPUT:
% conf - struct. With fields:
% * restart_file - FVCOM restart file with FABM variables (i.e. a donor file).
% OUTPUT:
% varlist - cell array of ERSEM variables.
%
% EXAMPLE USAGE:
% [varlist] = get_fabm_variables(conf);
%
% Author(s):
% Ricardo torres (Plymouth Marine Laboratory)
%
% Revision history:
% 2017-03-10 - First version
%
%==========================================================================
% hard coding these is a bad habit!! These should be identical to the ones
% in get_POLCOMS_ERSEM.m
% conf.casename = 'aqua_v14';
% conf.base_dir = '/users/modellers/rito';
% conf.project_dir = fullfile(conf.base_dir, '/Models/git/fvcom/rosa-implementation/');
% conf.restart_file = fullfile(conf.project_dir, 'matlab/restarts/', ...
% sprintf('%s_ersem_restart_donor.nc', conf.casename));
subname = 'read_fabm_variables';
global ftbverbose
if ftbverbose
fprintf('\nbegin : %s\n', subname)
end
% check file exist
%
if exist(conf.restart_file,'file')
% read ersem variables in donor restart file
info_donor=ncinfo(conf.restart_file);
else
warning(['File ',conf.restart_file,' Not found. Returning'])
return
end
% Generally the last fvcom variable although this could change with a
% different configuration of output variables. Better check on a case by case
% There is no FABM reference in the variable attributes to possibly do it differently
last_fvcom = 'wet_cells_prev_ext';
idx = find(strcmpi({info_donor.Variables.Name},last_fvcom));
ii=1;varlist={};
for ff=idx+1:length(info_donor.Variables)
% brute force search...
res = strfind(info_donor.Variables(ff).Name,['_']);
if ~isempty(res)
% variable seems to have the construct of FABM ...
% check is not a benthic variable
if (length(info_donor.Variables(ff).Dimensions)==3)
varlist(ii)={info_donor.Variables(ff).Name};
ii = ii+1;
end
end
end
return
......@@ -54,12 +54,12 @@ figure(plotOPTS.figure);clf
if isfield(plotOPTS,'Lontick')
MerTick = plotOPTS.Lontick;
else
MerTick = 0.5;
MerTick = floor(10*(diff(plotOPTS.range_lon)/5))/10;
end
if isfield(plotOPTS,'Lattick')
ParTick = plotOPTS.Lattick;
else
ParTick = 0.5;
ParTick = floor(10*(diff(plotOPTS.range_lat)/5))/10;
end
axesm('mercator','MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon],'MeridianLabel','on',...
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment