0001 function img_bkgnd = calc_jacobian_bkgnd( inv_model )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
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
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
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
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
0050 for i = 1:length(flds)
0051 img_bkgnd.(flds{i}) = inv_model.jacobian_bkgnd.(flds{i});
0052 end
0053
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);