hr_calc_v2 = npl.hr_from_xi(xis2_unif, atm, cco2, all_coeffs = all_coeffs, atm_pt = atm_pt, allatms = allatms, n_alts = n_alts)
        # hr_ab_orig = npl.hr_atm_calc(atm, cco2)[:n_alts]

        hr_calc_var = np.zeros(n_alts)
        for ialt in range(n_alts):#range(n_alts_lte):
            xis_var = best_var[(cco2, ialt)]
            hr_calc_var[ialt] = npl.hr_from_xi_at_x0(xis_var, atm, cco2, ialt)

        tit = 'co2: {} - atm: {}'.format(cco2, atm)
        xlab = 'CR (K/day)'
        ylab = 'Alt (km)'
        # hrs = [hr_ref, hr_calc, hr_calc_v2, hr_calc_var]
        # labels = ['ref', 'fit unif 1', 'fit unif 2', 'fit var']
        hrs = [hr_ref, hr_calc_v2, hr_calc_var]
        labels = ['ref', 'fit unif', 'fit var']
        fig, a0, a1 = npl.manuel_plot(alts, hrs, labels, xlabel = xlab, ylabel = ylab, title = tit, xlimdiff = (-2., 2.))
        # fig = plt.figure()
        # plt.plot(hr_ref, alts, label = 'ref')
        # plt.plot(hr_calc, alts, label = 'calc')
        # plt.plot(hr_calc-hr_ref, alts, label = 'diff')
        # plt.legend()
        # plt.grid()
        # plt.title('co2: {} - atm: {}'.format(cco2, atm))
        figs.append(fig)
        a0s.append(a0)
        a1s.append(a1)

npl.adjust_ax_scale(a0s)
npl.adjust_ax_scale(a1s)
npl.plot_pdfpages(cart_out + 'check_newparam_LTE_unifit2_vs_varfit.pdf', figs)
Exemple #2
0
        for co2mult in mults:
            co2vmr = co2mult * atm_pt[(atm, 2, 'co2')]
            int_fun = interp_coeffs[(nam, 'int_fun')]
            sc = interp_coeffs[(nam, 'signc')]
            if int_fun.ndim == 1:
                interplog = int_fun[ialt](co2vmr[ialt])
            else:
                interplog = np.array(
                    [intfu(co2vmr[ialt]) for intfu in int_fun[..., ialt]])
            print(co2mult, interplog)
            coefff.append(interplog)

        coefff = np.stack(coefff)
        colors = npl.color_set(n_alts_trlo)

        fig, ax = plt.subplots()
        ax.grid()
        for j, col in zip(range(n_alts_trlo), colors):
            ax.plot(mults, coefff[:, j], color=col, linewidth=0.5)
            #plt.scatter(coeffs['co2profs'][:, ialt]/coeffs['co2profs'][1, ialt], -np.log(coeffs[nam][:, j, ialt]/coeffs['co2profs'][:, ialt]))
        ax.set_title(nam + '[:, {}]'.format(ialt))
        ax.set_xlabel('x CO2')

        figs.append(fig)
        axes.append(ax)

    npl.adjust_ax_scale(axes)
    npl.plot_pdfpages(cart_out_4 + 'check_{}_all.pdf'.format(nam), figs)

###### Check. correlazione fra acoeff e cose
Exemple #3
0
                                     figsize=(24, 8))
        plt.suptitle('a and b coeff weights - version {}'.format(vers))

        a0.imshow(xis_a_alts, norm=LogNorm(vmin=0.1, vmax=10))
        a1.imshow(xis_b_alts, norm=LogNorm(vmin=0.1, vmax=10))
        a0.set_title('afit')
        a1.set_title('bfit')

        # a0.axhline(52, color = 'grey', linewidth = 0.5)
        # a1.axhline(52, color = 'grey', linewidth = 0.5)
        a0.axvline(40, color='grey', linewidth=0.5)
        a1.axvline(40, color='grey', linewidth=0.5)

        figsall.append(fig)

    npl.plot_pdfpages(cart_out_2 + 'allxis_cco2{}.pdf'.format(cco2), figsall)

sys.exit()
################### CHECK ACOEFF BCOEFF

absval = False
levels = [
    -10000, -1000, -100, -10, -1, -0.1, -0.01, 0., 0.01, 1, 10, 100, 1000,
    10000
]
levels2 = [-100, -10, -1, -0.1, -0.01, 0., 0.01, 1, 10, 100]

cmap = plt.get_cmap('RdBu_r')
norm = BoundaryNorm(levels, ncolors=cmap.N, clip=True)
norm2 = BoundaryNorm(levels2, ncolors=cmap.N, clip=True)
Exemple #4
0
            ylabel=ylab,
            title=tit,
            xlimdiff=(-15, 15),
            xlim=(-70, 10),
            linestyles=['-', '--', '-', '--', '-', ':', ':'],
            colors=colors,
            orizlines=[70., alts[n_alts_trlo], alts[n_alts_trhi]])

        figs.append(fig)
        a0s.append(a0)
        a1s.append(a1)

        npl.adjust_ax_scale(a0s)
        npl.adjust_ax_scale(a1s)

