Changeset 3633 for trunk


Ignore:
Timestamp:
Feb 19, 2025, 2:27:45 PM (4 months ago)
Author:
afalco
Message:

exo_k: updated scripts for better info and removed useless binning.
AF

Location:
trunk/UTIL/corrk_exo_k
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/corrk_exo_k/bin_corrk.py

    r3605 r3633  
    77R=100
    88wnedges=xk.wavenumber_grid_R(10000/100, 10000/.3, R)
    9 print("wnedges range: ", wnedges.min(), wnedges.max())
     9print("Spectral resolution asked: wn=", wnedges.min(), wnedges.max(), ", R =", R)
    1010
    1111### folder where corrk will be saved
     
    6666
    6767        tmp_ktab=xk.Ktable(mol=mol, remove_zeros=True)
     68        print(f"Initial spectral resolution = {tmp_ktab.Nw}")
    6869
    69         if logpgrid is None: # use first molecule to set p and t grid
     70        if logpgrid is None or tgrid is None: # use first molecule to set p and t grid
    7071            logpgrid = tmp_ktab.logpgrid
    7172            tgrid = tmp_ktab.tgrid
    7273
    73         print(f"Remapping: {mol}")
    74         tmp_ktab.remap_logPT(logp_array=logpgrid, t_array=tgrid)
    7574        print(f"Binning: {mol}")
    7675        tmp_ktab.bin_down(wnedges)
     76
     77        if (tmp_ktab.logpgrid != logpgrid).any() or (tmp_ktab.tgrid != tgrid).any():
     78            print("Initial P grid:", tmp_ktab.pgrid)
     79            print("Initial T grid:", tmp_ktab.tgrid)
     80            print(f"Remapping {mol}")
     81            print("New P grid:", np.power(logpgrid,10))
     82            print("New T grid:", tgrid)
     83            tmp_ktab.remap_logPT(logp_array=logpgrid, t_array=tgrid)
     84
     85        print(tmp_ktab)
    7786        print(f"Writing: {mol}")
    7887        tmp_ktab.write_hdf5(dir_out+mol+f"_R{R}.corrk.h5")
  • trunk/UTIL/corrk_exo_k/dace_to_corrk.py

    r3605 r3633  
    77
    88### choose spectral resolution for corrk
    9 R=500
     9R=20000
    1010wnedges=xk.wavenumber_grid_R(10000/100, 10000/.3, R)
    11 print(wnedges.min(), wnedges.max())
     11print("Spectral resolution asked: wn=", wnedges.min(), wnedges.max(), ", R =", R)
    1212
    1313### set data paths
     
    1515corrk_dir = "datadir/corrk_data/"
    1616dir_out = corrk_dir+f"/R{R}_from_dace/"
    17 ref=xk.Ktable(filename=corrk_dir + '/R500_from_R15000/CH4_R500.corrk.h5', mol="CH4")
     17
     18### you can set your desired p and t grid here (otherwise, first molecule is used)
     19logpgrid = None
     20tgrid = None
     21# ref=xk.Ktable(filename=corrk_dir + '/R500_from_R15000/CH4_R500.corrk.h5', mol="CH4")
     22# logpgrid = ref.logpgrid
     23# tgrid = ref.tgrid
     24
     25
    1826
    1927### select (output) molecules and their corresponding (input) isotopologues
    2028molecules = {
    21     "CO":  "12C-16O",
    22     "C2H2":"12C2-1H2",
    23     "C2H4":"12C2-1H4",
     29    # "CO":  "12C-16O",
     30    # "CO2":  "12C-16O2",
     31    # "H2O":  "1H2-16O",
     32    # # "C2H2":"12C2-1H2",
     33    # # "C2H4":"12C2-1H4",
    2434    "CH4": "12C-1H4",
     35    # "TiO": "48Ti-16O",
     36    # "VO": "51V-16O",
    2537}
    2638
    27 xk.Settings().set_mks(True)
     39# xk.Settings().set_mks(True)
    2840xk.Settings().set_log_interp(False)
    2941xk.Settings().set_case_sensitive(True)
    3042
    31 def dace_to_corrk(molecule=None, isotopologue=None, order=17):
     43def dace_to_corrk(molecule=None, isotopologue=None, order=17, logpgrid=logpgrid, tgrid=tgrid):
    3244    if molecule is None:
    3345        molecule=isotopologue_to_species(isotopologue)
     
    4355        return
    4456
    45     tmp=xk.hires_to_ktable(path=mol_corrk, helios=True, wnedges=wnedges, mol=molecule, order=order) # test conversion from a whole folder to tmp
     57    print(f"Reading: {mol}")
     58    hr = xk.Hires_spectrum(glob.glob(mol_corrk+"/*.bin")[0], helios=True)
     59    print(f"Initial spectral resolution = {hr.Nw}")
    4660
    47     tmp.kdata = tmp.kdata * 10 * xk.Molar_mass().fetch(molecule) / xk.N_A
     61    tmp_ktab=xk.hires_to_ktable(path=mol_corrk, helios=True, wnedges=wnedges, mol=molecule, order=order) # test conversion from a whole folder to tmp
     62
     63    tmp_ktab.kdata = tmp_ktab.kdata * 10 * xk.Molar_mass().fetch(molecule) / xk.N_A
    4864    # cm^2/g * 10000/1000 * kg/mol / (molecule/mol) -> m^2/molecule
    49     tmp.kdata_unit = "m^2/molecule"
    50     tmp.remap_logPT(ref.logpgrid, ref.tgrid)
    51     tmp.remove_zeros()
     65    tmp_ktab.kdata_unit = "m^2/molecule"
     66    tmp_ktab.remove_zeros()
    5267
    53     print(tmp)
    54     tmp.write_hdf5(dir_out+f"{molecule}_corrk_dace_{R}.h5")
     68
     69    if logpgrid is None or tgrid is None: # use first molecule to set p and t grid
     70            logpgrid = tmp_ktab.logpgrid
     71            tgrid = tmp_ktab.tgrid
     72
     73    if (tmp_ktab.logpgrid != logpgrid).any() or (tmp_ktab.tgrid != tgrid).any():
     74        print("Initial P grid:", tmp_ktab.pgrid)
     75        print("Initial T grid:", tmp_ktab.tgrid)
     76        print(f"Remapping {mol}")
     77        print("New P grid:", np.power(logpgrid,10))
     78        print("New T grid:", tgrid)
     79        tmp_ktab.remap_logPT(logp_array=logpgrid, t_array=tgrid)
     80
     81    print(tmp_ktab)
     82    print(f"Writing: {mol}")
     83    tmp_ktab.write_hdf5(dir_out+f"{molecule}_corrk_dace_{R}.h5")
    5584
    5685    # %matplotlib notebook
     
    5887    t_plot=300
    5988    fig,ax=plt.subplots(figsize=(9,6.5))
    60     tmp.plot_spectrum(ax,p=p_plot,t=t_plot,g=1.,yscale='log',xscale='log',label='g=1')
     89    tmp_ktab.plot_spectrum(ax,p=p_plot,t=t_plot,g=1.,yscale='log',xscale='log',label='g=1')
    6190    fig.tight_layout()
    6291    plt.savefig(dir_out+f"corrk_dace_R{R}_{molecule}_p{p_plot}_t{t_plot}.pdf")
  • trunk/UTIL/corrk_exo_k/lmdz_corrk_using_exo_k.py

    r3632 r3633  
    44### folder with corrk data for each molecule (see 'xsec_to_corrk.py' to convert cross-sections to correlated-k tables)
    55xk.Settings().set_search_path("datadir/exomol/taurex_R15000/")
     6# xk.Settings().set_search_path("datadir/corrk_data/R20000_from_dace/")
    67
    78corrk_dir = "datadir/corrk_data/"
  • trunk/UTIL/corrk_exo_k/xsec_to_corrk.py

    r3605 r3633  
    77R=500
    88wnedges=xk.wavenumber_grid_R(10000/100, 10000/.3, R)
    9 print("wnedges range: ", wnedges.min(), wnedges.max())
     9print("Spectral resolution asked: wn=", wnedges.min(), wnedges.max(), ", R =", R)
    1010
    1111### folder where corrk will be saved
     
    6363            print(f"Reading: {mol}")
    6464
    65         tmp_ktab=xk.Ktable(wnedges=wnedges, xtable=xk.Xtable(pattern, mol=mol, remove_zeros=True))
     65        xtable=xk.Xtable(pattern, mol=mol, remove_zeros=True)
     66        print(f"Initial spectral resolution = {xtable.Nw}")
    6667
    67         if logpgrid is None: # use first molecule to set p and t grid
     68        tmp_ktab=xk.Ktable(wnedges=wnedges, xtable=xtable)
     69
     70        # print(f"Binning: {mol}")
     71        # tmp_ktab.bin_down(wnedges)
     72
     73
     74        if logpgrid is None or tgrid is None: # use first molecule to set p and t grid
    6875            logpgrid = tmp_ktab.logpgrid
    6976            tgrid = tmp_ktab.tgrid
    7077
    71         print(f"Remapping: {mol}")
    72         tmp_ktab.remap_logPT(logp_array=logpgrid, t_array=tgrid)
     78        if (tmp_ktab.logpgrid != logpgrid).any() or (tmp_ktab.tgrid != tgrid).any():
     79            print("Initial P grid:", tmp_ktab.pgrid)
     80            print("Initial T grid:", tmp_ktab.tgrid)
     81            print(f"Remapping {mol}")
     82            print("New P grid:", np.power(logpgrid,10))
     83            print("New T grid:", tgrid)
     84            tmp_ktab.remap_logPT(logp_array=logpgrid, t_array=tgrid)
     85
     86        print(tmp_ktab)
    7387        print(f"Writing: {mol}")
    7488        tmp_ktab.write_hdf5(dir_out+mol+f"_R{R}.corrk.h5")
Note: See TracChangeset for help on using the changeset viewer.