Exemplo n.º 1
0
def __sample_read_files():
    vlim_raw = [-0.05, 0.1]
    vlim_diff = [None, None]
    nature_file = 'x_nature.pkl'
    nature = state_vector()
    nature = nature.load(nature_file)
    freerun_file = 'x_freerun.pkl'
    freerun = state_vector()
    freerun = freerun.load(freerun_file)
    sp.run("mkdir -p img", shell=True, check=True)
    plot_time_colormap(freerun.getTrajectory() - nature.getTrajectory(),
                       "img/error_free_run.png", *vlim_diff, "error free run")
    plot_time_colormap(freerun.getTrajectory(), "img/freerun.png", *vlim_raw,
                       "freerun", "viridis")
    plot_time_colormap(nature.getTrajectory(), "img/nature.png", *vlim_raw,
                       "nature", "viridis")
    for method in ["ETKF"]:
        analysis_file = 'x_analysis_{method}.pkl'.format(method=method)
        das = da_system()
        das = das.load(analysis_file)
        analysis = das.getStateVector()
        plot_time_colormap(analysis.getTrajectory() - nature.getTrajectory(),
                           "img/error_analysis_%s.png" % method, *vlim_diff,
                           "error analysis %s" % method)
        plot_time_colormap(analysis.getTrajectory(),
                           "img/analysis_%s.png" % method, *vlim_raw,
                           "analysis %s" % method, "viridis")
Exemplo n.º 2
0
def __sample_read_files():
    vlim_raw = [-0.05, 0.1]
    vlim_diff = [-0.15, 0.15]
    nature_file = 'x_nature.pkl'
    nature = state_vector()
    nature = nature.load(nature_file)
    freerun_file = 'x_freerun.pkl'
    freerun = state_vector()
    freerun = freerun.load(freerun_file)
    plot_time_colormap(freerun.getTrajectory() - nature.getTrajectory(),
                       "img/error_free_run.pdf", *vlim_diff, "error free run",
                       "RdBu_r", True)
    plot_time_colormap(freerun.getTrajectory(), "img/freerun.pdf", *vlim_raw,
                       "freerun", "viridis")
    plot_time_colormap(nature.getTrajectory(), "img/nature.pdf", *vlim_raw,
                       "nature", "viridis")
    for method in ["ETKF", "hybrid", "3DVar"]:
        analysis_file = 'x_analysis_{method}.pkl'.format(method=method)
        das = da_system()
        das = das.load(analysis_file)
        analysis = das.getStateVector()
        plot_time_colormap(analysis.getTrajectory() - nature.getTrajectory(),
                           "img/%s/error_analysis.pdf" % method, *vlim_diff,
                           "error analysis %s" % method, "RdBu_r", True)
        plot_time_colormap(analysis.getTrajectory(),
                           "img/%s/analysis.pdf" % method, *vlim_raw,
                           "analysis %s" % method, "viridis")
Exemplo n.º 3
0
def main():
    nature_file = 'x_nature.pkl'
    nature = state_vector()
    nature = nature.load(nature_file)
    freerun_file = 'x_freerun.pkl'
    freerun = state_vector()
    freerun = freerun.load(freerun_file)
    method = argv[1]
    analysis_file = 'x_analysis_{method}.pkl'.format(method=method)
    das = da_system()
    das = das.load(analysis_file)
    analysis = das.getStateVector()
    plot_rmse_all(nature, freerun, analysis, method, np.s_[:, :],
                  "img/%s/rmse_all.pdf" % method)
    plot_rmse_all(nature, freerun, analysis, method, np.s_[:, 0:10],
                  "img/%s/rmse_atmos_psi.pdf" % method)
    plot_rmse_all(nature, freerun, analysis, method, np.s_[:, 10:20],
                  "img/%s/rmse_atmos_temp.pdf" % method)
    plot_rmse_all(nature, freerun, analysis, method, np.s_[:, 20:28],
                  "img/%s/rmse_ocean_psi.pdf" % method)
    plot_rmse_all(nature, freerun, analysis, method, np.s_[:, 28:36],
                  "img/%s/rmse_ocean_temp.pdf" % method)
from class_obs_data import obs_data
from class_da_system import da_system

#-----------------------------------------------------------------------
# Exercises:
# (1) Compute the Lyapunov exponents of the nature system
# (2) Compute the forward and backward Lyapunov vectors
# (3) Compute the Covariant Lyapunov Vectors
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
# Read the L63 nature run
#-----------------------------------------------------------------------
name = 'x_nature'
infile = name + '.pkl'
sv = state_vector()
sv = sv.load(infile)
x_nature = sv.getTrajectory()
t_nature = sv.getTimes()
maxit, xdim = np.shape(x_nature)
sigma, rho, beta = sv.params

#------------------------------------------------------------------
# Initialize the l63 object
#------------------------------------------------------------------
l63 = lorenz63(sigma=sigma, rho=rho, beta=beta)

#------------------------------------------------------------------
# Input a nature run and compute its corresponding Jacobian
#------------------------------------------------------------------
print('Compute approximate Tangent Linear Model (TLM) at each timestep...')
Exemplo n.º 5
0
from class_lorenz63 import lorenz63
from class_state_vector import state_vector
from class_obs_data import obs_data
import numpy as np

