def calc_amoc_psi_and_index_correlation_map(args): """ A depth plot of correlation with the AMOC index. """ amoc_psi_map, amoc_idx_ts, amoc_idx_smoothed_ts, use_smoothed = args cor_map = np.zeros_like(amoc_psi_map[0,:,:]) for ind, _ in np.ndenumerate(amoc_psi_map[0, :, :]): i, j = ind[0], ind[1] if amoc_psi_map.mask[0, i, j]: continue amoc_psi_ts = pd.Series(amoc_psi_map[:, i, j], amoc_idx_ts.index) if use_smoothed: amoc_psi_ts = lowess_smoothed(amoc_psi_ts) cor_map[i, j] = amoc_idx_ts.corr(amoc_psi_ts) return cor_map
def calc_sst_and_amoc_index_cor_map(args): sst_nh_diff_ts, amoc_psi_max_ts, amoc_psi_max_smoothed_ts, use_smoothed = args assert(sst_nh_diff_ts.shape[0] == len(amoc_psi_max_ts)) assert(sst_nh_diff_ts.shape[0] == len(amoc_psi_max_smoothed_ts)) cor_map = np.zeros_like(sst_nh_diff_ts[0,:,:]) for ind, _ in np.ndenumerate(sst_nh_diff_ts[0, :, :]): i, j = ind[0], ind[1] if sst_nh_diff_ts.mask[0, i, j]: continue diff_ts = pd.Series(sst_nh_diff_ts[:, i, j], amoc_psi_max_ts.index) if use_smoothed: diff_ts = lowess_smoothed(diff_ts) cor_map[i, j] = amoc_psi_max_ts.corr(diff_ts) return cor_map
def main(): parser = argparse.ArgumentParser() parser.add_argument('input_files', nargs='+', help='The MOM ocean.nc input data files.') parser.add_argument('--grid_def_file', default='ocean_grid.nc', help='The ocean grid definition file.') parser.add_argument('--output_file', default='amoc_index_timeseries.png', help='Name of the plot.') plot_name = 'amoc_psi_and_index_correlation_depth_map.png' parser.add_argument('--depth_correlation_output_file', default=plot_name, help='Name of the plot.') plot_name = 'amoc_psi_and_sst_correlation_surface_map.png' parser.add_argument('--surface_correlation_output_file', default=plot_name, help='Name of the plot.') parser.add_argument('--offset', default=0, type=int, help='FIXME.') args = parser.parse_args() do_timeseries_plot = args.output_file.lower() != 'none' do_depth_correlation_plot = \ args.depth_correlation_output_file.lower() != 'none' do_surface_correlation_plot = \ args.surface_correlation_output_file.lower() != 'none' amoc_idx_ts, amoc_psi_max_ts, amoc_psi_mean_ts, amoc_psi, sst_nh_diff_ts = \ collect_timeseries(args.input_files, args.grid_def_file, do_depth_correlation_plot, do_surface_correlation_plot) if args.offset != 0: amoc_psi_max_ts = pd.Series(amoc_psi_max_ts.values[args.offset:], amoc_psi_max_ts.index[:-args.offset]) amoc_idx_ts = pd.Series(amoc_idx_ts.values[:-args.offset], amoc_idx_ts.index[:-args.offset]) if do_depth_correlation_plot: amoc_psi = amoc_psi[args.offset:,:,:] if do_surface_correlation_plot: sst_nh_diff_ts = sst_nh_diff_ts[:-args.offset,:,:] amoc_idx_smoothed_ts = lowess_smoothed(amoc_idx_ts) amoc_psi_max_anomaly_ts = abs_to_anomaly(amoc_psi_max_ts) amoc_psi_max_anomaly_smoothed_ts = lowess_smoothed(amoc_psi_max_anomaly_ts) amoc_psi_max_smoothed_ts = lowess_smoothed(amoc_psi_max_ts) #amoc_idx_smoothed_ts = pd.rolling_mean(amoc_idx_ts, window=12) #amoc_psi_max_anomaly_ts = abs_to_anomaly(amoc_psi_max_ts) #amoc_psi_max_anomaly_smoothed_ts = pd.rolling_mean(amoc_psi_max_anomaly_ts, window=12) #amoc_psi_max_smoothed_ts = pd.rolling_mean(amoc_psi_max_ts, window=12) if do_timeseries_plot: plot_timeseries(amoc_idx_ts, amoc_idx_smoothed_ts, amoc_psi_max_ts, amoc_psi_max_anomaly_ts, amoc_psi_max_anomaly_smoothed_ts, args.output_file) if do_depth_correlation_plot: depth_cor_map = amoc_psi_and_amoc_index_cor_map(amoc_psi, amoc_idx_ts, amoc_idx_smoothed_ts, use_smoothed=True) plot_depth_cor_map(depth_cor_map, args.input_files[0], args.depth_correlation_output_file) if do_surface_correlation_plot: surface_cor_map = sst_and_amoc_max_cor_map(sst_nh_diff_ts, amoc_psi_max_ts, amoc_psi_max_smoothed_ts, use_smoothed=True) plot_surface_cor_map(surface_cor_map, args.input_files[0], args.surface_correlation_output_file) print_amoc_idx_region_info(args.input_files[0]) return 0