pyspecair

The Python interface to SPECAIR

Getting Started

Install

Specair installation is automatic if you have a Ubuntu 18.x 64 bits machine, Git, and a SSH key with authorized access to the Gitlab.com repository :

  • If you don’t have git, run sudo apt-get install git

  • If you don’t have access to the Gitlab.com repository , please contact one of the Specair administrators.

  • If you don’t have a valid SSH key, please follow the steps on Gitlab.

Start where you want to install Specair (for instance: cd ~), and run:

git clone git@gitlab.com:spectralfit/specair.git
cd specair
source install.sh

That’s it! This will install Python with the Anaconda distribution (if you don’t have it already), HDF5 (if you don’t have it already), JSON-FORTRAN, SPECAIR-FORTRAN, then PySpecair. Installation time is about 15 min and requires no user input. You’ll be welcomed with an Argon spectrum at the end.

Argon Spectrum 7200 K

If you ever encounter any problem please follow the Manual installation steps. Specair can also be installed on older Ubuntu systems (14.x, 16.x), 32 bits systems, and on Mac OS. In that case, please refer to the Manual installation below:

Whenever you’ll want to update Specair, just pull the latest version and run the install again. It will be much faster. You can also discard the Anaconda update part with option -a and the test plot with -t (it’s still recommended to update Anaconda time to time):

cd specair
git pull
./install.sh -at

Quick start

pyspecair has three front-end functions:

  1. one_slab() is recommended for simple cases

  2. run_specair() for more complex cases (fine control of slabs and computational parameters)

  3. large_spectrum() is the same as run_specair() but over large spectral domain. In other words large_spectrum() = run_specair() + parallel computing.

  • one_slab(): runs simulation over a single slab, thus similar to Specair Windows GUI:

    from pyspecair import one_slab
    s = one_slab(wavelength_min=350,    # nm
                 wavelength_max=380,    # nm
                 Tgas=7200,             # K
                 pressure=1,            # bar
                 path_length=1,         # cm
                 mole_fractions={'Ar':1},
                 self_absorption=True)
    s.apply_slit(0.5)   # nm
    s.plot()
    

    Output is a RADIS Spectrum object, to which can be applied all the post-processing methods described in RADIS How to … ?, such as rescale_path_length(), rescale_mole_fraction(), apply_slit() or store(). RADIS then allows the combination of Spectrum objects along the line-of-sight with the following syntax:

    s_line_of_sight = s_plasma > s_room_absorption
    

    In a way, this repoduces the multi-slab feature of run_specair().

  • run_specair(): Output is a Python dictionary, unless you specify "output='spectrum'" to get a RADIS Spectrum object

    from pyspecair.specair import run_specair
    from pyspecair.slabs import slab
    
    import matplotlib.pyplot as mplt
    from six.moves import range
    
    # start by building up a generic cfg dictionary
    number_of_slabs = 3
    cfg = {
           'wavels': 1000.0,  # lower wavelength (Angstrom)
           'wavell': 8000.0,  # upper wavelength (Angstrom)
           # etc.
           }
    

    See default configuration values in cfg_defaults

       # now we have an atomic radiation dictionary,
       # where each species is specified as a list of strings
       # for what we want radiating. to not use a species, make
       # the list empty or just don't include it
    
       atomic_radiation = {}
    
       atomic_radiation['N'] = ['Bound-Bound', 'Bound-Free', 'Free-Free']
       atomic_radiation['O'] = ['Bound-Bound', 'Bound-Free', 'Free-Free']
       atomic_radiation['C'] = ['Bound-Bound', 'Bound-Free', 'Free-Free']
    
       cfg['atomic_radiation'] = atomic_radiation
    
       # molecular radiation is specified slightly differently,
       # if you want to use a molecular radiation system, just specify
       # it in the molecular radiation dictionary.
       # You can set it to True, 1, or any number
       # Don't include a system or set it to False or None to not use it
    
       molecular_radiation = {}
       molecular_radiation['N2Plus_FirstNegative'] = True
       molecular_radiation['N2_FirstPositive'] = True
       molecular_radiation['N2_SecondPositive'] = True
       molecular_radiation['N2_Birge-Hopfield_2'] = True
       # etc...
       molecular_radiation['N2_Worley_o3-X'] = True
       molecular_radiation['N2_ePrime-X'] = True
    
       cfg['molecular_radiation'] = molecular_radiation
    
       # gas_inp object
    
       list_of_slabs = [slab(slab_number=i,
                             x_0=i,
                             x_end=(i + 1) * 0.1,
                             input_fractions_dict={'N2': 1.0,'e-':1e-3},
                             equilibrium_moles_fractions=False,
                             gas_input_type='moles',
                             gas_set='pT',
                             T=7200.0, Tvib=7200.0, Trot=7200.0, Tel=7200.0,
                             rho=None,
                             p=1.0e5,
                             version='igloo') for i in range(0, number_of_slabs)]
       cfg['gas_inp'] = list_of_slabs
       #build_gas_inp_file(list_of_slabs = list_of_slabs, output_file_path = 'gas.inp', with_H2_He_Ar_Ne_Al = True)
    
       # %% Compare spectra from Windows and FORTRAN specair versions
    
       cfg['jobName'] = 'air7200KP1atm'
    
       rad_air = run_specair(cfg=cfg,
                             config_file=None,
                             existing_input_file=False,
                             plot=False,  # if True, final results will be plotted at end of the simulation
                             build_gas_inp=True,  # if True gas.inp will be built according to information in cfg['gas.inp']
                             build_temp_inp=False,  # if True temp.inp will be built according to information in cfg['temp.inp']
                             existing_gas_inp=False,  # if True gas.inp will be used
                             existing_temp_inp=False,  # if True temp.inp and aircomp.inp will be used
                             ignore_overwrite_warning=True,  # if True existing results folder will be overriden in any case
                             verbose=True,  # if True to allow print
                             specair_output=False,  # if True to allow print specair's output
                             version='igloo')
    
       mplt.figure()
       mplt.plot(rad_air['wavelength_nm'], rad_air['intensity_mW/cm^2/sr/um'], label='fortran')
       mplt.legend()
       mplt.show()
    
    See full example in `pyspecair\test_specair\air7200K1atm_with_non_eq_composition\scripting_specair_air7200K_noneq.py`
    

    The spirit of run_specair() input arguments is to put all the parameters sent to the underlying Fortran code into the cfg dictionnary, and to put all the python parameters as regular python arguments.

  • large_spectrum(): same as above

User Documentation

You may also want to execute all tests

Developer Documentation

References

Indices and tables