Changeset 15399


Ignore:
Timestamp:
07/02/13 10:16:12 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: always force colormap when plot_gridded is on, and do not add white

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/plot_gridded.m

    r14411 r15399  
    2323%Interpolating data on grid
    2424[x_m y_m data_grid]=InterpFromMeshToGrid(elements,x,y,data,xlim(1),ylim(2),post,post,round(diff(ylim)/post),round(diff(xlim)/post),NaN);
     25data_grid_save = data_grid;
    2526if size(data_grid,1)<3 | size(data_grid,2)<3,
    2627        error('data_grid size too small in plot_gridded, check posting and units');
     
    3435
    3536%Process data_grid: add white in NaN and correct caxis accordingly
     37[data_nani data_nanj]=find(isnan(data_grid) | data_grid==-9999);
    3638if exist(options,'caxis'),
    3739        caxis_opt=getfieldvalue(options,'caxis');
     
    4446        data_max=max(data_grid(:));
    4547end
    46 options = changefieldvalue(options,'cbYLim',[data_min data_max]);
    47 white   = data_min - (data_max-data_min)/(lenmap);
    48 options = changefieldvalue(options,'caxis',[white data_max]);
    49 data_grid(isnan(data_grid))=white;
    5048
    5149%Select plot area
     
    5351
    5452%shading interp;
    55 if exist(options,'forcecolormap'),
    56         image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(map)/(data_max-data_min))),map);
    57         h=imagesc(xlim,ylim,image_rgb);
    58 else
    59         h=imagesc(xlim,ylim,data_grid);
     53image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(map)/(data_max-data_min))),map);
     54if exist(options,'shaded'),
     55        a    = -45;
     56        scut = 0.2;
     57        c    = 1;
     58        % computes lighting from elevation gradient
     59        [fx,fy] = gradient(data_grid_save,x_m,y_m);
     60        fxy = -fx*sind(a) - fy*cosd(a);
     61        clear fx fy % free some memory...
     62        fxy(isnan(fxy)) = 0;
     63
     64        % computes maximum absolute gradient (median-style), normalizes, saturates and duplicates in 3-D matrix
     65        r = repmat(max(min(fxy/nmedian(abs(fxy),1 - scut/100),1),-1),[1,1,3]);
     66
     67        % applies contrast using exponent
     68        rp = (1 - abs(r)).^c;
     69        image_rgb = image_rgb.*rp;
     70
     71        % lighter for positive gradient
     72        k = find(r > 0);
     73        image_rgb(k) = image_rgb(k) + (1 - rp(k));
    6074end
     75
     76% set novalues / NaN to black color
     77if ~isempty(data_nani)
     78        nancolor=getfieldvalue(options,'nancolor',[0 0 0]);
     79        image_rgb(sub2ind(size(image_rgb),repmat(data_nani,1,3),repmat(data_nanj,1,3),repmat(1:3,size(data_nani,1),1))) = repmat(nancolor,size(data_nani,1),1);
     80end
     81
     82%plot grid
     83h=imagesc(xlim,ylim,image_rgb);
    6184axis xy
    6285
     
    6891
    6992%Apply options
     93if ~isnan(data_min),
     94        options=changefieldvalue(options,'caxis',[data_min data_max]); % force caxis so that the colorbar is ready
     95end
     96options=addfielddefault(options,'axis','xy equal off'); % default axis
    7097applyoptions(md,data,options);
Note: See TracChangeset for help on using the changeset viewer.