Changeset 399 for trunk/src/calc_field.m


Ignore:
Timestamp:
Apr 27, 2012, 12:28:47 PM (12 years ago)
Author:
sommeria
Message:

implementation of thin plate interpolation (proj on planes with mode 'filter'), rationalisation of variable formats in civ_matlab

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/calc_field.m

    r397 r399  
    11%'calc_field': defines fields (velocity, vort, div...) from civx data and calculate them
    22%---------------------------------------------------------------------
    3 % [DataOut,errormsg]=calc_field(FieldName,DataIn)
     3% [DataOut,errormsg]=calc_field(FieldList,DataIn,Coord_interp)
    44%
    55% OUTPUT:
     
    1616%
    1717% INPUT:
    18 % FieldName: string representing the name of the field
     18% FieldList: cell array of strings representing the name(s) of the field(s) to calculate
    1919% DataIn: structure representing the field, as defined in check_field_srtructure.m
     20% Coord_interp(:,nb_coord) optional set of coordinates to interpolate the field (use with thin plate shell)
    2021%
    2122% FUNCTION related
     
    2324% file, depending on the scalar
    2425
    25 function [DataOut,errormsg]=calc_field(FieldName,DataIn,Coord_interp)
     26function [DataOut,errormsg]=calc_field(FieldList,DataIn,Coord_interp)
    2627
    2728%list of defined scalars to display in menus (in addition to 'ima_cor').
     
    4647    'error'}; %error associated to a vector (for stereo or patch)
    4748errormsg=[]; %default error message
    48 if ~exist('FieldName','var')
     49if ~exist('FieldList','var')
    4950    DataOut=list_field;% gives the list of possible fields in the absence of input
    5051else
     
    5253        DataIn=[];
    5354    end
    54     if ischar(FieldName)
    55         FieldName={FieldName};%convert a string input to a cell with one string element
     55    if ischar(FieldList)
     56        FieldList={FieldList};%convert a string input to a cell with one string element
    5657    end
    5758    if isfield(DataIn,'Z')&& isequal(size(DataIn.Z),size(DataIn.X))
     
    7879        XMin=min(min(DataIn.SubRange(1,:,:)));
    7980        YMin=min(min(DataIn.SubRange(2,:,:)));
    80         %         if ~exist('Coord_interp','var')
    81         %             Mesh=sqrt((YMax-YMin)*(XMax-XMin)/numel(DataIn.Coord_tps(:,1,:)));%2D
    82         %             xI=XMin:Mesh:XMax;
    83         %             yI=YMin:Mesh:YMax;
    84         %             [XI,YI]=meshgrid(xI,yI);% interpolation grid
    85         %             Coord_interp(:,1)=reshape(XI,[],1);
    86         %             Coord_interp(:,2)=reshape(YI,[],1);
    87         %             DataOut.coord_y=[yI(1) yI(end)];
    88         %             DataOut.coord_x=[xI(1) xI(end)];
    89         %      end
    9081        check_der=0;
    9182        check_val=0;
    92         for ilist=1:length(FieldName)
    93             switch FieldName{ilist}
     83        nb_sites=size(Coord_interp,1);
     84        nb_coord=size(Coord_interp,2);
     85        for ilist=1:length(FieldList)
     86            switch FieldList{ilist}
    9487                case 'velocity'
    9588                    check_val=1;
    96                     DataOut.U=zeros(size(Coord_interp,1));
    97                     DataOut.V=zeros(size(Coord_interp,1));
     89                    DataOut.U=zeros(nb_sites,1);
     90                    DataOut.V=zeros(nb_sites,1);
    9891                case{'vort','div','strain'}% case of spatial derivatives
    9992                    check_der=1;
    100                     DataOut.(FieldName{ilist})=zeros(size(Coord_interp,1));
    101                 otherwise % case of a scalar
    102                     check_val=1;
    103                     DataOut.(FieldName{ilist})=zeros(size(Coord_interp,1));
    104             end
    105         end
    106         nbval=zeros(size(Coord_interp,1));
     93                    DataOut.(FieldList{ilist})=zeros(nb_sites,1);
     94%                 otherwise % case of a scalar
     95%                     check_val=1;
     96%                     DataOut.(FieldList{ilist})=zeros(size(Coord_interp,1));
     97            end
     98        end
     99        nbval=zeros(nb_sites,1);
    107100        NbSubDomain=size(DataIn.SubRange,3);
     101        %DataIn.Coord_tps=DataIn.Coord_tps(1:end-3,:,:);% suppress the 3 zeros used to fit with the dimensions of variables
    108102        for isub=1:NbSubDomain
    109             if isfield(DataIn,'NbSites')
    110                 nbvec_sub=DataIn.NbSites(isub);
    111             else
    112                 nbvec_sub=numel(find(DataIn.Indices_tps(:,isub)));
    113             end
    114             ind_sel=find(Coord_interp>=DataIn.SubRange(:,1,isub) & Coord_interp<=DataIn.SubRange(:,2,isub));
     103            nbvec_sub=DataIn.NbSites(isub);
     104            check_range=(Coord_interp >=ones(nb_sites,1)*DataIn.SubRange(:,1,isub)' & Coord_interp<=ones(nb_sites,1)*DataIn.SubRange(:,2,isub)');
     105            ind_sel=find(sum(check_range,2)==nb_coord);
    115106            %rho smoothing parameter
    116107            %                 epoints = Coord_interp(ind_sel) ;% coordinates of interpolation sites
     
    118109            nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for eacn interpolation point (in case of subdomain overlap)
    119110            if check_val
    120                 EM = tps_eval(Coord_interp(ind_sel),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the velocity from tps 'sources'
     111                EM = tps_eval(Coord_interp(ind_sel,:),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the velocity from tps 'sources'
    121112            end
    122113            if check_der
    123                 [EMDX,EMDY] = tps_eval_dxy(Coord_interp(ind_sel),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the spatial derivatives from tps 'sources'
    124             end
    125             for ilist=1:length(FieldName)
    126                 switch FieldName{ilist}
     114                [EMDX,EMDY] = tps_eval_dxy(Coord_interp(ind_sel,:),DataIn.Coord_tps(1:nbvec_sub,:,isub));%kernels for calculating the spatial derivatives from tps 'sources'
     115            end
     116            for ilist=1:length(FieldList)
     117                switch FieldList{ilist}
    127118                    case 'velocity'
    128119                        ListFields={'U', 'V'};
     
    154145            end
    155146            DataOut.FF=nbval==0; %put errorflag to 1 for points outside the interpolation rang
    156             DataOut.FF=reshape(DataOut.FF,numel(yI),numel(xI));
     147%            DataOut.FF=reshape(DataOut.FF,numel(yI),numel(xI));
    157148            nbval(nbval==0)=1;
    158             switch FieldName{1}
    159                 case {'velocity','u','v'}
    160                     DataOut.U=reshape(DataOut.U./nbval,numel(yI),numel(xI));
    161                     DataOut.V=reshape(DataOut.V./nbval,numel(yI),numel(xI));
    162                 case 'vort'
    163                     DataOut.vort=reshape(DataOut.vort,numel(yI),numel(xI));
    164                 case 'div'
    165                     DataOut.div=reshape(DataOut.div,numel(yI),numel(xI));
    166                 case 'strain'
    167                     DataOut.strain=reshape(DataOut.strain,numel(yI),numel(xI));
    168             end
     149%             switch FieldList{1}
     150%                 case {'velocity','u','v'}
     151%                     DataOut.U=reshape(DataOut.U./nbval,numel(yI),numel(xI));
     152%                     DataOut.V=reshape(DataOut.V./nbval,numel(yI),numel(xI));
     153%                 case 'vort'
     154%                     DataOut.vort=reshape(DataOut.vort,numel(yI),numel(xI));
     155%                 case 'div'
     156%                     DataOut.div=reshape(DataOut.div,numel(yI),numel(xI));
     157%                 case 'strain'
     158%                     DataOut.strain=reshape(DataOut.strain,numel(yI),numel(xI));
     159%             end
    169160            DataOut.ListVarName=[DataOut.ListVarName ListFields];
    170161            for ilist=3:numel(DataOut.ListVarName)
     
    179170        %% civx data
    180171        DataOut=DataIn;
    181         for ilist=1:length(FieldName)
    182             if ~isempty(FieldName{ilist})
    183                 [VarName,Value,Role,units]=feval(FieldName{ilist},DataIn);%calculate field with appropriate function named FieldName{ilist}
     172        for ilist=1:length(FieldList)
     173            if ~isempty(FieldList{ilist})
     174                [VarName,Value,Role,units]=feval(FieldList{ilist},DataIn);%calculate field with appropriate function named FieldList{ilist}
    184175                ListVarName=[ListVarName VarName];
    185176                ValueList=[ValueList Value];
Note: See TracChangeset for help on using the changeset viewer.