Developer GuideΒΆ
RADIS is an open-source project, and therefore anyone can contribute, whether you already know spectroscopy or not. The project is organized around a GitHub repository.
Getting StartedΒΆ
New to open source? Welcome! π Hereβs how to get started:
Look for Good First Issues - these are specifically tagged to help new contributors.
The Documentation TODO List is also a great place to start.
Making ChangesΒΆ
We use the GitHub Flow for all code changes:
Fork the repository
Create a branch for your feature
Make your changes
Open a Pull Request (PR)
Address review comments
Get merged!
For small changes (like fixing typos), you can edit directly on GitHub and open a PR.
Code Style and LintingΒΆ
We use the Black and Flake8 coding style to ensure consistent code formatting. Code style is checked using CI services which run automatically on each pull request. Black is automatically installed when radis is set-up in developer mode.
To format any file/files:
black /path/to/file/or/directory/
You can include Black coding style directly in some text editors
Black coding style can be checked automatically before each commit. For that all you need to do is to run the following command once:
cd radis
pre-commit install
On each commit, format will be fixed if it was incorrect. All you need to do is to commit a second time. Example:
$ git commit -am "test"
black....................................................................Failed
- hook id: black
- files were modified by this hook
reformatted [ALL FAILING FILES]
All done!
1 file reformatted.
$ git commit -am "test"
black....................................................................Passed
[develop XXX] test
1 file changed, 1 insertion(+)
Note that pre-commit will always require you to commit again after a test was failed, because itβs safer. If for any reason you want to skip formatting you can commit with the --no-verify
argument.
Keeping Your Fork UpdatedΒΆ
If youβre a regular contributor, keep your fork in sync with the main repository:
Add the upstream remote:
git remote add upstream git://github.com/radis/radis.git git fetch upstream
Create new branches from the latest upstream version:
git branch -b [NEW_BRANCH] upstream/develop
Update your branch with upstream changes:
git pull --rebase upstream [NEW_BRANCH]
Push to your fork:
git push -u origin [NEW-BRANCH]
SourcesΒΆ
InstallΒΆ
This is the developper documentation, if you want to access the latest features, modify the code, or contribute. For the user documentation, see the use-only install.
Fork the RADIS repository and use that url for the clone step below. This will make submitting changes easier in the long term for you.
In a terminal, run:
git clone https://github.com/<YOUR GITHUB USERNAME>/radis.git
3. For a best experience, it is recommended to install Radis on top of an Anaconda Python distribution, in an
isolated environment. We recommend to use the faster, local-optimization libmamba
solver for Anaconda.
You can create a radis environment with all dependencies with:
cd radis
conda env create --file environment.yml --solver=libmamba
Then install Radis in the
radis-env
environment:conda activate radis-env pip install -e . -v
The
-e
(editable) argument creates a link from the local folder./
into Python site-packages.For development, you can install additional packages with
pip install -e .[dev]
These include tools for testing and linting your code.For documentation development, use
pip install -e .[docs]
to install additional packages needed for building the documentation.
To make sure the install worked, run the first example from the Quick Start page. Then, youβre all set.
UpdateΒΆ
Whenever you want to update your local copy of Radis, run:
git pull
pip install -e .
For development or documentation updates, use pip install -e .[dev]
or pip install -e .[docs]
respectively.
Note
The command pip install -e .
is different from pip install radis --upgrade
. The former will install the latest version from the local folder, which may be more recent than the latest release on PyPI.
Dependency ManagementΒΆ
RADIS uses modern Python packaging with pyproject.toml
for pip installations and environment.yml
for conda installations.
These files are kept in sync through automated tests.
Adding DependenciesΒΆ
When adding new dependencies:
Add them to both
pyproject.toml
andenvironment.yml
Run the sync test locally:
python radis/test/test_sync_dependencies.py
Choose the appropriate dependency group:
Core dependencies: Add to both filesβ main section
Development tools: Add to
[project.optional-dependencies].dev
inpyproject.toml
Documentation tools: Add to
[project.optional-dependencies].docs
inpyproject.toml
Package StructureΒΆ
The package is structured to exclude tests and documentation from the main installation:
Tests are available when installing with
pip install -e .[dev]
Documentation tools are available with
pip install -e .[docs]
The main installation (
pip install radis
orpip install -e .
) includes only the core package
Update your changes online (push)ΒΆ
Submit a Pull Request from GitHub.
Online tests will be run automatically. They will check for:
Physics test cases, to ensure that the code is still working as expected (see Test Section to run them locally).
Code format (see Code Style and Linting).
Dependency synchronization between
pyproject.toml
andenvironment.yml
Testing RADISΒΆ
Test StatusΒΆ
Test routines are automatically executed by Travis CI whenever changes are made to the GitHub repository.
It is recommended to run these tests locally to identify potential errors before pushing changes.
To run the tests locally, assuming you have cloned the source code
(see the Install section), execute the following command in
the radis
directory:
cd radis
pytest
The entire test procedure takes approximately 5β10 minutes. You can use pytest filtering keys to run specific tests only.
Selecting TestsΒΆ
You can select or exclude specific tests using the -m
option. For example, to run only the fast tests, use:
pytest -m fast
Commonly used tags include:
fast: Tests that run in under 1 second.
needs_connection: Requires an internet connection.
needs_config_file: Requires the
~/radis.json
configuration file.
Additional tags for user-defined [HITEMP-2010] databases, as described in the Configuration file section:
needs_db_HITEMP_CO2_DUNHAM: Requires the HITEMP-CO2-DUNHAM database in
~/radis.json
.needs_db_HITEMP_CO_DUNHAM: Requires the HITEMP-CO-DUNHAM database in
~/radis.json
.needs_db_CDSD_HITEMP_PC: Requires the CDSD-HITEMP-PC database in
~/radis.json
.
The default test routine executed on Travis (see the radis/.travis.yml
file) is:
pytest -m "not fast and not needs_cuda and not download_large_databases and not needs_db_CDSD_HITEMP and not needs_db_CDSD_HITEMP_PCN and not needs_db_CDSD_HITEMP_PC and not needs_db_HITEMP_CO2_DUNHAM and not needs_db_HITEMP_CO_DUNHAM"
This routine excludes all tests that require large database files.
Writing New TestsΒΆ
Any function starting with test
will be automatically detected by pytest. Use assert
statements within the function to validate object properties. For example:
def test_positive(a):
assert a > 0
Tip: Ensure that no figures are opened by default in your test routines, as this may cause the process to hang when executed by pytest. To enforce non-blocking behavior, add the following lines within your test function:
if plot:
import matplotlib.pyplot as plt
plt.ion() # Prevent Matplotlib from blocking execution during pytest
Refer to previous pull requests for examples of test cases written for new features (e.g., #495 or #3697).
Test FilesΒΆ
To ensure errors are reproducible, use the test files provided in the
radis/test/files
and radis/test/validation directories.
These files include examples of line databases, spectra, and energy levels.
You can retrieve the paths to these test files using the getTestFile()
and
getValidationCase()
functions, respectively.
Load a line database file:
from radis.test.utils import getTestFile
from radis.api.hitranapi import hit2df
df = hit2df(getTestFile("hitran_CO_fragment.par"))
print(df) # Replace with your test code
>>> Out:
id iso wav int A ... gpp branch jl vu vl
0 5 1 3.705026 2.354000e-44 2.868000e-10 ... 1.0 1 0 4 4
...
Load a Spectrum object:
from radis.test.utils import getTestFile
from radis import load_spec
s = load_spec(getTestFile("CO_Tgas1500K_mole_fraction0.5.spec"))
print(s) # Replace with your test code
>>> Out:
Spectrum Name: CO_Tgas1500K_mole_fraction0.5.spec
Spectral Arrays
----------------------------------------
abscoeff (37,870 points)
...
DebuggingΒΆ
Use the printdbg()
function in radis.misc
and
the DEBUG_MODE
global variable for debugging.
Code CoverageΒΆ
Code coverage ensures that every line in RADIS is properly tested. View the current code coverage status (click the badge for details):
To view the test coverage report locally, use codecov
, which is integrated with pytest through the --cov=./
command:
pip install codecov pytest-cov
cd radis/test
pytest --cov=./
Performance BenchmarksΒΆ
RADIS performance is benchmarked against previous versions in a dedicated project: radis-benchmark.
Results are available at: π https://radis.github.io/radis-benchmark/
ArchitectureΒΆ
The RADIS modules are organized with the following flow chart
The upper part shows the successive calculation steps of the Line-by-Line module.
These steps appear clearly in the source code of the
eq_spectrum()
and
non_eq_spectrum()
methods of the
SpectrumFactory
.
See details at the end of this file.
Methods are written in Factory objects inherited with the following scheme:
DatabankLoader
> BaseFactory
>
BroadenFactory
> BandFactory
>
SpectrumFactory
The Input Conditions in the left part, and the Computation Parameters on the right part, are the input parameters of the different RADIS front-ends:
calc_spectrum()
for the simple cases.SpectrumFactory
witheq_spectrum()
andnon_eq_spectrum()
for the other cases. GPU calculation can be done witheq_spectrum_gpu()
The Input databases are either automatically downloaded from [HITRAN-2020], or defined locally in a Configuration file
The bottom part includes the post-processing modules of RADIS, in particular:
The various methods associated with the
Spectrum
class.The Line-of-Sight module module
The
LineSurvey
tool.The
SpecDatabase
tool.
Methods from the Flow Chart: this methods are called successively from the
radis.lbl.factory.SpectrumFactory.eq_spectrum()
and
radis.lbl.factory.SpectrumFactory.non_eq_spectrum()
methods.
Line Database: methods of
DatabankLoader
:Partition functions: methods of
RovibParFuncTabulator
andRovibParFuncCalculator
:Populations: methods of
BaseFactory
:Line Intensities: methods of
BaseFactory
:radis.lbl.base.BaseFactory._calc_linestrength_noneq()
radis.lbl.base.BaseFactory._calc_emission_integral()
Line Positions: methods of
BaseFactory
:Reduced line set: methods of
BaseFactory
:radis.lbl.base.BaseFactory._cutoff_linestrength()
Voigt Broadening: methods of
BroadenFactory
:radis.lbl.broadening._whiting()
radis.lbl.broadening._whiting_jit()
radis.lbl.broadening.BroadenFactory._calc_broadening_FWHM()
Pseudo-continuum: methods of
BroadenFactory
:radis.lbl.broadening.BroadenFactory._find_weak_lines()
radis.lbl.broadening.BroadenFactory._calculate_pseudo_continuum()
radis.lbl.broadening.BroadenFactory._add_pseudo_continuum()
Spectral densities k, j: methods of
SpectrumFactory
:RTE (1 slab): methods of
SpectrumFactory
:
HelpΒΆ
If you encounter any problem:
Check if itβs a known issue in our GitHub Issues
If not, please open a new issue with:
A quick summary
Steps to reproduce
Expected vs actual behavior
Any relevant notes or attempted solutions
You can also ask for advice on the community chat: