calc_jacobian_bkgnd

PURPOSE ^

CALC_JACOBIAN_BKGND: calculate background image around

SYNOPSIS ^

function img_bkgnd = calc_jacobian_bkgnd( inv_model )

DESCRIPTION ^

 CALC_JACOBIAN_BKGND: calculate background image around
    which initial estimate of jacobian is calculated
 
 img_bkgnd = calc_jacobian_bkgnd( inv_model )
 inv_model   is an EIDORS fwd_model 
 img_bkgnd   is an EIDORS struct

 Usage: 
      The background for calc_jacobian may be specified
      as an estimated value
  inv_model.jacobian_bkgnd.value;  % scalar OR
                                   % vector of Nx1

 Usage:
      The background may be calculated by a function
  inv_model.jacobian_bkgnd.func;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function img_bkgnd = calc_jacobian_bkgnd( inv_model )
0002 % CALC_JACOBIAN_BKGND: calculate background image around
0003 %    which initial estimate of jacobian is calculated
0004 %
0005 % img_bkgnd = calc_jacobian_bkgnd( inv_model )
0006 % inv_model   is an EIDORS fwd_model
0007 % img_bkgnd   is an EIDORS struct
0008 %
0009 % Usage:
0010 %      The background for calc_jacobian may be specified
0011 %      as an estimated value
0012 %  inv_model.jacobian_bkgnd.value;  % scalar OR
0013 %                                   % vector of Nx1
0014 %
0015 % Usage:
0016 %      The background may be calculated by a function
0017 %  inv_model.jacobian_bkgnd.func;
0018 
0019 % (C) 2005-2012 Andy Adler and Bartlomiej Grychtol
0020 % License: GPL version 2 or version 3
0021 % $Id: calc_jacobian_bkgnd.m 5430 2017-04-26 00:58:19Z aadler $
0022 
0023 if ischar(inv_model) && strcmp(inv_model,'UNIT_TEST') do_unit_test; return;end
0024 
0025 img_bkgnd = eidors_cache(@jacobian_bkgnd,{inv_model},'calc_jacobian_bkgnd');
0026 
0027 function img_bkgnd = jacobian_bkgnd(inv_model)
0028 
0029 %%% old interface %%%
0030 if isfield(inv_model.jacobian_bkgnd,'func')
0031    img_bkgnd= feval( inv_model.jacobian_bkgnd.func, inv_model );
0032 elseif isfield(inv_model.jacobian_bkgnd,'value')
0033    if has_params(inv_model.jacobian_bkgnd)
0034       warning('Ignoring parametrization-specific fields in Jacobian background')
0035    end
0036    % allow bkgnd to be scalar or vector
0037    fwd_model= inv_model.fwd_model;
0038    bkgnd = ones(size(fwd_model.elems,1),1);
0039    bkgnd(:)= inv_model.jacobian_bkgnd.value;
0040 
0041    img_bkgnd= eidors_obj('image', 'background image', ...
0042                          'elem_data', bkgnd, ...
0043                          'fwd_model', fwd_model );
0044 else
0045 %%% new interface with parametrizations (params) %%%
0046     fwd_model = inv_model.fwd_model;
0047     img_bkgnd = eidors_obj('image','background image','fwd_model',fwd_model);
0048     flds = fieldnames(inv_model.jacobian_bkgnd);
0049     % copy params from img
0050     for i = 1:length(flds)
0051        img_bkgnd.(flds{i}) = inv_model.jacobian_bkgnd.(flds{i});
0052     end
0053 %     img_bkgnd = data_mapper(img_bkgnd);
0054 end
0055 
0056 
0057 function b = has_params(s)
0058 b = false;
0059 if isstruct(s)
0060    b = any(ismember(fieldnames(s),supported_params));
0061 end
0062 
0063 function do_unit_test
0064 imdl = mk_common_model('d2c2');
0065 test = calc_jacobian_bkgnd(imdl);
0066 unit_test_cmp('t1:type',  test.type, 'image');
0067 unit_test_cmp('t1:elem_data',  test.elem_data, ones(1024,1));
0068 
0069 imdl.jacobian_bkgnd = rmfield(imdl.jacobian_bkgnd,'value');
0070 imdl.jacobian_bkgnd.node_data  = 5;
0071 test = calc_jacobian_bkgnd(imdl);
0072 unit_test_cmp('t2:type',  test.type, 'image');
0073 unit_test_cmp('t2:node_data',  test.node_data, 5);
0074 
0075 imdl.jacobian_bkgnd = rmfield(imdl.jacobian_bkgnd,'node_data');
0076 imdl.jacobian_bkgnd.node_data.val1  = 5;
0077 imdl.jacobian_bkgnd.node_data.val2  = ones(length(imdl.fwd_model.nodes),1);
0078 img = calc_jacobian_bkgnd(imdl);
0079 unit_test_cmp('t3:node_data',  img.node_data, imdl.jacobian_bkgnd.node_data);
0080 
0081 imdl.jacobian_bkgnd = rmfield(imdl.jacobian_bkgnd,'node_data');
0082 imdl.jacobian_bkgnd.elem_data.val1  = 5;
0083 imdl.jacobian_bkgnd.elem_data.val2  = ones(length(imdl.fwd_model.elems),1);
0084 img = calc_jacobian_bkgnd(imdl);
0085 unit_test_cmp('t4:elem_data',  img.elem_data, imdl.jacobian_bkgnd.elem_data);
0086 
0087 imdl = rmfield(imdl,'jacobian_bkgnd');
0088 imdl.jacobian_bkgnd.resistivity.elem_data = 3;
0089 img = calc_jacobian_bkgnd(imdl);
0090 
0091 expect = struct( ...
0092     'type','image', 'name', 'background image', ...
0093     'fwd_model', imdl.fwd_model, 'resistivity', ...
0094      imdl.jacobian_bkgnd.resistivity );;
0095 unit_test_cmp('t5:resistivity',  img, expect);

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005