npl.plot_pdfpages(cart_out_3 + 'check_uppertrans_all_checkLfomi.pdf', figs)

figs = []
a0s = []
a1s = []
for cco2 in range(1, 8):
    tip = 'varfit5_nlte'
    acoeff_cco2 = tot_coeff_co2[(tip, 'acoeff', cco2)]
    bcoeff_cco2 = tot_coeff_co2[(tip, 'bcoeff', cco2)]
    asurf_cco2 = tot_coeff_co2[(tip, 'asurf', cco2)]
    bsurf_cco2 = tot_coeff_co2[(tip, 'bsurf', cco2)]

    for atm in allatms:
        temp = atm_pt[(atm, 'temp')]
        surf_temp = atm_pt[(atm, 'surf_temp')]
        hr_calc = npl.hr_from_ab(acoeff_cco2, bcoeff_cco2, asurf_cco2,
Exemple #5
0
                                      hrs,
                                      labels,
                                      xlabel=xlab,
                                      ylabel=ylab,
                                      title=tit,
                                      xlimdiff=(-2.5, 2.5))

        figs2.append(fig)
        a0s.append(a0)
        a1s.append(a1)

npl.adjust_ax_scale(a0s)
npl.adjust_ax_scale(a1s)
# npl.plot_pdfpages(cart_out + 'check_newparam_LTE_final_newvsold.pdf', figs)

npl.plot_pdfpages(
    cart_out + 'check_newparam_LTE_final_LEASTSQUARES_v3_abfit.pdf', figs2)

for cos in ['std', 'max']:
    if cos == 'std':
        print('Average stddev of param in region.\n')
    else:
        print('Max absolute error of param in region.\n')

    for sco in ['lte', 'lte+trans']:
        print('---------------- \n')
        print(sco + ' region \n')
        allsco = []
        for tip in alltips:
            if cos == 'std':
                allsco.append(np.nanmean(fit_score[(tip, sco, cos)]))
                print('{} {}: {:6.3f} K'.format(tip, sco, allsco[-1]))
            ylabel=ylab,
            title=tit,
            xlimdiff=(-15, 15),
            xlim=(-70, 10),
            linestyles=['-', '--', '--'],
            colors=colors,
            orizlines=[70., alts[n_alts_trlo], alts[n_alts_trhi]])

        figs.append(fig)
        a0s.append(a0)
        a1s.append(a1)

        npl.adjust_ax_scale(a0s)
        npl.adjust_ax_scale(a1s)

npl.plot_pdfpages(cart_out_4 + 'check_allrefs_newparam.pdf', figs)

# Check con atm nuova?
figs = []
a0s = []
for atm in allatms:
    temp = atm_pt[(atm, 'temp')]
    surf_temp = atm_pt[(atm, 'surf_temp')]
    pres = atm_pt[(atm, 'pres')]

    ovmr = all_coeffs_nlte[(atm, 2, 'o_vmr')]
    o2vmr = all_coeffs_nlte[(atm, 2, 'o2_vmr')]
    n2vmr = all_coeffs_nlte[(atm, 2, 'n2_vmr')]

    new_cr = []
    old_cr = []
Exemple #7
0
        if ialt > 1 and ialt < n_alts - 1:
            if np.abs(coeff[ialt, ialt]) / np.abs(
                    np.mean([
                        coeff[ialt - 1, ialt - 1], coeff[ialt + 1, ialt + 1]
                    ])) > 1.5:
                print('Atm {}. Unstable ialt {}'.format(atm, ialt))
                plt.plot(np.mean([
                    coeff[:n_alts, ialt - 1][:-2], coeff[:n_alts, ialt + 1][2:]
                ],
                                 axis=0),
                         alts[1:-1],
                         color=col,
                         linestyle='--')
        plt.title('acoeff - ' + atm)
    figs.append(fig)
npl.plot_pdfpages(cartou + 'acoeff_atmvar.pdf', figs)

