source: trunk/src/mask_proj.m @ 643

Last change on this file since 643 was 639, checked in by sommeria, 12 years ago

introduction of mask on projection: fct mask_proj

File size: 4.8 KB
Line 
1%'mask_proj': projects the field on a projection object
2%--------------------------------------------------------------------------
3%  function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
4%
5%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
6%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
7%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
8%     This file is part of the toolbox UVMAT.
9%
10%     UVMAT is free software; you can redistribute it and/or modify
11%     it under the terms of the GNU General Public License as published by
12%     the Free Software Foundation; either version 2 of the License, or
13%     (at your option) any later version.
14%
15%     UVMAT is distributed in the hope that it will be useful,
16%     but WITHOUT ANY WARRANTY; without even the implied warranty of
17%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
19%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
20
21function [ProjData,errormsg]=mask_proj(FieldData,MaskData)
22errormsg='';%default
23ProjData=FieldData;
24
25
26%% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
27[CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData);
28if ~isempty(errormsg)
29    errormsg=['error in proj_field/proj_plane:' errormsg];
30    return
31end
32[Npy,Npx]=size(MaskData.A);
33DX=(MaskData.AX(2)-MaskData.AX(1))/(Npx-1);
34DY=(MaskData.AY(2)-MaskData.AY(1))/(Npy-1);
35for icell=1:numel(CellInfo)
36    if NbDimArray(icell)==2
37        switch CellInfo{icell}.CoordType;
38            case  'scattered'
39                XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)};
40                YName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)};
41                mask_ind_i=round(0.5+(FieldData.(XName)-MaskData.AX(1))/DX);%nbpoint terms
42                mask_ind_j=round(0.5+(FieldData.(YName)-MaskData.AY(1))/DY);%nbpoint terms
43                checkin=mask_ind_j+Npy*(mask_ind_i-1);%array  of mask indices for the nbpoints
44                checkin=checkin(mask_ind_i>=1 & mask_ind_i<=Npx & mask_ind_j>=1 & mask_ind_j<=Npy);%reduced array  of mask indices (inside the image)
45                checkfalse=true(size(FieldData.(XName)));
46                MaskData.A=reshape(MaskData.A,1,[]);
47                checkfalse(MaskData.A(checkin)>200)=0;
48                if ~isfield(FieldData,'FF')
49                    FieldData.FF=zeros(size(FieldData.(XName)));
50                    FieldData.ListVarName=[FieldData.ListVarName {'FF'}];
51                    FieldData.VarDimName=[FieldData.VarDimName FieldData.VarDimName(CellInfo{icell}.CoordIndex(1))];
52                    FieldData.VarAttribute{numel(FieldData.VarDimName)}.Role='errorflag';
53                end
54                for ivar=1:numel(CellInfo{icell}.VarIndex)
55                    VarName=FieldData.ListVarName{CellInfo{icell}.VarIndex(ivar)};
56                    FieldData.(VarName)(checkfalse)=0;
57                    FieldData.FF(checkfalse)=1;
58                end
59            case  'grid'
60                XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)};
61                YName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)};
62                Var1Name=FieldData.ListVarName{CellInfo{icell}.VarIndex(1)};
63                [Npy_field,Npx_field]=size(FieldData.(Var1Name));
64                DX_field=(FieldData.(XName)(end)-FieldData.(XName)(1))/(Npx_field-1);
65                DY_field=(FieldData.(YName)(end)-FieldData.(YName)(1))/(Npy_field-1);
66                XArray=FieldData.(XName)(1):DX_field:FieldData.(XName)(end);
67                YArray=FieldData.(YName)(1):DY_field:FieldData.(YName)(end);
68                XMask=MaskData.AX(1):DX:MaskData.AX(end);
69                YMask=MaskData.AY(end):-DY:MaskData.AY(1);
70                [XMask,YMask]=meshgrid(XMask,YMask);
71                Mask = interp2(XMask,YMask,MaskData.A,XArray,YArray','nearest');
72                figure(1)
73                image(MaskData.A)
74                Mask=Mask>200;
75                if ~isfield(FieldData,'FF')
76                    FieldData.FF=zeros(size(FieldData.(XName)));
77                    FieldData.ListVarName=[FieldData.ListVarName {'FF'}];
78                    FieldData.VarDimName=[FieldData.VarDimName FieldData.VarDimName(CellInfo{icell}.CoordIndex(1))];
79                    FieldData.VarAttribute{numel(FieldData.VarDimName)}.Role='errorflag';
80                end
81                for ivar=1:numel(CellInfo{icell}.VarIndex)
82                    VarName=FieldData.ListVarName{CellInfo{icell}.VarIndex(ivar)};
83                    FieldData.(VarName)=FieldData.(VarName).*Mask;
84                    FieldData.FF=~Mask;
85                end
86        end
87    end
88end
89       
90
Note: See TracBrowser for help on using the repository browser.