Package: ndradexhyperfine
ndRADEXPython package for RADEX grid calculationTL;DRndRADEX is a Python package which can runRADEX, non-LTE molecular radiative transfer code, with parameters of multiple values (i.e., RADEX with grid parameters).
The output will be multi-dimensional arrays, which may be useful for parameter search of physical conditions in comparison with observed values.FeaturesGrid calculation:ndRADEX has a simplerun()function, where all parameters of RADEX can be griddable (i.e., they can be list-like with length of more than one).Builtin RADEX:ndRADEX provides builtin RADEX binaries in the package, which are automatically downloaded and built during the package installation. This also enables us to do RADEX calculations in the cloud such asGoogle Colaboratory.Multiprocessing:ndRADEX supports multiprocessing RADEX run by default. At least twice speedup is expected compared to single processing.Handy I/O:The output of ndRADEX is axarray's Dataset, a standard multi-dimensional data structure as well aspandas. You can handle it in the same manner as NumPy and pandas (i.e., element-wise operation, save/load data, plotting, etc).RequirementsPython 3.6, 3.7, or 3.8 (tested by the author)gfortran (necessary to build RADEX)InstallationYou can install ndradexhyperfine with pip:$pipinstallndradexhyperfinePlease make sure that all requirements are met before the installation.UsagesWithin Python, import the package like:>>>importndradexhyperfineSingle RADEX runThe main funtion of ndRADEX isndradex.run().
For example, to get RADEX results of CO(1-0) with kinetic temperature of 100 K, CO column density of 1e15 cm^-2, and H2 density of 1e3 cm^-3:>>>ds=ndradexhyperfine.run('co.dat','1-0',100,1e15,1e3)where'co.dat'is a name ofLAMDAdatafile and'1-0'is a name of transition.
The available values are listed inList of available LAMDA datafiles and transitions.
Note that you don't need to any download datafiles:
ndRADEX automatically manage this.In this case, other parameters like line width, background temperature are default values defined in the function.
The geometry of escape probability is uniform ('uni') by default.
You can change these values with custom config (see customizations below).The output is axarray's Dataset with no dimension:>>>print(ds)<xarray.Dataset>Dimensions:()Coordinates:QN_ul<U3'1-0'T_kinint64100N_molfloat641e+15n_H2float641e+03T_bgfloat642.73dvfloat641.0geom<U3'uni'description<U9'LAMDA(CO)'Datavariables:E_ufloat645.5freqfloat64115.3wavelfloat642.601e+03T_exfloat64132.5taufloat640.009966T_rfloat641.278pop_ufloat640.4934pop_lfloat640.1715Ifloat641.36Ffloat642.684e-08You can access each result value like:>>>flux=ds['F'].valuesGrid RADEX runAs a natural extension, you can run grid RADEX calculation like:>>>ds=ndradexhyperfine.run('co.dat',['1-0','2-1'],T_kin=[100,200,300],N_mol=1e15,n_H2=[1e3,1e4,1e5,1e6,1e7])There are 13 parameters which can be griddable:QN_ul(transition name),T_kin(kinetic temperature),N_mol(column density),n_H2(H2 density),n_pH2(para-H2 density),n_oH2(ortho-H2 density),n_e(electron density),n_H(atomic hydrogen density),n_He(Helium density),n_Hp(ionized hydrogen density),T_bg(background temperature),dv(line width), andgeom(photon escape geometry).The output of this example is axarray's Dataset with three dimensions of (QN_ul,T_kin,n_H2):>>>print(ds)<xarray.Dataset>Dimensions:(QN_ul:2,T_kin:3,n_H2:5)Coordinates:*QN_ul(QN_ul)<U3'1-0''2-1'*T_kin(T_kin)int64100200300N_molfloat641e+15*n_H2(n_H2)float641e+031e+041e+051e+061e+07T_bgfloat642.73dvfloat641.0geom<U3'uni'description<U9'LAMDA(CO)'Datavariables:E_u(QN_ul,T_kin,n_H2)float645.55.55.55.5...16.616.616.6freq(QN_ul,T_kin,n_H2)float64115.3115.3115.3...230.5230.5wavel(QN_ul,T_kin,n_H2)float642.601e+032.601e+03...1.3e+03T_ex(QN_ul,T_kin,n_H2)float64132.5-86.52127.6...316.6301.6tau(QN_ul,T_kin,n_H2)float640.009966-0.005898...0.0009394T_r(QN_ul,T_kin,n_H2)float641.2780.5333...0.31210.2778pop_u(QN_ul,T_kin,n_H2)float640.49340.201...0.049720.04426pop_l(QN_ul,T_kin,n_H2)float640.17150.06286...0.030890.02755I(QN_ul,T_kin,n_H2)float641.360.5677...0.33220.2957F(QN_ul,T_kin,n_H2)float642.684e-081.12e-08...4.666e-08For more information, runhelp(ndradexhyperfine.run)to see the docstrings.Save/load resultsYou can save and load the dataset like:# save results to a netCDF file>>>ndradexhyperfine.save_dataset(ds,'results.nc')# load results from a netCDF file>>>ds=ndradexhyperfine.load_dataset('results.nc')CustomizationsFor the first time you import ndRADEX, the custom configuration file is created as~/.config/ndradex/config.toml.
By editing this, you can customize the following two settings of ndRADEX.
Note that you can change the path of configuration file by setting an environment variable,NDRADEX_PATH.Changing default valuesAs mentioned above, you can change the default values of therun()function like:# config.toml[grid]T_bg=10# change default background temp to 10 Kgeom="lvg"# change default geometry to LVGtimeout=30n_procs=2You can also change the number of multiprocesses (n_procs) and timeout (timeout) here.Setting datafile aliasesSometimes datafile names are not intuitive (for example, name of CS datafile iscs@lique.dat).
For convenience, you can define aliases of datafile names like:# config.toml[lamda]CS="cs@lique.dat"CO="~/your/local/co.dat"H13CN="https://home.strw.leidenuniv.nl/~moldata/datafiles/h13cn@xpol.dat"As shown in the second and third examples, you can also specify a local file path or a URL on the right hand.
After the customization, you can use these aliases in therun()function:>>>ds=ndradexhyperfine.run('CS','1-0',...)# equiv to cs@lique.datReferencesRADEXLAMDAxarraypandas