<jupyter_start><jupyter_text>Table 2 (Journal of Climate submission; Molina et al.) Table 2.  Spectral analysis of area weighted averages of monthly SSTs (◦C) across the tropical Pacific(10.5◦S, 170.5◦W, 10.5◦N, 120.5◦W), as in Figure 5. Years 201-500 were considered for the Global and Pacificexperiments and years 1,001-1,300 were considered for the CESM1 control for correspondence to the sensitivityexperiments during AMOC collapse. Years 101-250 were considered for the Pacific Salt experiment, which were the years PMOC was active. **Table by: <NAME>, NCAR**<jupyter_code># imports 

import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import cftime
from climatico.util import weighted_mean, pacific_lon
import subprocess
import copy
from datetime import timedelta
from config import directory_figs, directory_data
# list of filenames to do this for

file_g02sv = 'b1d.e11.B1850LENS.f09_g16.FWAtSalG02Sv.pop.h.SST.*.nc'
file_g04sv = 'b1d.e11.B1850LENS.f09_g16.FWAtSalG04Sv.pop.h.SST.*.nc'
file_p02sv = 'b1d.e11.B1850LENS.f09_g16.FWAtSalP02Sv.pop.h.SST.*.nc'
file_p04sv = 'b1d.e11.B1850LENS.f09_g16.FWAtSalP04Sv.pop.h.SST.*.nc'
file_psalt = 'b1d.e11.B1850LENS.f09_g16.FWPaSalP04Sv.pop.h.SST.*.nc'
file_cntrl = 'b1d.e11.B1850C5CN.f09_g16.005.pop.h.SST.*.nc'
ds_cntrl = xr.open_mfdataset(f'{directory_data}{file_cntrl}', combine='by_coords')
ds_cntrl = ds_cntrl.assign_coords(time=ds_cntrl.coords['time'] - timedelta(days=17))
ds_cntrl = ds_cntrl.isel(z_t=0)['SST'].sel(time=slice(cftime.DatetimeNoLeap(1001, 1, 1, 0, 0),cftime.DatetimeNoLeap(1301, 1, 1, 0, 0)))

ds_g02sv = xr.open_mfdataset(f'{directory_data}{file_g02sv}', combine='by_coords')
ds_g02sv = ds_g02sv.assign_coords(time=ds_g02sv.coords['time'] - timedelta(days=17))
ds_g02sv = ds_g02sv.isel(z_t=0)['SST'].sel(time=slice(cftime.DatetimeNoLeap(201, 1, 1, 0, 0),cftime.DatetimeNoLeap(501, 1, 1, 0, 0)))

ds_g04sv = xr.open_mfdataset(f'{directory_data}{file_g04sv}', combine='by_coords')
ds_g04sv = ds_g04sv.assign_coords(time=ds_g04sv.coords['time'] - timedelta(days=17))
ds_g04sv = ds_g04sv.isel(z_t=0)['SST'].sel(time=slice(cftime.DatetimeNoLeap(201, 1, 1, 0, 0),cftime.DatetimeNoLeap(501, 1, 1, 0, 0)))

ds_p02sv = xr.open_mfdataset(f'{directory_data}{file_p02sv}', combine='by_coords')
ds_p02sv = ds_p02sv.assign_coords(time=ds_p02sv.coords['time'] - timedelta(days=17))
ds_p02sv = ds_p02sv.isel(z_t=0)['SST'].sel(time=slice(cftime.DatetimeNoLeap(201, 1, 1, 0, 0),cftime.DatetimeNoLeap(501, 1, 1, 0, 0)))

ds_p04sv = xr.open_mfdataset(f'{directory_data}{file_p04sv}', combine='by_coords')
ds_p04sv = ds_p04sv.assign_coords(time=ds_p04sv.coords['time'] - timedelta(days=17))
ds_p04sv = ds_p04sv.isel(z_t=0)['SST'].sel(time=slice(cftime.DatetimeNoLeap(201, 1, 1, 0, 0),cftime.DatetimeNoLeap(501, 1, 1, 0, 0)))