figs = []
for atm in allatms:
    fig = plt.figure()
    coeff = all_coeffs_nlte[(atm, cco2, 'bcoeff')]
    for ialt, col in zip(range(n_alts), npl.color_set(n_alts)):
        plt.plot(coeff[:n_alts, ialt], alts, color=col)
        if ialt > 1 and ialt < n_alts - 1:
            if np.abs(coeff[ialt, ialt]) / np.abs(
                    np.mean([
                        coeff[ialt - 1, ialt - 1], coeff[ialt + 1, ialt + 1]
                    ])) > 1.5:
                print('Atm {}. Unstable ialt {}'.format(atm, ialt))
                plt.plot(np.mean([
                    coeff[:n_alts, ialt - 1][:-2], coeff[:n_alts, ialt + 1][2:]
        labels = ['ref', 'veof', 'veof2', 'vf5']
        hrs = [hr_ref, hr_new, hr_new_v2, hr_vf5]
        tit = 'co2: {} - atm: {}'.format(cco2, atm)
        xlab = 'CR (K/day)'
        ylab = 'index'
        #labels = ['ref'] + alltips + ['fomi rescale (no fit)', 'old param']
        fig, a0, a1 = npl.manuel_plot(np.arange(66),
                                      hrs,
                                      labels,
                                      xlabel=xlab,
                                      ylabel=ylab,
                                      title=tit,
                                      xlimdiff=(-2, 2),
                                      xlim=(-40, 10),
                                      ylim=(10, 90),
                                      linestyles=['-', '--', '--', ':'],
                                      colors=colors)

        figs.append(fig)
        a0s.append(a0)
        a1s.append(a1)

    ax2.set_title(str(cco2))
    figs2.append(fig2)

    npl.adjust_ax_scale(a0s)
    npl.adjust_ax_scale(a1s)

npl.plot_pdfpages(cart_out_rep + 'check_reparam_NLTE_low.pdf', figs)
npl.plot_pdfpages(cart_out_rep + 'check_reparam_NLTEcorrection.pdf', figs2)
            fig, a0, a1 = npl.manuel_plot(alts,
                                          hrs,
                                          labels,
                                          xlabel=xlab,
                                          ylabel=ylab,
                                          title=tit,
                                          xlimdiff=(-2.5, 2.5))

            figs.append(fig)
            a0s.append(a0)
            a1s.append(a1)

    npl.adjust_ax_scale(a0s)
    npl.adjust_ax_scale(a1s)
    npl.plot_pdfpages(
        cart_out + 'check_newparam_LTE_final_{}_correcto.pdf'.format(tip),
        figs)

#pickle.dump(interp_coeffs, open(cart_out + 'interp_coeffs_v1_LTE.p', 'w'))

for tip in ['unifit', 'varfit']:
    var_cosi = np.linspace(0., 1., 20)
    co2profs = [
        atm_pt[('mle', 1, 'co2')] * (1 - cos) + atm_pt[('mle', 6, 'co2')] * cos
        for cos in var_cosi
    ]
    colors = npl.color_set(20)

    ###########################################################################
    figs = []
    axes = []
Exemple #10
0
                                max_alts=51)
        #hr_vf5 = np.concatenate([hr_vf5, np.nan*np.ones(15)])

        hr_ref = all_coeffs[(atm, cco2, 'hr_ref')]

        labels = ['ref', 'veof', 'veof2', 'vf5']
        hrs = [hr_ref, hr_new, hr_new_v2, hr_vf5]
        tit = 'co2: {} - atm: {}'.format(cco2, atm)
        xlab = 'CR (K/day)'
        ylab = 'index'
        #labels = ['ref'] + alltips + ['fomi rescale (no fit)', 'old param']
        fig, a0, a1 = npl.manuel_plot(np.arange(66),
                                      hrs,
                                      labels,
                                      xlabel=xlab,
                                      ylabel=ylab,
                                      title=tit,
                                      xlimdiff=(-2, 2),
                                      xlim=(-40, 10),
                                      ylim=(10, 90),
                                      linestyles=['-', '--', '--', ':'],
                                      colors=colors)

        figs.append(fig)
        a0s.append(a0)
        a1s.append(a1)

    npl.adjust_ax_scale(a0s)
    npl.adjust_ax_scale(a1s)
    npl.plot_pdfpages(cart_out_rep + 'check_reparam_LTE.pdf', figs)
                                      ylabel=ylab,
                                      title=tit,
                                      xlimdiff=(-3, 3),
                                      xlim=(-40, 10),
                                      ylim=(40, 90),
                                      linestyles=['-', '-', '-', ':', ':'])

        figs2.append(fig)
        a0s.append(a0)
        a1s.append(a1)

npl.adjust_ax_scale(a0s)
npl.adjust_ax_scale(a1s)
# npl.plot_pdfpages(cart_out + 'check_newparam_LTE_final_newvsold.pdf', figs)

npl.plot_pdfpages(cart_out_2 + 'check_newparam_NLTE_lowtrans.pdf', figs2)

alltips.append('fomi')

for cos in ['std', 'max']:
    if cos == 'std':
        print('Average stddev of param in region.\n')
    else:
        print('Max absolute error of param in region.\n')

    for sco in ['trans', 'lte+trans']:
        print('---------------- \n')
        print(sco + ' region \n')
        allsco = []
        for tip in alltips:
            if cos == 'std':