#timeslice = slice(0,nt) #timeslice = slice(int(Tn),nt-int(Tn)) # Q_s = Q_s.isel(time=timeslice) # Q_r = Q_r.isel(time=timeslice) # tendsst = tendsst.isel(time=timeslice) # sst = sst.isel(time=timeslice) order = 5 fs = 1 # sample rate, (cycles per month) Tn_enso = 12.*2 cutoff_enso = 1/Tn_enso # desired cutoff frequency of the filter (cycles per month) enso = st2.spatial_ave_xr(sst.sel(lon=slice(190,240)), lats=lats.sel(lat=slice(-5,5))) enso = st.butter_lowpass_filter_xr(enso,cutoff_enso,fs,order) sste = st2.regressout_x(enso, sste) Q_se = st2.regressout_x(enso, Q_se) Q_re = st2.regressout_x(enso, Q_re) Q_tote = st2.regressout_x(enso, Q_tote) #lambdaQ_totlag0 = st.cov(sste, Q_tote, lagx=0)/st.cov(sste,sste, lagx=0) lambdaQ_totlag1 = st.cov(sste, Q_tote, lagx=-1)/st.cov(sste,sste, lagx=-1) #lambdaQ_totlag2 = st.cov(sste, Q_tote, lagx=-2)/st.cov(sste,sste, lagx=-2) #lambdaQ_totlag3 = st.cov(sste, Q_tote, lagx=-3)/st.cov(sste,sste, lagx=-3) #lambdaQ_tot = (lambdaQ_totlag1 + lambdaQ_totlag2 + lambdaQ_totlag3)/3. lambdaQ_tot = lambdaQ_totlag1 #lambdaQ_tot = lambdaQ_totlag3
# Filter requirements. order = 5 fs = 1 # sample rate, (cycles per month) Tn = 12. * 3 cutoff = 1 / Tn # desired cutoff frequency of the filter (cycles per month) if not (lowpass): Tn = 0. # Butterworth low-pass filter if lowpass: #sst = xr.DataArray(st.butter_lowpass_filter(sst, cutoff, fs, order),dims=sst.dims,coords=sst.coords) #thf = xr.DataArray(st.butter_lowpass_filter(thf, cutoff, fs, order),dims=thf.dims,coords=thf.coords) #Q_net_surf = xr.DataArray(st.butter_lowpass_filter(Q_net_surf, cutoff, fs, order),dims=Q_net_surf.dims,coords=Q_net_surf.coords) sst = st.butter_lowpass_filter_xr(sst, cutoff, fs, order) thf = st.butter_lowpass_filter_xr(thf, cutoff, fs, order) Q_net_surf = st.butter_lowpass_filter_xr(Q_net_surf, cutoff, fs, order) Q_ek = st.butter_lowpass_filter_xr(Q_ek, cutoff, fs, order) h = st.butter_lowpass_filter_xr(h, cutoff, fs, order) #Q_ek_f = st.butter_lowpass_filter_xr(Q_ek_f, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) # Mask zero values (continents) ocean_points1 = ~(sst == 0) ocean_points2 = ~(xr.ufuncs.isnan(sst)) ocean_points = xr.ufuncs.logical_or(ocean_points1, ocean_points2) sst = sst.where(ocean_points) thf = thf.where(ocean_points) Q_net_surf = Q_net_surf.where(ocean_points)
# Filter requirements. order = 5 fs = 1 # sample rate, (cycles per month) Tn =4.*12 cutoff = 1/Tn # desired cutoff frequency of the filter (cycles per month) if not(lowpass): Tn = 0. # Butterworth low-pass filter if lowpass: #sst = xr.DataArray(st.butter_lowpass_filter(sst, cutoff, fs, order),dims=sst.dims,coords=sst.coords) #thf = xr.DataArray(st.butter_lowpass_filter(thf, cutoff, fs, order),dims=thf.dims,coords=thf.coords) #Q_net_surf = xr.DataArray(st.butter_lowpass_filter(Q_net_surf, cutoff, fs, order),dims=Q_net_surf.dims,coords=Q_net_surf.coords) sst = st.butter_lowpass_filter_xr(sst, cutoff, fs, order) #thf = st.butter_lowpass_filter_xr(thf, cutoff, fs, order) Qs = st.butter_lowpass_filter_xr(Qs, cutoff, fs, order) #Q_ek = st.butter_lowpass_filter_xr(Q_ek, cutoff, fs, order) # sst_ECCO = st.butter_lowpass_filter_xr(sst_ECCO, cutoff, fs, order) # Tmxl_ECCO = st.butter_lowpass_filter_xr(Tmxl_ECCO, cutoff, fs, order) #Q_ek_f = st.butter_lowpass_filter_xr(Q_ek_f, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) # Mask zero values (continents) ocean_points1 = ~(sst==0) ocean_points2 = ~(xr.ufuncs.isnan(sst)) ocean_points = xr.ufuncs.logical_or(ocean_points1, ocean_points2) sst = sst.where(ocean_points) Qs = Qs.where(ocean_points)
nt = sst.shape[0] #timeslice = slice(0,nt) #timeslice = slice(int(Tn),nt-int(Tn)) # Q_s = Q_s.isel(time=timeslice) # Q_r = Q_r.isel(time=timeslice) # tendsst = tendsst.isel(time=timeslice) # sst = sst.isel(time=timeslice) order = 5 fs = 1 # sample rate, (cycles per month) Tn = 4. * 12. cutoff = 1 / Tn # desired cutoff frequency of the filter (cycles per month) if lowpass: sst_lp = st.butter_lowpass_filter_xr(sst, cutoff, fs, order) r2corrs = st2.cor(sst_lp, sst_lp, lagx=2) else: r2corrs = st2.cor(sst, sst, lagx=2) #Niño 3.4 (5N-5S, 170W-120W order = 5 fs = 1 # sample rate, (cycles per month) Tn_enso = 6. cutoff_enso = 1 / Tn # desired cutoff frequency of the filter (cycles per month) enso = st2.spatial_ave_xr(sst.sel(lon=slice(190, 240)), lats=lats.sel(lat=slice(-5, 5))) enso = st.butter_lowpass_filter_xr(enso, cutoff_enso, fs, order)
# Filter requirements. order = 5 fs = 1 # sample rate, (cycles per month) Tn = 4. * 12 cutoff = 1 / Tn # desired cutoff frequency of the filter (cycles per month) if not (lowpass): Tn = 0. # Butterworth low-pass filter if lowpass: #sst = xr.DataArray(st.butter_lowpass_filter(sst, cutoff, fs, order),dims=sst.dims,coords=sst.coords) #thf = xr.DataArray(st.butter_lowpass_filter(thf, cutoff, fs, order),dims=thf.dims,coords=thf.coords) #Q_net_surf = xr.DataArray(st.butter_lowpass_filter(Q_net_surf, cutoff, fs, order),dims=Q_net_surf.dims,coords=Q_net_surf.coords) sst = st.butter_lowpass_filter_xr(sst, cutoff, fs, order) thf = st.butter_lowpass_filter_xr(thf, cutoff, fs, order) #Q_net_surf = st.butter_lowpass_filter_xr(Q_net_surf, cutoff, fs, order) #Q_ek = st.butter_lowpass_filter_xr(Q_ek, cutoff, fs, order) #Q_ek_f = st.butter_lowpass_filter_xr(Q_ek_f, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) # Mask zero values (continents) ocean_points1 = ~(sst == 0) ocean_points2 = ~(xr.ufuncs.isnan(sst)) ocean_points = xr.ufuncs.logical_or(ocean_points1, ocean_points2) sst = sst.where(ocean_points) thf = thf.where(ocean_points) #Q_net_surf = Q_net_surf.where(ocean_points) #Q_ek = Q_ek.where(ocean_points)
# Scale the SST tendency by the ratio of MXL temp tendency / SST tendency from ECCO (as an esimate for a more physical result) sst_raw = sst Qs_raw = Qs tendT_mxl_raw = tendT_mxl #Q_net_surf_raw = Q_net_surf #Q_ek_raw = Q_ek for jj, Tn in enumerate(Tns): cutoff = 1 / Tn print('Tn', Tn) if Tn > 0: sst = st.butter_lowpass_filter_xr(sst_raw, cutoff, fs, order) #thf = st.butter_lowpass_filter_xr(thf_raw, cutoff, fs, order) Qs = st.butter_lowpass_filter_xr(Qs_raw, cutoff, fs, order) tendT_mxl = st.butter_lowpass_filter_xr(tendT_mxl_raw, cutoff, fs, order) #Q_net_surf = st.butter_lowpass_filter_xr(Q_net_surf_raw, cutoff, fs, order) #Q_ek = st.butter_lowpass_filter_xr(Q_ek_raw, cutoff, fs, order) #sst_ECCO = st.butter_lowpass_filter_xr(sst_ECCO, cutoff, fs, order) #Tmxl_ECCO = st.butter_lowpass_filter_xr(Tmxl_ECCO, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) #Tmxl_var_ECCO = Tmxl_ECCO.var(dim='time') #sst_var_ECCO = sst_ECCO.var(dim='time') # Scale the SST tendency by the ratio of MXL temp tendency / SST tendency from ECCO (as an esimate for a more physical result)
sst_raw = sst thf_raw = thf Q_net_surf_raw = Q_net_surf sst_ECCO_raw = sst_ECCO Tmxl_ECCO_raw = Tmxl_ECCO #Q_ek_raw = Q_ek for jj, Tn in enumerate(Tns): cutoff = 1 / Tn print('Tn', Tn) if Tn > 0: sst = st.butter_lowpass_filter_xr(sst_raw, cutoff, fs, order) thf = st.butter_lowpass_filter_xr(thf_raw, cutoff, fs, order) Q_net_surf = st.butter_lowpass_filter_xr(Q_net_surf_raw, cutoff, fs, order) #Q_ek = st.butter_lowpass_filter_xr(Q_ek_raw, cutoff, fs, order) #sst_ECCO = st.butter_lowpass_filter_xr(sst_ECCO, cutoff, fs, order) #Tmxl_ECCO = st.butter_lowpass_filter_xr(Tmxl_ECCO, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) # Tmxl_var_ECCO = Tmxl_ECCO.var(dim='time') # sst_var_ECCO = sst_ECCO.var(dim='time') # Scale the SST tendency by the ratio of MXL temp tendency / SST tendency from ECCO (as an esimate for a more physical result) # Tmxlfrac = Tmxl_var_ECCO/sst_var_ECCO # sst = sst*np.sqrt(Tmxlfrac)
# Filter requirements. order = 5 fs = 1 # sample rate, (cycles per month) Tn = 4. * 12 cutoff = 1 / Tn # desired cutoff frequency of the filter (cycles per month) if not (lowpass): Tn = 0. # Butterworth low-pass filter if lowpass: #sst = xr.DataArray(st.butter_lowpass_filter(sst, cutoff, fs, order),dims=sst.dims,coords=sst.coords) #thf = xr.DataArray(st.butter_lowpass_filter(thf, cutoff, fs, order),dims=thf.dims,coords=thf.coords) #Q_net_surf = xr.DataArray(st.butter_lowpass_filter(Q_net_surf, cutoff, fs, order),dims=Q_net_surf.dims,coords=Q_net_surf.coords) sst = st.butter_lowpass_filter_xr(sst, cutoff, fs, order) thf = st.butter_lowpass_filter_xr(thf, cutoff, fs, order) Q_net_surf = st.butter_lowpass_filter_xr(Q_net_surf, cutoff, fs, order) #Q_ek = st.butter_lowpass_filter_xr(Q_ek, cutoff, fs, order) sst_ECCO = st.butter_lowpass_filter_xr(sst_ECCO, cutoff, fs, order) Tmxl_ECCO = st.butter_lowpass_filter_xr(Tmxl_ECCO, cutoff, fs, order) #Q_ek_f = st.butter_lowpass_filter_xr(Q_ek_f, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) # Mask zero values (continents) ocean_points1 = ~(sst == 0) ocean_points2 = ~(xr.ufuncs.isnan(sst)) ocean_points = xr.ufuncs.logical_or(ocean_points1, ocean_points2) sst = sst.where(ocean_points) thf = thf.where(ocean_points)
sst_raw = sst thf_raw = thf Q_net_surf_raw = Q_net_surf sst_ECCO_raw = sst_ECCO Tmxl_ECCO_raw = Tmxl_ECCO #Q_ek_raw = Q_ek for jj, Tn in enumerate(Tns): cutoff = 1 / Tn print('Tn', Tn) if Tn > 0: sst = st.butter_lowpass_filter_xr(sst_raw, cutoff, fs, order) thf = st.butter_lowpass_filter_xr(thf_raw, cutoff, fs, order) Q_net_surf = st.butter_lowpass_filter_xr(Q_net_surf_raw, cutoff, fs, order) err_sst = st.butter_lowpass_filter_xr(err_sst, cutoff, fs, order) err_thf = st.butter_lowpass_filter_xr(err_thf, cutoff, fs, order) sst_ECCO = st.butter_lowpass_filter_xr(sst_ECCO_raw, cutoff, fs, order) Tmxl_ECCO = st.butter_lowpass_filter_xr(Tmxl_ECCO_raw, cutoff, fs, order) #Q_ek = butter_lowpass_filter(Q_ek, cutoff, fs, order) #Q_g = butter_lowpass_filter(Q_g, cutoff, fs, order) Tmxl_var_ECCO = Tmxl_ECCO.var(dim='time') sst_var_ECCO = sst_ECCO.var(dim='time') # Scale the SST tendency by the ratio of MXL temp tendency / SST tendency from ECCO (as an esimate for a more physical result)