ds_psalt = xr.open_mfdataset(f'{directory_data}{file_psalt}', combine='by_coords')
ds_psalt = ds_psalt.assign_coords(time=ds_psalt.coords['time'] - timedelta(days=17))
ds_psalt = ds_psalt.isel(z_t=0)['SST'].sel(time=slice(cftime.DatetimeNoLeap(101, 1, 1, 0, 0),cftime.DatetimeNoLeap(251, 1, 1, 0, 0)))
def grab_wghtmean(ds_cntrl, ds_g02sv, ds_g04sv, ds_p02sv, ds_p04sv, ds_psalt,
                  lon1 = 170.5, lon2 = -150.5, lat1 = 30.5, lat2 = 40.5):
    """
    Compute weighted mean for the select region.
    
    Args:
        ds_cntrl: Xarray data array for control. 
        ds_g02sv: Xarray data array for 0.2 Sv global experiment.
        ds_g04sv: Xarray data array for 0.4 Sv global experiment.
        ds_p02sv: Xarray data array for 0.2 Sv pacific experiment.
        ds_p04sv: Xarray data array for 0.4 Sv pacific experiment.
        ds_psalt: Xarray data array for pacific salt experiment. 
        lon1 (float): Lower left corner longitude. Defaults to ``170.5``.
        lon2 (float): Upper right corner longitude. Defaults to ``-150.5``.
        lat1 (float): Lower left corner latitude. Defaults to ``30.5``.
        lat2 (float): Upper right corner latitude. Defaults to ``40.5``.
    """
    ds_cntrl_box = weighted_mean(ds_cntrl.sel(
        lon=slice(pacific_lon(lon1, to180=False), pacific_lon(lon2, to180=False)), 
        lat=slice(lat1, lat2)), lat_name='lat')

    ds_g02sv_box = weighted_mean(ds_g02sv.sel(
        lon=slice(pacific_lon(lon1, to180=False), pacific_lon(lon2, to180=False)), 
        lat=slice(lat1, lat2)), lat_name='lat')

    ds_g04sv_box = weighted_mean(ds_g04sv.sel(
        lon=slice(pacific_lon(lon1, to180=False), pacific_lon(lon2, to180=False)), 
        lat=slice(lat1, lat2)), lat_name='lat')

    ds_p02sv_box = weighted_mean(ds_p02sv.sel(
        lon=slice(pacific_lon(lon1, to180=False), pacific_lon(lon2, to180=False)), 
        lat=slice(lat1, lat2)), lat_name='lat')

    ds_p04sv_box = weighted_mean(ds_p04sv.sel(
        lon=slice(pacific_lon(lon1, to180=False), pacific_lon(lon2, to180=False)), 
        lat=slice(lat1, lat2)), lat_name='lat')

    ds_psalt_box = weighted_mean(ds_psalt.sel(
        lon=slice(pacific_lon(lon1, to180=False), pacific_lon(lon2, to180=False)), 
        lat=slice(lat1, lat2)), lat_name='lat')
    
    return ds_cntrl_box, ds_g02sv_box, ds_g04sv_box, ds_p02sv_box, ds_p04sv_box, ds_psalt_box
def grab_specx(da, variable='SST'):
    """
    Calling to ncl directory to use spectral analysis ncl scripts.
    Input your directory into the function.
    Use ``os.path.dirname(os.getcwd())+'/ncl/'`` to find your respective path.

    Args:
        da: Xarray data array .
        variables (str): Variable name. Defaults to ``SST``.
    """
    da.to_dataset(name=variable).to_netcdf('/glade/u/home/molina/python_scripts/climatico/ncl/box_sst.nc')
    subprocess.call([f'ml intel/18.0.5; ml ncl; ncl /glade/u/home/molina/python_scripts/climatico/ncl/specx_anal.ncl'], shell=True)
    spcx = xr.open_dataset("~/python_scripts/climatico/ncl/spcx.nc")
    frqx = xr.open_dataset("~/python_scripts/climatico/ncl/frq.nc")
    spcxa = copy.deepcopy(spcx['spcx'].squeeze().values)
    frqxa = copy.deepcopy(frqx['frq'].squeeze().values)
    del spcx
    del frqx
    return spcxa, frqxa