#------------------------------------------------------------------
# Read state vector objects
#------------------------------------------------------------------
infile1 = 'x_nature.pkl'
sv1 = state_vector()
sv1 = sv1.load(infile1)
print(sv1)

infile2 = 'x_freerun.pkl'
sv2 = state_vector()
sv2 = sv2.load(infile2)
print(sv2)

#------------------------------------------------------------------
# Plot the result
#------------------------------------------------------------------
error = np.abs(sv2.getTrajectory() - sv1.getTrajectory())
times = sv1.getTimes()
l63 = lorenz63()
title = 'Sensitive dependence on initial conditions with Lorenz-63'
l63.plot_lines_and_lines(states1=sv1.getTrajectory(),
                         states2=sv2.getTrajectory(),
                         cvec=times,
                         name1=sv1.name,
                         name2=sv2.name,
                         plot_title=title)
#[2.37742045 2.26356092 2.45364065 2.31241994 2.02554909]
#Climatological Standard Deviation:
#[3.63477096 3.63919927 3.30788215 3.76514026 3.62503822]

#name = 'x_freerun'
#initial_perturbation = np.squeeze(0.01*(np.random.rand(1,3)*2-1))
#print('initial_perturbation = ', initial_perturbation)
#climate_std =  [3.63477096 3.63919927 3.30788215 3.76514026 3.62503822]
#print('climate_std = ', climate_std)
#state0 = state0 + initial_perturbation*climate_std
#print('initial state = ', state0)

#------------------------------------------------------------------
# Setup state vector object
#------------------------------------------------------------------
sv = state_vector(params=params,params_cpl= params_cpl,x0=state0,t=tvec,name=name)

#------------------------------------------------------------------
# Initialize the l96 object
#------------------------------------------------------------------
lpk = lorenzlpk(params=params, params_cpl= params_cpl,F=F)

#------------------------------------------------------------------
# Run L96 to generate a nature run with the specified parameters
#------------------------------------------------------------------
print('Run lorenz pena and Kalnay model...')
trajectory = lpk.run(sv.x0,sv.t)
sv.setTrajectory(trajectory)

#------------------------------------------------------------------
# Output the beginning and end states, and compute model climatology
Exemplo n.º 7
0
#[2.37742045 2.26356092 2.45364065 2.31241994 2.02554909]
#Climatological Standard Deviation:
#[3.63477096 3.63919927 3.30788215 3.76514026 3.62503822]

#name = 'x_freerun'
#initial_perturbation = np.squeeze(0.01*(np.random.rand(1,3)*2-1))
#print('initial_perturbation = ', initial_perturbation)
#climate_std =  [3.63477096 3.63919927 3.30788215 3.76514026 3.62503822]
#print('climate_std = ', climate_std)
#state0 = state0 + initial_perturbation*climate_std
#print('initial state = ', state0)

#------------------------------------------------------------------
# Setup state vector object
#------------------------------------------------------------------
sv = state_vector(params=params, x0=state0, t=tvec, name=name)

#------------------------------------------------------------------
# Initialize the l96 object
#------------------------------------------------------------------
l96 = lorenz96(F=F)

#------------------------------------------------------------------
# Run L96 to generate a nature run with the specified parameters
#------------------------------------------------------------------
print('Run l96...')
trajectory = l96.run(sv.x0, sv.t)
sv.setTrajectory(trajectory)

#------------------------------------------------------------------
# Output the beginning and end states, and compute model climatology
Exemplo n.º 8
0
from class_obs_data import obs_data
from class_da_system import da_system
from sys import argv
from copy import deepcopy

#-----------------------------------------------------------------------
# Usage:
#  python generate_analysis_LEs.py <method>
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
# Read the L96 nature run
#-----------------------------------------------------------------------
name1 = 'x_nature'
infile1 = name1 + '_Mhist.pkl'
sv1 = state_vector()
sv1 = sv1.load(infile1)
x_nature = sv1.getTrajectory()
t_nature = sv1.getTimes()

#-----------------------------------------------------------------------
# Read the analysis
#-----------------------------------------------------------------------
name = 'x_analysis'
method = argv[1]
infile2 = name + '_' + method + '.pkl'
das = da_system()
das = das.load(infile2)
sv = das.getStateVector()
KH, khidx = das.getKH()
print(sv)
Exemplo n.º 9
0
from class_state_vector import state_vector
from class_da_system import da_system
import numpy as np
from sys import argv
import matplotlib.pyplot as plt

nature_file ='x_nature.pkl'
nature = state_vector()
nature = nature.load(nature_file)

freerun_file = 'x_freerun.pkl'
freerun = state_vector()
freerun = freerun.load(freerun_file)

method = argv[1]
analysis_file = 'x_analysis_{method}.pkl'.format(method=method)
das = da_system()
das = das.load(analysis_file)
analysis = das.getStateVector()

plt.plot(nature.getTimes(),
         np.linalg.norm(freerun.getTrajectory() - nature.getTrajectory(),
                        axis=1), label='Free run')
plt.plot(nature.getTimes(),
         np.linalg.norm(analysis.getTrajectory() - nature.getTrajectory(),
                        axis=1), label='Analysis ({method})'.format(method=method))
plt.legend()
plt.xlabel('Time')
plt.ylabel('Error', rotation='horizontal', labelpad=20)
plt.tight_layout()
plt.show()