compare_lagged_instantaneous_feedback_strengths.m 4.54 KB
Newer Older
Claas Faber's avatar
Claas Faber committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                         %
%   COMPARE LAGGED AND INSTANTANEOUS FEEDBACK STRENGTHS   %
%   MAIN                                                  %
%                                                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all;

compare_lagged_instantaneous_feedback_strengths_settings;
disp(sprintf('\n%s: %s-%s\n',...
        basin_name,upper(reference_name),upper(response_name)));

% --------- %
% LOAD DATA %
% --------- %

    data = struct();
    data.lagged        = load(in_lagged);
    data.instantaneous = load(in_instantaneous);

% ------------------- %
% PATTERN CORRELATION %
% ------------------- %

    disp('pattern correlations');

    % positive and negative
    rho_positive = corr2(data.instantaneous.feedback_strengths.positive,...
                         data.lagged.feedback_strengths.positive);

    rho_negative = corr2(data.instantaneous.feedback_strengths.negative,...
                         data.lagged.feedback_strengths.negative);

    disp(sprintf('\n\tpositive:\t%1.2f\n\tnegative:\t%1.2f\n',...
                  rho_positive,rho_negative));

% --------------- %
% PLOT DIFFERENCE %
% --------------- %

    disp('plotting and mean values of difference maps')
    for type_string = {'positive','negative'}

        type_string = char(type_string);

        % EXTRACT DATA
        % ++++++++++++

            use_difference = data.instantaneous.feedback_strengths.(type_string)-...
                             data.lagged.feedback_strengths.(type_string);
            disp(sprintf('\tMean diff %s:\t%2.4f',...
                          type_string,nanmean(nanmean(use_difference))));

        if plot_difference

        % SET UP FIGURE
        % +++++++++++++

             hf  = figure;
             hf.Position(3) = scale_figure_width*hf.Position(3);
             hf.Position(4) = scale_figure_height*hf.Position(4);

             % axes
             hax = axes('XLim',lon_cover,'YLim',[0.5 12.5],...
                     'YTick',[1:12],'YTickLabel',month_ids,...
                     'XGrid','on','Layer','top',...
                     'Units','normalized');

             font_size    = floor(hax.FontSize*scale_font_size);
             hax.FontSize = font_size;

             hold(hax,'on');

         % PLOT DATA
         % +++++++++

             % checkerboard, as in the dynamics analysis
             image(hax,central_longitudes,[1:12],use_difference,...
                     'CDataMapping','scaled');
             colorbar(hax);

        % NINO REGIONS
        % ++++++++++++

            % label boxes in a different axis
            hax_labels = axes('XLim',lon_cover,'YLim',[0.5 12.5],...
                    'FontSize',hax.FontSize,'Visible','off');

            hold(hax_labels,'on');

            for c_region = 1:length(region_names)

                x_values = [highlight_regions(c_region,1) highlight_regions(c_region,2) ...
                            highlight_regions(c_region,2) highlight_regions(c_region,1) ...
                            highlight_regions(c_region,1)];

                y_values = [highlight_y_values(c_region,1) highlight_y_values(c_region,1) ...
                            highlight_y_values(c_region,2) highlight_y_values(c_region,2) ...
                            highlight_y_values(c_region,1)];

                h_patch = patch(x_values,y_values,region_colours(c_region,:),...
                        'EdgeColor','none');

            % plot in highlight regions
            end

         % POLISHING AND PRINTING
         % ++++++++++++++++++++++

             xlabel(hax,'\circ lon');
             ylabel(hax,'Month');

             % title
             fig_title = strrep(title_dummy,'@ANOMALY_TYPE@',...
                     [upper(type_string(1)),type_string(2:end)]);
             h_title = title(hax_labels,fig_title);
             set(h_title,'Visible','on');

             % align axes
             hax.Position        = hax.Position+axes_offset;
             hax_labels.Position = hax.Position;

            % offset the patches
            hax_labels.Position(2)   = hax_labels.Position(2)+hax_labels_height_offset.(basin_name);

             % colormap and number of displayed colours
             hax.CLim = c_limits;
             colormap(use_cmap);

             % print
             fig_name = strrep(name_dummy,'@ANOMALY_TYPE@',type_string);
             print(hf,res_flag,fig_name,'-dpng');
             close(hf);

        % if: plot difference
        end

% for: plot difference for pos/neg
 end