%%capture
# equatorial pacific
ds_cntrl_box, ds_g02sv_box, ds_g04sv_box, ds_p02sv_box, ds_p04sv_box, ds_psalt_box = grab_wghtmean(
    ds_cntrl, ds_g02sv, ds_g04sv, ds_p02sv, ds_p04sv, ds_psalt, lon1 = -170.5, lon2 = -120.5, lat1 = -5.5, lat2 = 5.5)
# control
spcx_cntrl3, frqx_cntrl3 = grab_specx(ds_cntrl_box)
# 2svg
spcx_g02sv3, frqx_g02sv3 = grab_specx(ds_g02sv_box)
# 4svg
spcx_g04sv3, frqx_g04sv3 = grab_specx(ds_g04sv_box)
# 2svp
spcx_p02sv3, frqx_p02sv3 = grab_specx(ds_p02sv_box)
# 4svp
spcx_p04sv3, frqx_p04sv3 = grab_specx(ds_p04sv_box)
#psalt
spcx_psalt3, frqx_psalt3 = grab_specx(ds_psalt_box)
print('tropical pac; frequency of max variance')
print(str(np.round(frqx_cntrl3[np.argmax(spcx_cntrl3)],3)))
print(str(np.round(frqx_g02sv3[np.argmax(spcx_g02sv3)],3)))
print(str(np.round(frqx_g04sv3[np.argmax(spcx_g04sv3)],3)))
print(str(np.round(frqx_p02sv3[np.argmax(spcx_p02sv3)],3)))
print(str(np.round(frqx_p04sv3[np.argmax(spcx_p04sv3)],3)))
print(str(np.round(frqx_psalt3[np.argmax(spcx_psalt3)],3)))
print('tropical pac; variance of annual cycle')
print(str(np.round(spcx_cntrl3[np.argwhere(frqx_cntrl3==1/12)],2)))
print(str(np.round(spcx_g02sv3[np.argwhere(frqx_g02sv3==1/12)],2)))
print(str(np.round(spcx_g04sv3[np.argwhere(frqx_g04sv3==1/12)],2)))
print(str(np.round(spcx_p02sv3[np.argwhere(frqx_p02sv3==1/12)],2)))
print(str(np.round(spcx_p04sv3[np.argwhere(frqx_p04sv3==1/12)],2)))
print(str(np.round(spcx_psalt3[np.argwhere(frqx_psalt3==1/12)],2)))
print('tropical pac; variance of semi-annual cycle')
print(str(np.round(spcx_cntrl3[np.argwhere(frqx_cntrl3==2/12)],2)))
print(str(np.round(spcx_g02sv3[np.argwhere(frqx_g02sv3==2/12)],2)))
print(str(np.round(spcx_g04sv3[np.argwhere(frqx_g04sv3==2/12)],2)))
print(str(np.round(spcx_p02sv3[np.argwhere(frqx_p02sv3==2/12)],2)))
print(str(np.round(spcx_p04sv3[np.argwhere(frqx_p04sv3==2/12)],2)))
print(str(np.round(spcx_psalt3[np.argwhere(frqx_psalt3==2/12)],2)))<jupyter_output>tropical pac; variance of semi-annual cycle
[[31.4]]
[[26.46]]
[[20.38]]
[[30.44]]
[[25.59]]
[[18.45]]
{'fraction_non_alphanumeric': 0.1532873676434376, 'fraction_numerical': 0.08212262989411476, 'mean_word_length': 5.566693613581245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '313571', 'license': 'MIT', 'n_tokens_mistral': 3935, 'n_tokens_neox': 3543, 'n_words': 552, 'path': 'notebooks/figures/table2_spectral_series.ipynb', 'repo_name': 'mariajmolina/climatico', 'size': '8131'}