Ignore:
Timestamp:
Dec 9, 2024, 7:40:14 PM (3 months ago)
Author:
sommeria
Message:

bugs repaired in civ TEST mode

Location:
trunk/src/transform_field
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/transform_field/FFT2_detrend.m

    r1127 r1168  
    1 % 'FFT2_detrend': calculate the 2D spectrum of the input scalar after removing the linear trend
     1% 'FFT2_detrend': calculate the 2D spectrum of the input scalar or image after removing the linear trend
    22%------------------------------------------------------------------------
    33%%%%  Use the general syntax for transform fields with a single input %%%%
     
    3434end
    3535%%%%%%%%%%%%%%%%%%%%%%%%%
    36 [CellInfo,NbDim,errormsg]=find_field_cells(DataIn);
     36[CellInfo,NbDim,errormsg]=find_field_cells(DataIn);% detect the input fields
    3737if ~isempty(errormsg)
    3838    DataOut.Txt=errormsg;
     
    4242DataOut.VarDimName={};
    4343for ilist=1:numel(CellInfo)
    44     if NbDim(ilist)==2 && numel(CellInfo{ilist}.CoordIndex)==2 % field with structured coordinates
     44    if NbDim(ilist)==2 && numel(CellInfo{ilist}.CoordIndex)==2 % field with structured 2D coordinates
     45        %process scalar
     46        ivar=CellInfo{ilist}.VarIndex_scalar(1);
     47        VarName=DataIn.ListVarName{ivar};% name o the scalar field
     48        z=double(DataIn.(VarName));% transform integer input to double real
     49        z(isnan(z))=0;% set NaN values to 0
     50        [npy,npx]=size(z);
     51       
    4552        %process coordinates
    4653        CoordName=DataIn.ListVarName(CellInfo{ilist}.CoordIndex);
    47         x1 = DataIn.(CoordName{2}); y1 = DataIn.(CoordName{1});
    48         [x y] = meshgrid(x1,y1);
    49         coeff(1,1) = sum(sum(x.^2)); coeff(1,2) = sum(sum(x.*y)); coeff(1,3) = sum(sum(x));
    50         coeff(2,1) = sum(sum(x.*y)); coeff(2,2) = sum(sum(y.^2)); coeff(2,3) = sum(sum(y));
    51         coeff(3,1) = sum(sum(x)); coeff(3,2) = sum(sum(y)); coeff(3,3) = length(x1)*length(y1);
     54        x1 = linspace(DataIn.(CoordName{2})(1),DataIn.(CoordName{2})(end),npx);
     55        y1 =linspace(DataIn.(CoordName{1})(1),DataIn.(CoordName{1})(end),npy);
     56        [x,y] = meshgrid(x1,y1);% 2D grid of coordinates
     57       
     58        % prepare the grid of wave vectors
    5259        delta_x = x1(2) - x1(1); delta_y = y1(2) - y1(1);
    5360        Nx = length(x1); Ny = length(y1);
     
    5562        ssx = find(Nxa<Nx/2); ssy = find(Nya<Ny/2);
    5663        Nxa(Nx-ssx+1) = -Nxa(ssx)+1; Nya(Ny-ssy+1) = -Nya(ssy)+1;
    57         [Nxa Ix] = sort(Nxa); [Nya Iy] = sort(Nya);
     64        [Nxa, Ix] = sort(Nxa); [Nya, Iy] = sort(Nya);         
    5865        kx1 = (2*pi/delta_x/Nx)*(Nxa-1); ky1 = (2*pi/delta_y/Ny)*(Nya-1);
    5966        ss = find(ky1>=0); ky1 = ky1(ss);
    60         [kx ky] = meshgrid(kx1,ky1);
     67        [kx,ky] = meshgrid(kx1,ky1);
    6168        DataOut.(CoordName{2}) = kx1; DataOut.(CoordName{1}) = ky1;
    6269        if isfield(DataIn,'CoordUnit')
    63             DataOut.CoordUnit=[DataIn.CoordUnit '^{-1}'];
     70            DataOut.CoordUnit=[DataIn.CoordUnit '^{-1}'];%unit of wave vectors
    6471            DataOut.ListGlobalAttribute={'CoordUnit'};
    6572        end
    66         %process scalar
    67         ivar=CellInfo{ilist}.VarIndex_scalar(1);
    68         VarName=DataIn.ListVarName{ivar};
    69         z=DataIn.(VarName);
    70         z(isnan(z))=0;% set to 0 NaN values
     73       
     74        % get the coeff to calulate the linear trend
     75        coeff(1,1) = sum(sum(x.^2)); coeff(1,2) = sum(sum(x.*y)); coeff(1,3) = sum(sum(x));
     76        coeff(2,1) = sum(sum(x.*y)); coeff(2,2) = sum(sum(y.^2)); coeff(2,3) = sum(sum(y));
     77        coeff(3,1) = sum(sum(x)); coeff(3,2) = sum(sum(y)); coeff(3,3) = length(x1)*length(y1);
    7178        rhs(1) = sum(sum(x.*z)); rhs(2) = sum(sum(y.*z)); rhs(3) = sum(sum(z));
    72         lin_coeff = inv(coeff)*rhs';
     79       % lin_coeff = inv(coeff)*rhs';
     80       lin_coeff = coeff\rhs';
    7381        lin_trend = lin_coeff(1)*x + lin_coeff(2)*y + lin_coeff(3);
    74         z2 = z - lin_trend;
    75         spec2 = abs(fft2(z2)).^2;
     82        z2 = z - lin_trend;% substract the linear trend to the input field
     83       
     84        spec2 = abs(fft2(z2)).^2;% get spectrum as squared of fft modulus
    7685        spec2 = spec2(Iy,Ix);
    7786        spec2 = spec2(ss,:);
    78         DataOut.(VarName) = log10(spec2);
     87        DataOut.(VarName) = log10(spec2);% take the log10 of spectrum
    7988        %DataOut.(VarName) = spec2;
    80         spec_sum=sum(sum(spec2));
    81         kx_mean=sum(sum(spec2.*kx))/spec_sum;
    82         ky_mean=sum(sum(spec2.*ky))/spec_sum;
    83         theta=atand(ky_mean/kx_mean);
    84         lambda=2*pi/(sqrt(kx_mean*kx_mean+ky_mean*ky_mean));
     89%         spec_sum=sum(sum(spec2));
     90%         kx_mean=sum(sum(spec2.*kx))/spec_sum;
     91%         ky_mean=sum(sum(spec2.*ky))/spec_sum;
     92%         theta=atand(ky_mean/kx_mean);
     93%         lambda=2*pi/(sqrt(kx_mean*kx_mean+ky_mean*ky_mean));
    8594       
    8695        DataOut.ListVarName=[CoordName {VarName}];%list of variables
  • trunk/src/transform_field/ima_filter.m

    r1127 r1168  
    3939    dlg_title = 'get the filter size in x and y';
    4040    num_lines= 2;
    41     def     = { '20';'20'};
     41    def     = { '21';'21'};
    4242    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
    4343            isfield(Param.TransformInput,'FilterBoxSize_y')
     
    7474            else
    7575                DataOut.(VarName)=filter2(Mfiltre,DataIn.(VarName));
     76               %DataOut.(VarName)=filter2_uvmat(Param.TransformInput.FilterBoxSize_x,Param.TransformInput.FilterBoxSize_y,DataIn.(VarName));
    7677                DataOut.(VarName)=feval(Atype,DataOut.(VarName));%transform to the initial image format
    7778            end
Note: See TracChangeset for help on using the changeset viewer.