From b1706d42d643abcf546ede66bdf80b15985fd275 Mon Sep 17 00:00:00 2001 From: vsnever Date: Mon, 7 Aug 2023 17:51:40 +0300 Subject: [PATCH 1/4] Reduce cherab-adas module to parsers and installers for compatibility with the new atomic data architecture. --- cherab/adas/__init__.py | 10 +- cherab/adas/adas.py | 573 --------------------- cherab/adas/adas4xx/__init__.py | 6 +- cherab/adas/adas4xx/adas405.py | 26 +- cherab/adas/adas6xx/__init__.py | 8 +- cherab/adas/adas6xx/adas603.py | 68 +-- cherab/adas/install.py | 134 ++++- cherab/adas/parse/__init__.py | 6 +- cherab/adas/rates/__init__.pxd | 20 - cherab/adas/rates/__init__.py | 21 - cherab/adas/rates/fractional_abundance.pxd | 29 -- cherab/adas/rates/fractional_abundance.pyx | 47 -- cherab/adas/rates/radiated_power.pxd | 29 -- cherab/adas/rates/radiated_power.pyx | 55 -- cherab/adas/repository/__init__.py | 25 - cherab/adas/repository/atomic.py | 34 -- cherab/adas/repository/beam/__init__.py | 22 - cherab/adas/repository/beam/cx.py | 25 - cherab/adas/repository/beam/emission.py | 25 - cherab/adas/repository/beam/population.py | 25 - cherab/adas/repository/beam/stopping.py | 25 - cherab/adas/repository/create.py | 395 -------------- cherab/adas/repository/pec.py | 32 -- cherab/adas/repository/radiated_power.py | 34 -- cherab/adas/repository/utility.py | 46 -- cherab/adas/repository/wavelength.py | 25 - demos/fractional_abundance.py | 7 +- demos/total_radiation.py | 7 +- demos/zeeman_splitting.py | 19 +- setup.py | 59 +-- 30 files changed, 216 insertions(+), 1621 deletions(-) delete mode 100644 cherab/adas/adas.py delete mode 100644 cherab/adas/rates/__init__.pxd delete mode 100644 cherab/adas/rates/__init__.py delete mode 100644 cherab/adas/rates/fractional_abundance.pxd delete mode 100644 cherab/adas/rates/fractional_abundance.pyx delete mode 100644 cherab/adas/rates/radiated_power.pxd delete mode 100644 cherab/adas/rates/radiated_power.pyx delete mode 100644 cherab/adas/repository/__init__.py delete mode 100644 cherab/adas/repository/atomic.py delete mode 100644 cherab/adas/repository/beam/__init__.py delete mode 100644 cherab/adas/repository/beam/cx.py delete mode 100644 cherab/adas/repository/beam/emission.py delete mode 100644 cherab/adas/repository/beam/population.py delete mode 100644 cherab/adas/repository/beam/stopping.py delete mode 100644 cherab/adas/repository/create.py delete mode 100644 cherab/adas/repository/pec.py delete mode 100644 cherab/adas/repository/radiated_power.py delete mode 100644 cherab/adas/repository/utility.py delete mode 100644 cherab/adas/repository/wavelength.py diff --git a/cherab/adas/__init__.py b/cherab/adas/__init__.py index be74fd7..8fa2d21 100644 --- a/cherab/adas/__init__.py +++ b/cherab/adas/__init__.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -16,4 +16,6 @@ # See the Licence for the specific language governing permissions and limitations # under the Licence. -from .adas import ADAS +from cherab.atomic.atomicdata import AtomicData as ADAS + +from . import install diff --git a/cherab/adas/adas.py b/cherab/adas/adas.py deleted file mode 100644 index 3864423..0000000 --- a/cherab/adas/adas.py +++ /dev/null @@ -1,573 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import numpy as np -from raysect.core.math.function.float import Interpolator1DArray - -from cherab.core import AtomicData -from cherab.core.atomic.elements import Isotope -from cherab.core.atomic import ZeemanStructure -from cherab.adas.repository import DEFAULT_REPOSITORY_PATH -from cherab.adas.adas4xx.adas405 import run_adas405 -from cherab.adas.adas6xx.adas603 import run_adas603 - -from cherab.adas.rates import * -from cherab.adas import repository - - -class ADAS(AtomicData): - """ - ADAS atomic data source. - - :param str data_path: ADAS local repository path. - :param bool permit_extrapolation: If true, informs interpolation objects to allow extrapolation - beyond the limits of the tabulated data. Default is False. - :param bool missing_rates_return_null: If true, allows Null rate objects to be returned when - the requested atomic data is missing. Default is False. - :param bool wavelength_element_fallback: If true, allows to use the element's wavelength when - the isotope's wavelength is not available. - Default is False. - """ - - def __init__(self, data_path=None, permit_extrapolation=False, missing_rates_return_null=False, - wavelength_element_fallback=False): - - super().__init__() - self._data_path = data_path or DEFAULT_REPOSITORY_PATH - - self._permit_extrapolation = permit_extrapolation - - self._missing_rates_return_null = missing_rates_return_null - - self._wavelength_element_fallback = wavelength_element_fallback - - @property - def data_path(self): - return self._data_path - - def wavelength(self, ion, charge, transition): - """ - Spectral line wavelength for a given transition. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :param transition: Tuple containing (initial level, final level) - :return: Wavelength in nanometers. - """ - - if isinstance(ion, Isotope) and self._wavelength_element_fallback: - try: - return repository.get_wavelength(ion, charge, transition, repository_path=self._data_path) - except RuntimeError: - return repository.get_wavelength(ion.element, charge, transition, repository_path=self._data_path) - - return repository.get_wavelength(ion, charge, transition, repository_path=self._data_path) - - def ionisation_rate(self, ion, charge): - """ - Electron impact ionisation rate for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :return: Ionisation rate in m^3/s as a function of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - try: - # read ionisation rate from json file in the repository - data = repository.get_ionisation_rate(ion, charge, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullIonisationRate() - raise - - return IonisationRate(data, extrapolate=self._permit_extrapolation) - - def recombination_rate(self, ion, charge): - """ - Recombination rate for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :return: Recombination rate in m^3/s as a function of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - try: - # read recombination rate from json file in the repository - data = repository.get_recombination_rate(ion, charge, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullRecombinationRate() - raise - - return RecombinationRate(data, extrapolate=self._permit_extrapolation) - - def thermal_cx_rate(self, donor_element, donor_charge, receiver_element, receiver_charge): - """ - Thermal charge exchange effective rate coefficient for a given donor and receiver species. - - ADAS data is interpolated with cubic spline in log-log space. - Linear extrapolation is used when permit_extrapolation is True. - - :param donor_element: Element object defining the donor ion type. - :param donor_charge: Charge state of the donor ion. - :param receiver_element: Element object defining the receiver ion type. - :param receiver_charge: Charge state of the receiver ion. - :return: Thermal charge exchange rate in m^3/s as a function of electron density and - temperature. - """ - - # extract elements from isotopes because there are no isotope rates in ADAS - if isinstance(donor_element, Isotope): - donor_element = donor_element.element - - if isinstance(receiver_element, Isotope): - receiver_element = receiver_element.element - - try: - # read thermal CX rate from json file in the repository - data = repository.get_thermal_cx_rate(donor_element, donor_charge, - receiver_element, receiver_charge, - repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullThermalCXRate() - raise - - return ThermalCXRate(data, extrapolate=self._permit_extrapolation) - - def beam_cx_pec(self, donor_ion, receiver_ion, receiver_charge, transition): - """ - Effective charge exchange photon emission coefficient for a given donor (beam) - and receiver (plasma) species and a given transition. - - The data for "qeb" is interpolated with a cubic spline in log-log space. - The data for "qti", "qni", "qz" and "qb" are interpolated with a cubic spline - in linear space. - Quadratic extrapolation is used for "qeb" and nearest neighbour extrapolation is used for - "qti", "qni", "qz" and "qb" when permit_extrapolation is True. - - - :param donor_ion: Element object defining the donor ion type. - :param receiver_ion: Element object defining the receiver ion type. - :param receiver_charge: Charge state of the receiver ion. - :param transition: Tuple containing (initial level, final level) of the receiver species. - :return: Charge exchange photon emission coefficient in W.m^3 as a function of - interaction energy, receiver ion temperature, receiver ion density, - plasma Z-effective, magnetic field magnitude. - """ - - # extract element from donor isotope because there are no isotope rates in ADAS - if isinstance(donor_ion, Isotope): - donor_ion = donor_ion.element - - # extract element from receiver isotope, but keep the receiver isotope for the wavelength - receiver_ion_element = receiver_ion.element if isinstance(receiver_ion, Isotope) else receiver_ion - - try: - # read element CX rate from json file in the repository - data = repository.get_beam_cx_rates(donor_ion, receiver_ion_element, receiver_charge, transition, - repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return [NullBeamCXPEC()] - raise - - # obtain isotope's rest wavelength for a given transition - # the wavelength is used ot convert the PEC from photons/s/m3 to W/m3 - wavelength = self.wavelength(receiver_ion, receiver_charge - 1, transition) - - # load and interpolate the relevant transition data from each file - rates = [] - for donor_metastable, rate_data in data: - rates.append(BeamCXPEC(donor_metastable, wavelength, rate_data, extrapolate=self._permit_extrapolation)) - return rates - - def beam_stopping_rate(self, beam_ion, plasma_ion, charge): - """ - Beam stopping coefficient for a given beam and target species. - - ADAS data is interpolated with cubic spline in log-log space. - Linear and quadratic extrapolations are used for "sen" and "st" respectively - when permit_extrapolation is True. - - :param beam_ion: Element object defining the beam ion type. - :param plasma_ion: Element object defining the target ion type. - :param charge: Charge state of the target ion. - :return: The beam stopping coefficient in m^3.s^-1 as a function of interaction energy, - target equivalent electron density, target temperature. - """ - - # extract elements from isotopes because there are no isotope rates in ADAS - if isinstance(beam_ion, Isotope): - beam_ion = beam_ion.element - - if isinstance(plasma_ion, Isotope): - plasma_ion = plasma_ion.element - - try: - # read beam stopping rate from json file in the repository - data = repository.get_beam_stopping_rate(beam_ion, plasma_ion, charge, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullBeamStoppingRate() - raise - - # load and interpolate data - return BeamStoppingRate(data, extrapolate=self._permit_extrapolation) - - def beam_population_rate(self, beam_ion, metastable, plasma_ion, charge): - """ - Beam population coefficient for a given beam and target species. - - ADAS data is interpolated with cubic spline in log-log space. - Linear and quadratic extrapolations are used for "sen" and "st" respectively - when permit_extrapolation is True. - - :param beam_ion: Element object defining the beam ion type. - :param metastable: The beam ion metastable number. - :param plasma_ion: Element object defining the target ion type. - :param charge: Charge state of the target ion. - :return: The beam population coefficient in dimensionless units as a function of - interaction energy, target equivalent electron density, target temperature. - """ - - # extract elements from isotopes because there are no isotope rates in ADAS - if isinstance(beam_ion, Isotope): - beam_ion = beam_ion.element - - if isinstance(plasma_ion, Isotope): - plasma_ion = plasma_ion.element - - try: - # read beam population rate from json file in the repository - data = repository.get_beam_population_rate(beam_ion, metastable, plasma_ion, charge, - repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullBeamPopulationRate() - raise - - # load and interpolate data - return BeamPopulationRate(data, extrapolate=self._permit_extrapolation) - - def beam_emission_pec(self, beam_ion, plasma_ion, charge, transition): - """ - The beam photon emission coefficient for a given beam and target species - and a given transition. - - ADAS data is interpolated with cubic spline in log-log space. - Linear and quadratic extrapolations are used for "sen" and "st" respectively - when permit_extrapolation is True. - - :param beam_ion: Element object defining the beam ion type. - :param plasma_ion: Element object defining the target ion type. - :param charge: Charge state of the target ion. - :param transition: Tuple containing (initial level, final level) of the beam ion. - :return: The beam photon emission coefficient in W.m^3 as a function of - interaction energy, target equivalent electron density, target temperature. - """ - - # extract element from beam isotope, but keep the beam isotope for the wavelength - beam_ion_element = beam_ion.element if isinstance(beam_ion, Isotope) else beam_ion - - # extract element from plasma isotope because there are no isotope rates in ADAS - if isinstance(plasma_ion, Isotope): - plasma_ion = plasma_ion.element - - try: - # read beam emission PEC from json file in the repository - data = repository.get_beam_emission_rate(beam_ion_element, plasma_ion, charge, transition, - repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullBeamEmissionPEC() - raise - - # obtain isotope's rest wavelength for a given transition - # the wavelength is used ot convert the PEC from photons/s/m3 to W/m3 - wavelength = self.wavelength(beam_ion, 0, transition) - - # load and interpolate data - return BeamEmissionPEC(data, wavelength, extrapolate=self._permit_extrapolation) - - def impact_excitation_pec(self, ion, charge, transition): - """ - Electron impact excitation photon emission coefficient for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :param transition: Tuple containing (initial level, final level). - :return: Impact excitation photon emission coefficient in W.m^3 as a - function of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - # keep the isotope for the wavelength - ion_element = ion.element if isinstance(ion, Isotope) else ion - - try: - # read electron impact excitation PEC from json file in the repository - data = repository.get_pec_excitation_rate(ion_element, charge, transition, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullImpactExcitationPEC() - raise - - # obtain isotope's rest wavelength for a given transition - # the wavelength is used ot convert the PEC from photons/s/m3 to W/m3 - wavelength = self.wavelength(ion, charge, transition) - - return ImpactExcitationPEC(wavelength, data, extrapolate=self._permit_extrapolation) - - def recombination_pec(self, ion, charge, transition): - """ - Recombination photon emission coefficient for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion after recombination. - :param transition: Tuple containing (initial level, final level). - :return: Recombination photon emission coefficient in W.m^3 as a function of electron - density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - # keep the isotope for the wavelength - ion_element = ion.element if isinstance(ion, Isotope) else ion - - try: - # read free electron recombination PEC from json file in the repository - data = repository.get_pec_recombination_rate(ion_element, charge, transition, repository_path=self._data_path) - - except (FileNotFoundError, KeyError): - if self._missing_rates_return_null: - return NullRecombinationPEC() - raise - - # obtain isotope's rest wavelength for a given transition - # the wavelength is used ot convert the PEC from photons/s/m3 to W/m3 - wavelength = self.wavelength(ion, charge, transition) - - return RecombinationPEC(wavelength, data, extrapolate=self._permit_extrapolation) - - def line_radiated_power_rate(self, ion, charge): - """ - Line radiated power coefficient for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :return: Line radiated power coefficient in W.m^3 as a function of electron - density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - try: - # read total line radiated power rate from json file in the repository - data = repository.get_line_radiated_power_rate(ion, charge, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullLineRadiationPower(ion, charge) - raise - - return LineRadiationPower(ion, charge, data, extrapolate=self._permit_extrapolation) - - def continuum_radiated_power_rate(self, ion, charge): - """ - Recombination continuum radiated power coefficient for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :return: Continuum radiated power coefficient in W.m^3 as a function - of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - try: - # read continuum radiated power rate from json file in the repository - data = repository.get_continuum_radiated_power_rate(ion, charge, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullContinuumPower(ion, charge) - raise - - return ContinuumPower(ion, charge, data, extrapolate=self._permit_extrapolation) - - def cx_radiated_power_rate(self, ion, charge): - """ - Charge exchange radiated power coefficient for a given species. - - ADAS data is interpolated with cubic spline in log-log space. - Linear extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :return: Charge exchange radiated power coefficient in W.m^3 as a function - of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - try: - # read CX radiated power rate from json file in the repository - data = repository.get_cx_radiated_power_rate(ion, charge, repository_path=self._data_path) - - except RuntimeError: - if self._missing_rates_return_null: - return NullCXRadiationPower(ion, charge) - raise - - return CXRadiationPower(ion, charge, data, extrapolate=self._permit_extrapolation) - - def total_radiated_power(self, ion): - """ - Total radiated power coefficient for a given element or isotope summed - over charge states. - - Runs ADAS405. - - ADAS data is interpolated with cubic spline in log-log space. - Linear extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - - :return: Total radiated power coefficient in W.m^3 as a function - of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - electron_densities, electron_temperatures, _, total_power_array, _, _, _, _ = run_adas405(elem=ion.symbol.lower()) - - return TotalRadiatedPower(ion, electron_densities, electron_temperatures, total_power_array, - extrapolate=self._permit_extrapolation) - - def fractional_abundance(self, ion, charge): - """ - Fractional abundance for a given species. - - Runs ADAS405. - - ADAS data is interpolated with cubic spline. - Linear extrapolation is used when permit_extrapolation is True. - - :param ion: Element object defining the ion type. - :param charge: Charge state of the ion. - :return: Fractional abundance as a function - of electron density and temperature. - """ - - # extract element from isotope because there are no isotope rates in ADAS - if isinstance(ion, Isotope): - ion = ion.element - - electron_densities, electron_temperatures, fraction, _, _, _, _, _ = run_adas405(elem=ion.symbol.lower()) - name = ion.symbol + '_' + str(charge) - - return FractionalAbundance(ion, charge, electron_densities, electron_temperatures, fraction[:, :, charge], - name=name, extrapolate=self._permit_extrapolation) - - def zeeman_structure(self, line, b_field=None): - r""" - Wavelengths and ratios of :math:`\pi`-/:math:`\sigma`-polarised Zeeman components - of the specified spectral line for any given value of magnetic field strength. - - Runs ADAS 603. - - ADAS data is interpolated linearly. - Nearest neighbour extrapolation is used when permit_extrapolation is True. - - :param Line line: Spectral line object. - Run cherab.adas.adas6xx.print_adas603_supported_lines() to see - the complete list of supported lines. - :param b_field: The grid of magnetic field strength (list or ndarray) - to interpolate from. Defaults to np.arange(0, bmax, 0.1), - where bmax is B_FIELD_MAX[line] if B_FIELD_MAX is - specified for this line, or 20.0 T if B_FIELD_MAX is not specified. - - :return: ZeemanStructure - """ - - b_field, pi_comp, sigma_plus_comp, sigma_minus_comp = run_adas603(line, b_field) - - pi_components = [] - sigma_plus_components = [] - sigma_minus_components = [] - - extrapolation_type = 'nearest' if self._permit_extrapolation else 'none' - - for component in pi_comp: - wvl = Interpolator1DArray(b_field, component[0], 'linear', extrapolation_type, np.inf) - ratio = Interpolator1DArray(b_field, component[1], 'linear', extrapolation_type, np.inf) - pi_components.append((wvl, ratio)) - - for component in sigma_plus_comp: - wvl = Interpolator1DArray(b_field, component[0], 'linear', extrapolation_type, np.inf) - ratio = Interpolator1DArray(b_field, component[1], 'linear', extrapolation_type, np.inf) - sigma_plus_components.append((wvl, ratio)) - - for component in sigma_minus_comp: - wvl = Interpolator1DArray(b_field, component[0], 'linear', extrapolation_type, np.inf) - ratio = Interpolator1DArray(b_field, component[1], 'linear', extrapolation_type, np.inf) - sigma_minus_components.append((wvl, ratio)) - - return ZeemanStructure(pi_components, sigma_plus_components, sigma_minus_components) diff --git a/cherab/adas/adas4xx/__init__.py b/cherab/adas/adas4xx/__init__.py index f6b50f2..03b924a 100644 --- a/cherab/adas/adas4xx/__init__.py +++ b/cherab/adas/adas4xx/__init__.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); diff --git a/cherab/adas/adas4xx/adas405.py b/cherab/adas/adas4xx/adas405.py index 1da60c5..6241664 100644 --- a/cherab/adas/adas4xx/adas405.py +++ b/cherab/adas/adas4xx/adas405.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -29,6 +29,26 @@ def run_adas405(uid='adas', year=96, elem='ne'): + """ + Runs ADAS405 routine and gets radiated power for a given element. + + :param uid: Username of adf11 location. Defaults to 'adas' for central ADAS data. + :param year: Year index of the adf11 data. Defaults to 96. + :param elem: Element symbol. Defaults to 'ne'. + + :returns: + + | ne: electron density array of size N, + | te: electron temperature array of size M, + | fractional_abundance: (N, M, K) array with fractional abundances, + | total_power: (N, M) array with total radiated power, + | line_power: (N, M) array with line power driven by excitation of dominant ions, + | continuum_power: (N, M) array with continuum and line power driven by recombination + | and Bremsstrahlung of dominant ions, + | cx_power: (N, M) array with line power due to charge transfer from thermal neutral + | hydrogen to dominant ions, + | stage_resolved_line_power: (N, M, K) array with line power resolved over ionisation stage. + """ unique_cache_id = (uid, year, elem) diff --git a/cherab/adas/adas6xx/__init__.py b/cherab/adas/adas6xx/__init__.py index 48c3814..43024fe 100644 --- a/cherab/adas/adas6xx/__init__.py +++ b/cherab/adas/adas6xx/__init__.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -16,4 +16,4 @@ # See the Licence for the specific language governing permissions and limitations # under the Licence. -from .adas603 import run_adas603, print_adas603_supported_lines +from .adas603 import run_adas603, print_adas603_supported_lines, SUPPORTED_LINES diff --git a/cherab/adas/adas6xx/adas603.py b/cherab/adas/adas6xx/adas603.py index 50789ef..8e0ac48 100755 --- a/cherab/adas/adas6xx/adas603.py +++ b/cherab/adas/adas6xx/adas603.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -105,6 +105,9 @@ HDLIKE += [Line(neon, 9, (j, 13)) for j in range(15, 21)] +SUPPORTED_LINES = MULTIPLETS + HDLIKE + + B_FIELD_MAX = {line: None for line in MULTIPLETS + HDLIKE} for isotope in (hydrogen, deuterium, tritium): for i in (1, 4): @@ -208,9 +211,8 @@ def run_adas603(line, b_field=None, adas_fort=None): if not os.path.isfile(file_path): raise IOError('File {} not found.'.format(file_path)) - pi_components = [] - sigma_plus_components = [] - sigma_minus_components = [] + wavelength_list = [] + ratio_list = [] for b in b_field: process = Popen([file_path], stdin=PIPE, stdout=PIPE, stderr=PIPE) @@ -222,41 +224,49 @@ def run_adas603(line, b_field=None, adas_fort=None): if errors: raise IOError('Process {} is terminated with error: {}.'.format(file_path, errors.decode('utf-8'))) - pi_comp, sigma_plus_comp, sigma_minus_comp = _adas603_output_to_components(outs.decode('utf-8')) + polarisation, wavelength, ratio = _adas603_output_to_components(outs.decode('utf-8')) - pi_components.append(pi_comp) - sigma_plus_components.append(sigma_plus_comp) - sigma_minus_components.append(sigma_minus_comp) + wavelength_list.append(wavelength) + ratio_list.append(ratio) - return b_field, np.array(pi_components).T, np.array(sigma_plus_components).T, np.array(sigma_minus_components).T + data = { + 'b': b_field, + 'polarisation': polarisation, + 'wavelength': np.array(wavelength_list).T, + 'ratio': np.array(ratio_list).T, + 'reference': 'ADAS {}'.format(executable) + } + + return data def _adas603_output_to_components(outs): lines = outs.splitlines() - pi_components = [] - sigma_plus_components = [] - sigma_minus_components = [] + ratio = [] + wavelength = [] + polarisation = [] for line in lines: if '#' in line: columns = line.split('#') intensity = float(columns[-1]) - wavelength = 0.1 * float(columns[-2]) - polarisation = int(columns[-3].split('/')[0]) + wvl = 0.1 * float(columns[-2]) + pol = int(columns[-3].split('/')[0]) - if polarisation == 0: # pi components - pi_components.append([wavelength, intensity]) - elif polarisation > 0: # sigma+ components - sigma_plus_components.append([wavelength, intensity]) - elif polarisation < 0: # sigma- components - sigma_minus_components.append([wavelength, intensity]) + polarisation.append(np.sign(pol)) + wavelength.append(wvl) + ratio.append(intensity) - pi_components = np.array(pi_components).T - sigma_plus_components = np.array(sigma_plus_components).T - sigma_minus_components = np.array(sigma_minus_components).T + polarisation = np.array(polarisation, dtype=np.int32) + wavelength = np.array(wavelength) + ratio = np.array(ratio) # renormalising - pi_components[1] /= pi_components[1].sum() - sigma_plus_components[1] /= sigma_plus_components[1].sum() - sigma_minus_components[1] /= sigma_minus_components[1].sum() + index_pi, = np.where(polarisation == 0) + index_sigma_plus, = np.where(polarisation == 1) + index_sigma_minus, = np.where(polarisation == -1) + + ratio[index_pi] /= ratio[index_pi].sum() + ratio[index_sigma_plus] /= ratio[index_sigma_plus].sum() + ratio[index_sigma_minus] /= ratio[index_sigma_minus].sum() - return pi_components, sigma_plus_components, sigma_minus_components + return polarisation, wavelength, ratio diff --git a/cherab/adas/install.py b/cherab/adas/install.py index c5283c7..a82471c 100644 --- a/cherab/adas/install.py +++ b/cherab/adas/install.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -19,12 +19,19 @@ import os -from cherab.adas import repository +from cherab.atomic import repository from cherab.adas.parse import * +from cherab.adas.adas6xx.adas603 import SUPPORTED_LINES as ADAS603_SUPPORTED_LINES +from cherab.adas.adas6xx import run_adas603 +from cherab.adas.adas4xx import run_adas405 from cherab.core.utility import RecursiveDict, PerCm3ToPerM3, Cm3ToM3 def install_files(configuration, repository_path=None, adas_home=None): + """ + Wrapper function that installs rates of atomic processes defined + in ADAS files to the repository. + """ for adf in configuration: if adf.lower() == 'adf11scd': @@ -255,13 +262,17 @@ def install_adf15(element, ionisation, file_path, repository_path=None, adas_hom def install_adf21(beam_species, target_ion, target_charge, file_path, repository_path=None, adas_home=None): - # """ - # Adds the rate defined in an ADF21 file to the repository. - # - # :param file_path: Path relative to ADAS home. - # :param repository_path: Path to the repository in which to install the rates (optional). - # :param adas_home: Path to ADAS home directory (optional). - # """ + """ + Adds the beam stopping rate defined in an ADF21 file to the repository. + + :param beam_species: Beam neutral atom (Element/Isotope). + :param target_ion: Target species (Element/Isotope). + :param target_charge: Charge of the target species. + :param file_path: Path relative to ADAS root. + :param download: Attempt to download file if not present (Default=True). + :param repository_path: Path to the repository in which to install the rates (optional). + :param adas_home: Path to ADAS home directory (optional). + """ print('Installing {}...'.format(file_path)) path = _locate_adas_file(file_path, adas_home) @@ -274,14 +285,18 @@ def install_adf21(beam_species, target_ion, target_charge, file_path, repository def install_adf22bmp(beam_species, beam_metastable, target_ion, target_charge, file_path, repository_path=None, adas_home=None): - pass - # """ - # Adds the rate defined in an ADF21 file to the repository. - # - # :param file_path: Path relative to ADAS home. - # :param repository_path: Path to the repository in which to install the rates (optional). - # :param adas_home: Path to ADAS home directory (optional). - # """ + """ + Adds the beam population rate defined in an ADF22 BMP file to the repository. + + :param beam_species: Beam neutral atom (Element/Isotope). + :param beam_metastable: Metastable level of beam neutral atom. + :param target_ion: Target species (Element/Isotope). + :param target_charge: Charge of the target species. + :param file_path: Path relative to ADAS root. + :param download: Attempt to download file if not present (Default=True). + :param repository_path: Path to the repository in which to install the rates (optional). + :param adas_home: Path to ADAS home directory (optional). + """ print('Installing {}...'.format(file_path)) path = _locate_adas_file(file_path, adas_home) @@ -294,14 +309,18 @@ def install_adf22bmp(beam_species, beam_metastable, target_ion, target_charge, f def install_adf22bme(beam_species, target_ion, target_charge, transition, file_path, repository_path=None, adas_home=None): - pass - # """ - # Adds the rate defined in an ADF21 file to the repository. - # - # :param file_path: Path relative to ADAS home. - # :param repository_path: Path to the repository in which to install the rates (optional). - # :param adas_home: Path to ADAS home directory (optional). - # """ + """ + Adds the beam emission rate defined in an ADF22 BME file to the repository. + + :param beam_species: Beam neutral atom (Element/Isotope). + :param target_ion: Target species (Element/Isotope). + :param target_charge: Charge of the target species. + :param transition: Tuple containing (initial level, final level). + :param file_path: Path relative to ADAS root. + :param download: Attempt to download file if not present (Default=True). + :param repository_path: Path to the repository in which to install the rates (optional). + :param adas_home: Path to ADAS home directory (optional). + """ print('Installing {}...'.format(file_path)) path = _locate_adas_file(file_path, adas_home) @@ -313,6 +332,67 @@ def install_adf22bme(beam_species, target_ion, target_charge, transition, file_p repository.update_beam_emission_rates(rate, repository_path) +def install_zeeman_structures(lines=None, adas_fort=None, repository_path=None): + """ + Runs ADAS603 and adds Zeeman multiplet structures for given spectral lines to the repository. + + :param lines: Spectral lines for which the Zeeman structure is calculated. + Run cherab.adas.adas6xx.print_adas603_supported_lines() to see the complete list + of supported lines. + :param adas_fort: Path to ADAS FORTRAN executables. + Default path is 'home/adas/bin64' for 64-bit systems or 'home/adas/bin' for 32-bit systems. + :param repository_path: Path to the repository in which to install the rates (optional). + """ + + if lines is None: + lines = ADAS603_SUPPORTED_LINES + else: + unsupported_lines = set(lines).difference(ADAS603_SUPPORTED_LINES) + if len(unsupported_lines): + unsupported_lines_str = '\n'.join([str(line) for line in unsupported_lines]) + raise ValueError("The followoing spectral lines are not supported:\n{}".format(unsupported_lines_str)) + + zeeman_structures = RecursiveDict() + for line in lines: + data = run_adas603(line, adas_fort=adas_fort) + zeeman_structures[line.element][line.charge][line.transition] = data + + repository.update_zeeman_structures(zeeman_structures, repository_path) + + +def install_total_power_rate(element, uid='adas', year=96, repository_path=None): + """ + Runs ADAS405 and adds total radiated power rate for given species to the repository. + + :param element: Plasma species element. + :param uid: Username of adf11 location. Defaults to 'adas' for central ADAS data. + :param year: Year index of the adf11 data. Defaults to 96. + """ + + ne, te, _, total_power_rate, _, _, _, _ = run_adas405(uid=uid, year=year, elem=element.symbol.lower()) + data = {'ne': ne, 'te': te, 'rate': rate} + + repository.add_total_power_rate(element, data, repository_path=repository_path) + + +def install_fractional_abundances(element, uid='adas', year=96, repository_path=None): + """ + Runs ADAS405 and adds fractional abundances for given species to the repository. + + :param element: Plasma species element. + :param uid: Username of adf11 location. Defaults to 'adas' for central ADAS data. + :param year: Year index of the adf11 data. + """ + + ne, te, fractionl_abundances, _, _, _, _, _ = run_adas405(uid=uid, year=year, elem=element.symbol.lower()) + data = {element: {}} + + for i in range(fractionl_abundances.shape[-1]): + data[element][i] = {'ne': ne, 'te': te, 'fractionl_abundance': fractionl_abundances[:, :, i]} + + repository.update_fractional_abundances(data, repository_path=repository_path) + + def _locate_adas_file(file_path, adas_home=None): path = None diff --git a/cherab/adas/parse/__init__.py b/cherab/adas/parse/__init__.py index 340539b..f5b65f1 100644 --- a/cherab/adas/parse/__init__.py +++ b/cherab/adas/parse/__init__.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); diff --git a/cherab/adas/rates/__init__.pxd b/cherab/adas/rates/__init__.pxd deleted file mode 100644 index 190f4bd..0000000 --- a/cherab/adas/rates/__init__.pxd +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from cherab.openadas.rates cimport * - diff --git a/cherab/adas/rates/__init__.py b/cherab/adas/rates/__init__.py deleted file mode 100644 index 35e34bd..0000000 --- a/cherab/adas/rates/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from cherab.openadas.rates import * -from .radiated_power import * -from .fractional_abundance import * diff --git a/cherab/adas/rates/fractional_abundance.pxd b/cherab/adas/rates/fractional_abundance.pxd deleted file mode 100644 index c80bc5a..0000000 --- a/cherab/adas/rates/fractional_abundance.pxd +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from cherab.core.atomic.rates cimport FractionalAbundance as CoreFractionalAbundance -from cherab.core.math cimport Function2D - - -cdef class FractionalAbundance(CoreFractionalAbundance): - - cdef: - readonly dict raw_data - readonly tuple density_range, temperature_range - readonly Function2D _abundance_func - diff --git a/cherab/adas/rates/fractional_abundance.pyx b/cherab/adas/rates/fractional_abundance.pyx deleted file mode 100644 index 2766dc8..0000000 --- a/cherab/adas/rates/fractional_abundance.pyx +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import numpy as np -from libc.math cimport INFINITY - -from raysect.core.math.function.float cimport Interpolator2DArray - - -cdef class FractionalAbundance(CoreFractionalAbundance): - - def __init__(self, element, ionisation, electron_density, electron_temperature, fractional_abundance, name='', extrapolate=False): - - super().__init__(element, ionisation, name) - - self.raw_data = {'ne': np.array(electron_density, np.float64), - 'te': np.array(electron_temperature, np.float64), - 'fractional_abundance': np.array(fractional_abundance, np.float64)} - - # store limits of data - self.density_range = self.raw_data['ne'].min(), self.raw_data['ne'].max() - self.temperature_range = self.raw_data['te'].min(), self.raw_data['te'].max() - - # interpolate fractional abundance - extrapolation_type = 'linear' if extrapolate else 'none' - self._abundance_func = Interpolator2DArray(self.raw_data['ne'], self.raw_data['te'], self.raw_data['fractional_abundance'], - 'cubic', extrapolation_type, INFINITY, INFINITY) - - cdef double evaluate(self, double electron_density, double electron_temperature) except? -1e999: - - # prevent negative values (possible if extrapolation enabled) - return max(0, self._abundance_func.evaluate(electron_density, electron_temperature)) \ No newline at end of file diff --git a/cherab/adas/rates/radiated_power.pxd b/cherab/adas/rates/radiated_power.pxd deleted file mode 100644 index 92f4087..0000000 --- a/cherab/adas/rates/radiated_power.pxd +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from cherab.core.atomic.rates cimport TotalRadiatedPower as CoreTotalRadiatedPower -from cherab.core.math cimport Function2D - - -cdef class TotalRadiatedPower(CoreTotalRadiatedPower): - - cdef: - readonly dict raw_data - readonly tuple density_range, temperature_range - readonly Function2D _rate - diff --git a/cherab/adas/rates/radiated_power.pyx b/cherab/adas/rates/radiated_power.pyx deleted file mode 100644 index a7e72b3..0000000 --- a/cherab/adas/rates/radiated_power.pyx +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import numpy as np -from libc.math cimport INFINITY, log10 - -from raysect.core.math.function.float cimport Interpolator2DArray - - -cdef class TotalRadiatedPower(CoreTotalRadiatedPower): - - def __init__(self, element, electron_density, electron_temperature, radiated_power, extrapolate=False): - - super().__init__(element) - - self.raw_data = {'ne': np.array(electron_density, np.float64), - 'te': np.array(electron_temperature, np.float64), - 'rate': np.array(radiated_power, np.float64)} - - # store limits of data - self.density_range = self.raw_data['ne'].min(), self.raw_data['ne'].max() - self.temperature_range = self.raw_data['te'].min(), self.raw_data['te'].max() - - # interpolate rate - # using nearest extrapolation to avoid infinite values at 0 for some rates - extrapolation_type = 'nearest' if extrapolate else 'none' - self._rate = Interpolator2DArray(np.log10(self.raw_data['ne']), np.log10(self.raw_data['te']), np.log10(self.raw_data['rate']), - 'cubic', extrapolation_type, INFINITY, INFINITY) - - cdef double evaluate(self, double electron_density, double electron_temperature) except? -1e999: - - # need to handle zeros, also density and temperature can become negative due to cubic interpolation - if electron_density < 1.e-300: - electron_density = 1.e-300 - - if electron_temperature < 1.e-300: - electron_temperature = 1.e-300 - - # calculate rate and convert from log10 space to linear space - return 10 ** self._rate.evaluate(log10(electron_density), log10(electron_temperature)) diff --git a/cherab/adas/repository/__init__.py b/cherab/adas/repository/__init__.py deleted file mode 100644 index 79cc1b9..0000000 --- a/cherab/adas/repository/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from .beam import * -from .pec import * -from .atomic import * -from .wavelength import * -from .radiated_power import * -from .utility import DEFAULT_REPOSITORY_PATH -from .create import populate diff --git a/cherab/adas/repository/atomic.py b/cherab/adas/repository/atomic.py deleted file mode 100644 index ae2f381..0000000 --- a/cherab/adas/repository/atomic.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - - -import cherab.openadas.repository.atomic as _atomic -from .utility import repository_path_decorator - - -add_ionisation_rate = repository_path_decorator(_atomic.add_ionisation_rate) -update_ionisation_rates = repository_path_decorator(_atomic.update_ionisation_rates) -get_ionisation_rate = repository_path_decorator(_atomic.get_ionisation_rate) - -add_recombination_rate = repository_path_decorator(_atomic.add_recombination_rate) -update_recombination_rates = repository_path_decorator(_atomic.update_recombination_rates) -get_recombination_rate = repository_path_decorator(_atomic.get_recombination_rate) - -add_thermal_cx_rate = repository_path_decorator(_atomic.add_thermal_cx_rate) -update_thermal_cx_rates = repository_path_decorator(_atomic.update_thermal_cx_rates) -get_thermal_cx_rate = repository_path_decorator(_atomic.get_thermal_cx_rate) diff --git a/cherab/adas/repository/beam/__init__.py b/cherab/adas/repository/beam/__init__.py deleted file mode 100644 index a00c68e..0000000 --- a/cherab/adas/repository/beam/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from .cx import * -from .stopping import * -from .population import * -from .emission import * diff --git a/cherab/adas/repository/beam/cx.py b/cherab/adas/repository/beam/cx.py deleted file mode 100644 index e585a90..0000000 --- a/cherab/adas/repository/beam/cx.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import cherab.openadas.repository.beam.cx as _beam_cx -from ..utility import repository_path_decorator - - -add_beam_cx_rate = repository_path_decorator(_beam_cx.add_beam_cx_rate) -update_beam_cx_rates = repository_path_decorator(_beam_cx.update_beam_cx_rates) -get_beam_cx_rates = repository_path_decorator(_beam_cx.get_beam_cx_rates) diff --git a/cherab/adas/repository/beam/emission.py b/cherab/adas/repository/beam/emission.py deleted file mode 100644 index 24296bc..0000000 --- a/cherab/adas/repository/beam/emission.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import cherab.openadas.repository.beam.emission as _beam_emission -from ..utility import repository_path_decorator - - -add_beam_emission_rate = repository_path_decorator(_beam_emission.add_beam_emission_rate) -update_beam_emission_rates = repository_path_decorator(_beam_emission.update_beam_emission_rates) -get_beam_emission_rate = repository_path_decorator(_beam_emission.get_beam_emission_rate) diff --git a/cherab/adas/repository/beam/population.py b/cherab/adas/repository/beam/population.py deleted file mode 100644 index d7e6850..0000000 --- a/cherab/adas/repository/beam/population.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import cherab.openadas.repository.beam.population as _beam_population -from ..utility import repository_path_decorator - - -add_beam_population_rate = repository_path_decorator(_beam_population.add_beam_population_rate) -update_beam_population_rates = repository_path_decorator(_beam_population.update_beam_population_rates) -get_beam_population_rate = repository_path_decorator(_beam_population.get_beam_population_rate) diff --git a/cherab/adas/repository/beam/stopping.py b/cherab/adas/repository/beam/stopping.py deleted file mode 100644 index 23c5a6f..0000000 --- a/cherab/adas/repository/beam/stopping.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import cherab.openadas.repository.beam.stopping as _beam_stopping -from ..utility import repository_path_decorator - - -add_beam_stopping_rate = repository_path_decorator(_beam_stopping.add_beam_stopping_rate) -update_beam_stopping_rates = repository_path_decorator(_beam_stopping.update_beam_stopping_rates) -get_beam_stopping_rate = repository_path_decorator(_beam_stopping.get_beam_stopping_rate) diff --git a/cherab/adas/repository/create.py b/cherab/adas/repository/create.py deleted file mode 100644 index 3528679..0000000 --- a/cherab/adas/repository/create.py +++ /dev/null @@ -1,395 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the 'Licence'); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an 'AS IS' basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -from cherab.core.utility import RecursiveDict -from cherab.core.atomic.elements import * -from cherab.adas.install import install_files -from cherab.adas import repository - - -def populate(repository_path=None, adas_home=None): - ''' - Populates the ADAS repository with a typical set of rates and wavelengths. - - :param repository_path: Alternate path for the ADAS repository (default=None). - :param adas_home: Alternate path to ADAS home directory (default=None) . - ''' - - # install a common selection of open adas files - rates = { - 'adf11scd': ( - (hydrogen, 'adas/adf11/scd12/scd12_h.dat'), - (helium, 'adas/adf11/scd96/scd96_he.dat'), - (lithium, 'adas/adf11/scd96/scd96_li.dat'), - (beryllium, 'adas/adf11/scd96/scd96_be.dat'), - (boron, 'adas/adf11/scd89/scd89_b.dat'), - (carbon, 'adas/adf11/scd96/scd96_c.dat'), - (nitrogen, 'adas/adf11/scd96/scd96_n.dat'), - (oxygen, 'adas/adf11/scd96/scd96_o.dat'), - (neon, 'adas/adf11/scd96/scd96_ne.dat'), - (argon, 'adas/adf11/scd89/scd89_ar.dat'), - (krypton, 'adas/adf11/scd89/scd89_kr.dat'), - (xenon, 'adas/adf11/scd89/scd89_xe.dat'), - ), - 'adf11acd': ( - (hydrogen, 'adas/adf11/acd12/acd12_h.dat'), - (helium, 'adas/adf11/acd96/acd96_he.dat'), - (lithium, 'adas/adf11/acd96/acd96_li.dat'), - (beryllium, 'adas/adf11/acd96/acd96_be.dat'), - (boron, 'adas/adf11/acd89/acd89_b.dat'), - (carbon, 'adas/adf11/acd96/acd96_c.dat'), - (nitrogen, 'adas/adf11/acd96/acd96_n.dat'), - (oxygen, 'adas/adf11/acd96/acd96_o.dat'), - (neon, 'adas/adf11/acd96/acd96_ne.dat'), - (argon, 'adas/adf11/acd89/acd89_ar.dat'), - (krypton, 'adas/adf11/acd89/acd89_kr.dat'), - (xenon, 'adas/adf11/acd89/acd89_xe.dat'), - ), - 'adf11ccd': ( - # (donor_element, donor_charge, receiver_element, file_path) - (hydrogen, 0, hydrogen, 'adas/adf11/ccd96/ccd96_h.dat'), - (hydrogen, 0, helium, 'adas/adf11/ccd96/ccd96_he.dat'), - (hydrogen, 0, lithium, 'adas/adf11/ccd89/ccd89_li.dat'), - (hydrogen, 0, beryllium, 'adas/adf11/ccd89/ccd89_be.dat'), - (hydrogen, 0, boron, 'adas/adf11/ccd89/ccd89_b.dat'), - (hydrogen, 0, carbon, 'adas/adf11/ccd96/ccd96_c.dat'), - (hydrogen, 0, nitrogen, 'adas/adf11/ccd89/ccd89_n.dat'), - (hydrogen, 0, oxygen, 'adas/adf11/ccd89/ccd89_o.dat'), - (hydrogen, 0, neon, 'adas/adf11/ccd89/ccd89_ne.dat'), - (hydrogen, 0, argon, 'adas/adf11/ccd89/ccd89_ar.dat'), - (hydrogen, 0, krypton, 'adas/adf11/ccd89/ccd89_kr.dat'), - (hydrogen, 0, xenon, 'adas/adf11/ccd89/ccd89_xe.dat'), - ), - 'adf11plt': ( - (hydrogen, 'adas/adf11/plt12/plt12_h.dat'), - (helium, 'adas/adf11/plt96/plt96_he.dat'), - (lithium, 'adas/adf11/plt96/plt96_li.dat'), - (beryllium, 'adas/adf11/plt96/plt96_be.dat'), - (boron, 'adas/adf11/plt89/plt89_b.dat'), - (carbon, 'adas/adf11/plt96/plt96_c.dat'), - (nitrogen, 'adas/adf11/plt96/plt96_n.dat'), - (oxygen, 'adas/adf11/plt96/plt96_o.dat'), - (neon, 'adas/adf11/plt96/plt96_ne.dat'), - (argon, 'adas/adf11/plt40/plt40_ar.dat'), - (krypton, 'adas/adf11/plt89/plt89_kr.dat'), - (xenon, 'adas/adf11/plt89/plt89_xe.dat') - ), - 'adf11prb': ( - (hydrogen, 'adas/adf11/prb12/prb12_h.dat'), - (helium, 'adas/adf11/prb96/prb96_he.dat'), - (lithium, 'adas/adf11/prb96/prb96_li.dat'), - (beryllium, 'adas/adf11/prb96/prb96_be.dat'), - (boron, 'adas/adf11/prb89/prb89_b.dat'), - (carbon, 'adas/adf11/prb96/prb96_c.dat'), - (nitrogen, 'adas/adf11/prb96/prb96_n.dat'), - (oxygen, 'adas/adf11/prb96/prb96_o.dat'), - (neon, 'adas/adf11/prb96/prb96_ne.dat'), - (argon, 'adas/adf11/prb89/prb89_ar.dat'), - (krypton, 'adas/adf11/prb89/prb89_kr.dat'), - (xenon, 'adas/adf11/prb89/prb89_xe.dat') - ), - 'adf11prc': ( - (hydrogen, 'adas/adf11/prc96/prc96_h.dat'), - (helium, 'adas/adf11/prc96/prc96_he.dat'), - (lithium, 'adas/adf11/prc89/prc89_li.dat'), - (beryllium, 'adas/adf11/prc89/prc89_be.dat'), - (boron, 'adas/adf11/prc89/prc89_b.dat'), - (carbon, 'adas/adf11/prc96/prc96_c.dat'), - (nitrogen, 'adas/adf11/prc89/prc89_n.dat'), - (oxygen, 'adas/adf11/prc89/prc89_o.dat'), - (neon, 'adas/adf11/prc89/prc89_ne.dat'), - (argon, 'adas/adf11/prc89/prc89_ar.dat'), - (krypton, 'adas/adf11/prc89/prc89_kr.dat'), - (xenon, 'adas/adf11/prc89/prc89_xe.dat') - ), - 'adf12': ( - # (donor, receiver, ionisation, donor_metastable, rate file) - (hydrogen, 1, hydrogen, 1, 'adas/adf12/qef93#h/qef93#h_h1.dat'), - (hydrogen, 1, helium, 2, 'adas/adf12/qef93#h/qef93#h_he2.dat'), - (hydrogen, 2, helium, 2, 'adas/adf12/qef97#h/qef97#h_en2_kvi#he2.dat'), - (hydrogen, 1, beryllium, 4, 'adas/adf12/qef93#h/qef93#h_be4.dat'), - (hydrogen, 2, beryllium, 4, 'adas/adf12/qef97#h/qef97#h_en2_kvi#be4.dat'), - (hydrogen, 1, boron, 5, 'adas/adf12/qef93#h/qef93#h_b5.dat'), - (hydrogen, 2, boron, 5, 'adas/adf12/qef97#h/qef97#h_en2_kvi#b5.dat'), - (hydrogen, 1, carbon, 6, 'adas/adf12/qef93#h/qef93#h_c6.dat'), - (hydrogen, 2, carbon, 6, 'adas/adf12/qef97#h/qef97#h_en2_kvi#c6.dat'), - (hydrogen, 1, neon, 10, 'adas/adf12/qef93#h/qef93#h_ne10.dat'), - (hydrogen, 2, neon, 10, 'adas/adf12/qef97#h/qef97#h_en2_kvi#ne10.dat') - ), - 'adf15': ( - (hydrogen, 0, 'adas/adf15/pec12#h/pec12#h_pju#h0.dat'), - (helium, 0, 'adas/adf15/pec96#he/pec96#he_pju#he0.dat'), - (helium, 1, 'adas/adf15/pec96#he/pec96#he_pju#he1.dat'), - (beryllium, 0, 'adas/adf15/pec96#be/pec96#be_pju#be0.dat'), - (beryllium, 1, 'adas/adf15/pec96#be/pec96#be_pju#be1.dat'), - (beryllium, 2, 'adas/adf15/pec96#be/pec96#be_pju#be2.dat'), - (beryllium, 3, 'adas/adf15/pec96#be/pec96#be_pju#be3.dat'), - (carbon, 0, 'adas/adf15/pec96#c/pec96#c_vsu#c0.dat'), - (carbon, 1, 'adas/adf15/pec96#c/pec96#c_vsu#c1.dat'), - (carbon, 2, 'adas/adf15/pec96#c/pec96#c_vsu#c2.dat'), - # (neon, 0, 'adas/adf15/pec96#ne/pec96#ne_pju#ne0.dat'), #TODO: OPENADAS DATA CORRUPT - # (neon, 1, 'adas/adf15/pec96#ne/pec96#ne_pju#ne1.dat'), #TODO: OPENADAS DATA CORRUPT - (nitrogen, 0, 'adas/adf15/pec96#n/pec96#n_vsu#n0.dat'), - (nitrogen, 1, 'adas/adf15/pec96#n/pec96#n_vsu#n1.dat'), - # (nitrogen, 2, 'adas/adf15/pec96#n/pec96#n_vsu#n2.dat'), #TODO: OPENADAS DATA CORRUPT - ), - 'adf21': ( - # (beam_species, target_ion, target_ionisation, rate file) - (hydrogen, hydrogen, 1, 'adas/adf21/bms97#h/bms97#h_h1.dat'), - (hydrogen, helium, 2, 'adas/adf21/bms97#h/bms97#h_he2.dat'), - (hydrogen, lithium, 3, 'adas/adf21/bms97#h/bms97#h_li3.dat'), - (hydrogen, beryllium, 4, 'adas/adf21/bms97#h/bms97#h_be4.dat'), - (hydrogen, boron, 5, 'adas/adf21/bms97#h/bms97#h_b5.dat'), - (hydrogen, carbon, 6, 'adas/adf21/bms97#h/bms97#h_c6.dat'), - (hydrogen, nitrogen, 7, 'adas/adf21/bms97#h/bms97#h_n7.dat'), - (hydrogen, oxygen, 8, 'adas/adf21/bms97#h/bms97#h_o8.dat'), - (hydrogen, fluorine, 9, 'adas/adf21/bms97#h/bms97#h_f9.dat'), - (hydrogen, neon, 10, 'adas/adf21/bms97#h/bms97#h_ne10.dat'), - ), - 'adf22bmp': ( - # (beam species, beam metastable, target ion, target ionisation, rate file) - (hydrogen, 2, hydrogen, 1, 'adas/adf22/bmp97#h/bmp97#h_2_h1.dat'), - (hydrogen, 3, hydrogen, 1, 'adas/adf22/bmp97#h/bmp97#h_3_h1.dat'), - (hydrogen, 4, hydrogen, 1, 'adas/adf22/bmp97#h/bmp97#h_4_h1.dat'), - (hydrogen, 2, helium, 2, 'adas/adf22/bmp97#h/bmp97#h_2_he2.dat'), - (hydrogen, 3, helium, 2, 'adas/adf22/bmp97#h/bmp97#h_3_he2.dat'), - (hydrogen, 4, helium, 2, 'adas/adf22/bmp97#h/bmp97#h_4_he2.dat'), - (hydrogen, 2, lithium, 3, 'adas/adf22/bmp97#h/bmp97#h_2_li3.dat'), - (hydrogen, 3, lithium, 3, 'adas/adf22/bmp97#h/bmp97#h_3_li3.dat'), - (hydrogen, 4, lithium, 3, 'adas/adf22/bmp97#h/bmp97#h_4_li3.dat'), - (hydrogen, 2, beryllium, 4, 'adas/adf22/bmp97#h/bmp97#h_2_be4.dat'), - (hydrogen, 3, beryllium, 4, 'adas/adf22/bmp97#h/bmp97#h_3_be4.dat'), - (hydrogen, 4, beryllium, 4, 'adas/adf22/bmp97#h/bmp97#h_4_be4.dat'), - (hydrogen, 2, boron, 5, 'adas/adf22/bmp97#h/bmp97#h_2_b5.dat'), - (hydrogen, 3, boron, 5, 'adas/adf22/bmp97#h/bmp97#h_3_b5.dat'), - (hydrogen, 4, boron, 5, 'adas/adf22/bmp97#h/bmp97#h_4_b5.dat'), - (hydrogen, 2, carbon, 6, 'adas/adf22/bmp97#h/bmp97#h_2_c6.dat'), - (hydrogen, 3, carbon, 6, 'adas/adf22/bmp97#h/bmp97#h_3_c6.dat'), - (hydrogen, 4, carbon, 6, 'adas/adf22/bmp97#h/bmp97#h_4_c6.dat'), - (hydrogen, 2, nitrogen, 7, 'adas/adf22/bmp97#h/bmp97#h_2_n7.dat'), - (hydrogen, 3, nitrogen, 7, 'adas/adf22/bmp97#h/bmp97#h_3_n7.dat'), - (hydrogen, 4, nitrogen, 7, 'adas/adf22/bmp97#h/bmp97#h_4_n7.dat'), - (hydrogen, 2, oxygen, 8, 'adas/adf22/bmp97#h/bmp97#h_2_o8.dat'), - (hydrogen, 3, oxygen, 8, 'adas/adf22/bmp97#h/bmp97#h_3_o8.dat'), - (hydrogen, 4, oxygen, 8, 'adas/adf22/bmp97#h/bmp97#h_4_o8.dat'), - (hydrogen, 2, fluorine, 9, 'adas/adf22/bmp97#h/bmp97#h_2_f9.dat'), - (hydrogen, 3, fluorine, 9, 'adas/adf22/bmp97#h/bmp97#h_3_f9.dat'), - (hydrogen, 4, fluorine, 9, 'adas/adf22/bmp97#h/bmp97#h_4_f9.dat'), - (hydrogen, 2, neon, 10, 'adas/adf22/bmp97#h/bmp97#h_2_ne10.dat'), - (hydrogen, 3, neon, 10, 'adas/adf22/bmp97#h/bmp97#h_3_ne10.dat'), - (hydrogen, 4, neon, 10, 'adas/adf22/bmp97#h/bmp97#h_4_ne10.dat'), - ), - 'adf22bme': ( - # (beam species, target_ion, target_ionisation, (initial_level, final_level), rate file) - (hydrogen, hydrogen, 1, (3, 2), 'adas/adf22/bme10#h/bme10#h_h1.dat'), - (hydrogen, helium, 2, (3, 2), 'adas/adf22/bme97#h/bme97#h_he2.dat'), - (hydrogen, lithium, 3, (3, 2), 'adas/adf22/bme97#h/bme97#h_li3.dat'), - (hydrogen, beryllium, 4, (3, 2), 'adas/adf22/bme97#h/bme97#h_be4.dat'), - (hydrogen, boron, 5, (3, 2), 'adas/adf22/bme97#h/bme97#h_b5.dat'), - (hydrogen, carbon, 6, (3, 2), 'adas/adf22/bme97#h/bme97#h_c6.dat'), - (hydrogen, nitrogen, 7, (3, 2), 'adas/adf22/bme97#h/bme97#h_n7.dat'), - (hydrogen, oxygen, 8, (3, 2), 'adas/adf22/bme97#h/bme97#h_o8.dat'), - (hydrogen, fluorine, 9, (3, 2), 'adas/adf22/bme97#h/bme97#h_f9.dat'), - (hydrogen, neon, 10, (3, 2), 'adas/adf22/bme97#h/bme97#h_ne10.dat'), - (hydrogen, argon, 18, (3, 2), 'adas/adf22/bme99#h/bme99#h_ar18.dat'), - ) - } - - # add common wavelengths to the repository - wavelengths = RecursiveDict() - - # H0, from the NIST Atomic Spectra Database - # Vacuum (< 200 nm), Air (200 - 2000 nm), Vacuum (> 2000 nm) - wavelengths[hydrogen][0] = { - (2, 1): 121.567, - (3, 1): 102.573, - (3, 2): 656.279, - (4, 1): 97.252, - (4, 2): 486.135, - (4, 3): 1875.130, - (5, 1): 94.974, - (5, 2): 434.047, - (5, 3): 1281.807, - (5, 4): 4052.279, - (6, 1): 93.781, - (6, 2): 410.173, - (6, 3): 1093.817, - (6, 4): 2625.871, - (6, 5): 7459.900, - (7, 1): 93.075, - (7, 2): 397.008, - (7, 3): 1004.98, - (7, 4): 2166.118, - (7, 5): 4653.780, - (7, 6): 12371.912, - (8, 1): 92.625, - (8, 2): 388.906, - (8, 3): 954.620, - (8, 4): 1944.558, # Ritz - (8, 5): 3740.576, - (8, 6): 7502.440, - (8, 7): 19061.960, - (9, 1): 92.315, - (9, 2): 383.540, - (9, 3): 922.970, - (9, 4): 1817.424, - (9, 5): 3296.980, - (9, 6): 5908.220, # Ritz - (9, 7): 11308.681, - (9, 8): 27803.50, - (10, 1): 92.095, - (10, 2): 379.791, - (10, 3): 901.530, - (10, 4): 1736.214, - (10, 5): 3039.202, # Ritz - (10, 6): 5128.650, - (10, 7): 8760.064, - (10, 8): 16209.09, # Ritz - (10, 9): 38869.79, # Ritz - (11, 1): 91.934, - (11, 2): 377.063, - (11, 3): 886.289, - (11, 4): 1680.651, - (11, 5): 2872.996, # Ritz - (11, 6): 4672.512, # Ritz - (11, 7): 7508.107, # Ritz - (11, 8): 12387.153, - (11, 9): 22340.42, # Ritz - (11, 10): 52534.80, # Ritz - (12, 1): 91.813, - (12, 2): 375.015, - (12, 3): 875.046, - (12, 4): 1640.688, - (12, 5): 2758.268, - (12, 6): 4376.458, # Ritz - (12, 7): 6771.992, # Ritz - (12, 8): 10503.507, - (12, 9): 16880.61, # Ritz - (12, 10): 29839.49, # Ritz - (12, 11): 69071.70, - } - - me = 5.48579909e-4 # electron mass in a.u. - mh = protium.atomic_weight - md = deuterium.atomic_weight - mt = tritium.atomic_weight - - # D0, from H0 using the equation dLambda/Lambda = -me/mh*(1-mh/md) - wavelengths[deuterium][0] = {key: round(value * (1. - me / mh * (1. - mh / md)), 3) for key, value in wavelengths[hydrogen][0].items()} - - # Some D0 (observed) wavelengths are available in the NIST database - wavelengths[deuterium][0][(2, 1)] = 121.534 - wavelengths[deuterium][0][(4, 2)] = 486.000 - wavelengths[deuterium][0][(5, 2)] = 433.928 - wavelengths[deuterium][0][(6, 2)] = 410.062 - wavelengths[deuterium][0][(7, 2)] = 396.899 - wavelengths[deuterium][0][(8, 2)] = 388.799 - wavelengths[deuterium][0][(9, 2)] = 383.434 - - # T0, from H0 using the equation dLambda/Lambda = -me/mh*(1-mh/mt) - wavelengths[tritium][0] = {key: round(value * (1. - me / mh * (1. - mh / mt)), 3) for key, value in wavelengths[hydrogen][0].items()} - - # He1+ - wavelengths[helium][1] = { - (2, 1): 30.378, # 2p -> 1s - (3, 1): 25.632, # 3p -> 1s - (3, 2): 164.04, # 3d -> 2p - (4, 2): 121.51, # 4d -> 2p - (4, 3): 468.71, # 4f -> 3d - (5, 3): 320.28, # 5f -> 3d - (5, 4): 1012.65, # 5g -> 4f - (6, 4): 656.20, # 6g -> 4f - (6, 5): 1864.20, # 6h -> 5g - (7, 5): 1162.53, # from ADAS comment, unknown source - (7, 6): 3090.55 # from ADAS comment, unknown source - } - - # Be3+ - wavelengths[beryllium][3] = { - (3, 1): 6.4065, # 3p -> 1s - (3, 2): 41.002, # 3d -> 2p - (4, 2): 30.373, # 4d -> 2p - (4, 3): 117.16, # 4f -> 3d - (5, 3): 80.092, # 5f -> 3d - (5, 4): 253.14, # 5g -> 4f - (6, 4): 164.03, # 6g -> 4f - (6, 5): 466.01, # 6h -> 5g - (7, 5): 290.62, # from ADAS comment, unknown source - (7, 6): 772.62, # from ADAS comment, unknown source - (8, 6): 468.53, # from ADAS comment, unknown source - (8, 7): 1190.42 # from ADAS comment, unknown source - } - - # B4+ - wavelengths[boron][4] = { - (3, 1): 4.0996, # 3p -> 1s - (3, 2): 26.238, # 3d -> 2p - (4, 2): 19.437, # 4d -> 2p - (4, 3): 74.980, # 4f -> 3d - (5, 3): 51.257, # 5f -> 3d - (5, 4): 162.00, # 5g -> 4f - (6, 4): 104.98, # 6g -> 4f - (6, 5): 298.24, # 6h -> 5g - (7, 5): 186.05, # 7h -> 5g - (7, 6): 494.48, # 7i -> 6h - (8, 6): 299.86, # 8i -> 6h - (8, 7): 761.87, # 8k -> 7i - (9, 7): 451.99, # 9k -> 7i - (9, 8): 1111.25 # from ADAS comment, unknown source - } - - # C5+ - wavelengths[carbon][5] = { - (4, 2): 13.496, # 4d -> 2p - (4, 3): 52.067, # 4f -> 3d - (5, 3): 35.594, # 5f -> 3d - (5, 4): 112.50, # 5g -> 4f - (6, 4): 72.900, # 6g -> 4f - (6, 5): 207.11, # 6h -> 5g - (7, 5): 129.20, # from ADAS comment, unknown source - (7, 6): 343.38, # from ADAS comment, unknown source - (8, 6): 208.23, # from ADAS comment, unknown source - (8, 7): 529.07, # from ADAS comment, unknown source - (9, 7): 313.87, # from ADAS comment, unknown source - (9, 8): 771.69, # from ADAS comment, unknown source - (10, 8): 449.89, # from ADAS comment, unknown source - (10, 9): 1078.86 # from ADAS comment, unknown source - } - - # Ne9+ - wavelengths[neon][9] = { - (6, 5): 74.54, # from ADAS comment, unknown source - (7, 6): 123.64, # from ADAS comment, unknown source - (8, 7): 190.50, # from ADAS comment, unknown source - (9, 8): 277.79, # from ADAS comment, unknown source - (10, 9): 388.37, # from ADAS comment, unknown source - (11, 10): 524.92, # from ADAS comment, unknown source - (12, 11): 690.16, # from ADAS comment, unknown source - (13, 12): 886.83, # from ADAS comment, unknown source - (6, 4): 26.24, # from ADAS comment, unknown source - (7, 5): 46.51, # from ADAS comment, unknown source - (8, 6): 74.98, # from ADAS comment, unknown source - (9, 7): 113.02, # from ADAS comment, unknown source - (10, 8): 162.00, # from ADAS comment, unknown source - (11, 9): 223.22, # from ADAS comment, unknown source - (12, 10): 298.15, # from ADAS comment, unknown source - (13, 11): 388.12 # from ADAS comment, unknown source - } - - install_files(rates, repository_path=repository_path, adas_home=adas_home) - repository.update_wavelengths(wavelengths, repository_path=repository_path) diff --git a/cherab/adas/repository/pec.py b/cherab/adas/repository/pec.py deleted file mode 100644 index cfa6bb1..0000000 --- a/cherab/adas/repository/pec.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import cherab.openadas.repository.pec as _pec -from .utility import repository_path_decorator - - -add_pec_excitation_rate = repository_path_decorator(_pec.add_pec_excitation_rate) -get_pec_excitation_rate = repository_path_decorator(_pec.get_pec_excitation_rate) - -add_pec_recombination_rate = repository_path_decorator(_pec.add_pec_recombination_rate) -get_pec_recombination_rate = repository_path_decorator(_pec.get_pec_recombination_rate) - -add_pec_thermalcx_rate = repository_path_decorator(_pec.add_pec_thermalcx_rate) -get_pec_thermalcx_rate = repository_path_decorator(_pec.get_pec_thermalcx_rate) - -update_pec_rates = repository_path_decorator(_pec.update_pec_rates) diff --git a/cherab/adas/repository/radiated_power.py b/cherab/adas/repository/radiated_power.py deleted file mode 100644 index d58d4cd..0000000 --- a/cherab/adas/repository/radiated_power.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - - -import cherab.openadas.repository.radiated_power as _radiated_power -from .utility import repository_path_decorator - - -add_line_power_rate = repository_path_decorator(_radiated_power.add_line_power_rate) -update_line_power_rates = repository_path_decorator(_radiated_power.update_line_power_rates) -get_line_radiated_power_rate = repository_path_decorator(_radiated_power.get_line_radiated_power_rate) - -add_continuum_power_rate = repository_path_decorator(_radiated_power.add_continuum_power_rate) -update_continuum_power_rates = repository_path_decorator(_radiated_power.update_continuum_power_rates) -get_continuum_radiated_power_rate = repository_path_decorator(_radiated_power.get_continuum_radiated_power_rate) - -add_cx_power_rate = repository_path_decorator(_radiated_power.add_cx_power_rate) -update_cx_power_rates = repository_path_decorator(_radiated_power.update_cx_power_rates) -get_cx_radiated_power_rate = repository_path_decorator(_radiated_power.get_cx_radiated_power_rate) diff --git a/cherab/adas/repository/utility.py b/cherab/adas/repository/utility.py deleted file mode 100644 index f721a1d..0000000 --- a/cherab/adas/repository/utility.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import os -from inspect import signature -from functools import wraps -from cherab.openadas.repository.utility import encode_transition, valid_charge - - -DEFAULT_REPOSITORY_PATH = os.path.expanduser('~/.cherab/adas/repository') - - -def repository_path_decorator(f): - - @wraps(f) - def wrapper(*args, **kwargs): - if len(args) == len(signature(f).parameters): # repository_path is passed in args - if not args[-1]: # repository_path is None - kwargs['repository_path'] = DEFAULT_REPOSITORY_PATH - return f(*args[:-1], **kwargs) - - return f(*args, **kwargs) # repository_path is not None - - try: # repository_path is passed in kwargs - kwargs['repository_path'] = kwargs['repository_path'] or DEFAULT_REPOSITORY_PATH - except KeyError: # repository_path is not passed - kwargs['repository_path'] = DEFAULT_REPOSITORY_PATH - - return f(*args, **kwargs) - - return wrapper diff --git a/cherab/adas/repository/wavelength.py b/cherab/adas/repository/wavelength.py deleted file mode 100644 index 442e0e8..0000000 --- a/cherab/adas/repository/wavelength.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas -# -# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the -# European Commission - subsequent versions of the EUPL (the "Licence"); -# You may not use this work except in compliance with the Licence. -# You may obtain a copy of the Licence at: -# -# https://joinup.ec.europa.eu/software/page/eupl5 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. -# -# See the Licence for the specific language governing permissions and limitations -# under the Licence. - -import cherab.openadas.repository.wavelength as _wavelength -from .utility import repository_path_decorator - - -add_wavelength = repository_path_decorator(_wavelength.add_wavelength) -update_wavelengths = repository_path_decorator(_wavelength.update_wavelengths) -get_wavelength = repository_path_decorator(_wavelength.get_wavelength) diff --git a/demos/fractional_abundance.py b/demos/fractional_abundance.py index c956508..f477ff6 100644 --- a/demos/fractional_abundance.py +++ b/demos/fractional_abundance.py @@ -19,12 +19,15 @@ import matplotlib.pyplot as plt from cherab.core.atomic import neon -from cherab.adas import ADAS +from cherab.atomic import AtomicData +from cherab.adas import install_fractional_abundances print("testing fraction abundance for Neon") -atomic_data = ADAS() +install_fractional_abundances(neon) + +atomic_data = AtomicData() plt.figure() ne0_frac = atomic_data.fractional_abundance(neon, 0) diff --git a/demos/total_radiation.py b/demos/total_radiation.py index ff5059b..fa01c0d 100644 --- a/demos/total_radiation.py +++ b/demos/total_radiation.py @@ -21,12 +21,15 @@ from cherab.core.atomic import neon from cherab.core.math import sample2d_grid -from cherab.adas import ADAS +from cherab.atomic import AtomicData +from cherab.adas import install_total_power_rate print("Testing total radiation for Neon.") -atomic_data = ADAS() +install_total_power_rate(neon) + +atomic_data = AtomicData() electron_density = 1.e19 electron_temperature = np.geomspace(1, 10000, 81) diff --git a/demos/zeeman_splitting.py b/demos/zeeman_splitting.py index 4eacaf8..12d48db 100755 --- a/demos/zeeman_splitting.py +++ b/demos/zeeman_splitting.py @@ -28,13 +28,22 @@ from cherab.core import Species, Maxwellian, Plasma, Line from cherab.core.atomic.elements import deuterium, beryllium from cherab.core.model import ExcitationLine, RecombinationLine, ZeemanMultiplet -from cherab.adas import ADAS +from cherab.atomic import AtomicData from cherab.tools.plasmas import GaussianVolume +from cherab.adas import install_zeeman_structures # Uncomment this if local ADAS respository is not populated # from cherab.adas.repository import populate # populate() +# setup D-alpha line +deuterium_I_656 = Line(deuterium, 0, (3, 2)) # n = 3->2: 656.1nm + +# setup Be II 527 nm line +beryllium_II_527 = Line(beryllium, 1, ("4s1 2s0.5", "3p1 2p2.5")) # 527 nm + +install_zeeman_structures(lines=[deuterium_I_656, beryllium_II_527], adas_fort=None, repository_path=None) + # tunables ion_density = 1e19 sigma = 0.25 @@ -43,7 +52,7 @@ world = World() # create atomic data source -adas = ADAS(permit_extrapolation=True) +adas = AtomicData(permit_extrapolation=True) # PLASMA ---------------------------------------------------------------------- plasma = Plasma(parent=world) @@ -80,12 +89,6 @@ plasma.electron_distribution = e_distribution plasma.composition = [d0_species, d1_species, be1_species, be2_species] -# setup D-alpha line -deuterium_I_656 = Line(deuterium, 0, (3, 2)) # n = 3->2: 656.1nm - -# setup Be II 527 nm line -beryllium_II_527 = Line(beryllium, 1, ("4s1 2s0.5", "3p1 2p2.5")) # 527 nm - # angles between the ray and the magnetic field direction angles = (0., 45., 90.) diff --git a/setup.py b/setup.py index 2438632..d78173d 100644 --- a/setup.py +++ b/setup.py @@ -1,49 +1,11 @@ -from setuptools import setup, find_packages, Extension -from Cython.Build import cythonize +from setuptools import setup, find_packages import sys -import numpy -import os -import os.path as path -import multiprocessing -multiprocessing.set_start_method('fork') - -threads = multiprocessing.cpu_count() -force = False -profile = False -install_rates = False - -if "--force" in sys.argv: - force = True - del sys.argv[sys.argv.index("--force")] - -if "--profile" in sys.argv: - profile = True - del sys.argv[sys.argv.index("--profile")] - -if "--install-rates" in sys.argv: - install_rates = True - del sys.argv[sys.argv.index("--install-rates")] - -compilation_includes = [".", numpy.get_include()] - -setup_path = path.dirname(path.abspath(__file__)) - -# build extension list -extensions = [] -for root, dirs, files in os.walk(setup_path): - for file in files: - if path.splitext(file)[1] == ".pyx": - pyx_file = path.relpath(path.join(root, file), setup_path) - module = path.splitext(pyx_file)[0].replace("/", ".") - extensions.append(Extension(module, [pyx_file], include_dirs=compilation_includes),) - -cython_directives = { - 'language_level': 3 -} -if profile: - cython_directives['profile'] = True +install_data = False +if "--install-data" in sys.argv: + install_data = True + del sys.argv[sys.argv.index("--install-data")] setup( name="cherab-adas", @@ -51,14 +13,13 @@ license="EUPL 1.1", namespace_packages=['cherab'], packages=find_packages(), - include_package_data=True, - ext_modules=cythonize(extensions, nthreads=threads, force=force, compiler_directives=cython_directives) + include_package_data=True ) -# setup a rate repository with common rates -if install_rates: +# add some ADAS data to local atomic repository +if install_data: try: - from cherab.adas import repository - repository.populate() + from cherab.adas import install_zeeman_structures + install_zeeman_structures() except ImportError: pass From 5b3983966f0eb0dd43cb2f8a6fbea49a420ddec0 Mon Sep 17 00:00:00 2001 From: vsnever Date: Mon, 7 Aug 2023 18:44:45 +0300 Subject: [PATCH 2/4] Fix a KeyError in install_fractional_abundances() and an ImportError in the demos. --- cherab/adas/install.py | 2 +- demos/fractional_abundance.py | 2 +- demos/total_radiation.py | 2 +- demos/zeeman_splitting.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cherab/adas/install.py b/cherab/adas/install.py index a82471c..18a8350 100644 --- a/cherab/adas/install.py +++ b/cherab/adas/install.py @@ -388,7 +388,7 @@ def install_fractional_abundances(element, uid='adas', year=96, repository_path= data = {element: {}} for i in range(fractionl_abundances.shape[-1]): - data[element][i] = {'ne': ne, 'te': te, 'fractionl_abundance': fractionl_abundances[:, :, i]} + data[element][i] = {'ne': ne, 'te': te, 'fractional_abundance': fractionl_abundances[:, :, i]} repository.update_fractional_abundances(data, repository_path=repository_path) diff --git a/demos/fractional_abundance.py b/demos/fractional_abundance.py index f477ff6..4aa205a 100644 --- a/demos/fractional_abundance.py +++ b/demos/fractional_abundance.py @@ -20,7 +20,7 @@ from cherab.core.atomic import neon from cherab.atomic import AtomicData -from cherab.adas import install_fractional_abundances +from cherab.adas.install import install_fractional_abundances print("testing fraction abundance for Neon") diff --git a/demos/total_radiation.py b/demos/total_radiation.py index fa01c0d..8344ea9 100644 --- a/demos/total_radiation.py +++ b/demos/total_radiation.py @@ -22,7 +22,7 @@ from cherab.core.atomic import neon from cherab.core.math import sample2d_grid from cherab.atomic import AtomicData -from cherab.adas import install_total_power_rate +from cherab.adas.install import install_total_power_rate print("Testing total radiation for Neon.") diff --git a/demos/zeeman_splitting.py b/demos/zeeman_splitting.py index 12d48db..3da6fcc 100755 --- a/demos/zeeman_splitting.py +++ b/demos/zeeman_splitting.py @@ -30,7 +30,7 @@ from cherab.core.model import ExcitationLine, RecombinationLine, ZeemanMultiplet from cherab.atomic import AtomicData from cherab.tools.plasmas import GaussianVolume -from cherab.adas import install_zeeman_structures +from cherab.adas.install import install_zeeman_structures # Uncomment this if local ADAS respository is not populated # from cherab.adas.repository import populate From 7dedb3ccb3c6fee85b124aa5d15e82e76f4f3a52 Mon Sep 17 00:00:00 2001 From: vsnever Date: Mon, 7 Aug 2023 18:55:03 +0300 Subject: [PATCH 3/4] Fix a KeyError in install_total_power_rate(). --- cherab/adas/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherab/adas/install.py b/cherab/adas/install.py index 18a8350..4c71d32 100644 --- a/cherab/adas/install.py +++ b/cherab/adas/install.py @@ -370,7 +370,7 @@ def install_total_power_rate(element, uid='adas', year=96, repository_path=None) """ ne, te, _, total_power_rate, _, _, _, _ = run_adas405(uid=uid, year=year, elem=element.symbol.lower()) - data = {'ne': ne, 'te': te, 'rate': rate} + data = {'ne': ne, 'te': te, 'rate': total_power_rate} repository.add_total_power_rate(element, data, repository_path=repository_path) From 9501d77deaf9cda62f82c3fe3450473a046bc01c Mon Sep 17 00:00:00 2001 From: vsnever Date: Tue, 8 Aug 2023 18:27:08 +0300 Subject: [PATCH 4/4] Update demos and add comments. --- demos/fractional_abundance.py | 7 ++++--- demos/total_radiation.py | 7 ++++--- demos/zeeman_splitting.py | 17 +++++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/demos/fractional_abundance.py b/demos/fractional_abundance.py index 4aa205a..2fbadb1 100644 --- a/demos/fractional_abundance.py +++ b/demos/fractional_abundance.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -25,6 +25,7 @@ print("testing fraction abundance for Neon") +# install fractional abundance data for neon from ADAS to the atomic data repository install_fractional_abundances(neon) atomic_data = AtomicData() diff --git a/demos/total_radiation.py b/demos/total_radiation.py index 8344ea9..92a68e1 100644 --- a/demos/total_radiation.py +++ b/demos/total_radiation.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -27,6 +27,7 @@ print("Testing total radiation for Neon.") +# install total radiated power data for neon from ADAS to the atomic data repository install_total_power_rate(neon) atomic_data = AtomicData() diff --git a/demos/zeeman_splitting.py b/demos/zeeman_splitting.py index 3da6fcc..1322e7e 100755 --- a/demos/zeeman_splitting.py +++ b/demos/zeeman_splitting.py @@ -1,6 +1,6 @@ -# Copyright 2016-2021 Euratom -# Copyright 2016-2021 United Kingdom Atomic Energy Authority -# Copyright 2016-2021 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# Copyright 2016-2023 Euratom +# Copyright 2016-2023 United Kingdom Atomic Energy Authority +# Copyright 2016-2023 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas # # Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the # European Commission - subsequent versions of the EUPL (the "Licence"); @@ -42,7 +42,8 @@ # setup Be II 527 nm line beryllium_II_527 = Line(beryllium, 1, ("4s1 2s0.5", "3p1 2p2.5")) # 527 nm -install_zeeman_structures(lines=[deuterium_I_656, beryllium_II_527], adas_fort=None, repository_path=None) +# install Zeeman multiplet structure for D-alpha and Be II 527 nm from ADAS to the atomic data repository +install_zeeman_structures(lines=[deuterium_I_656, beryllium_II_527]) # tunables ion_density = 1e19 @@ -52,11 +53,11 @@ world = World() # create atomic data source -adas = AtomicData(permit_extrapolation=True) +atomic_data = AtomicData(permit_extrapolation=True) # PLASMA ---------------------------------------------------------------------- plasma = Plasma(parent=world) -plasma.atomic_data = adas +plasma.atomic_data = atomic_data plasma.geometry = Sphere(sigma * 5.0) plasma.geometry_transform = None plasma.integrator = NumericalIntegrator(step=sigma / 5.0) @@ -93,7 +94,7 @@ angles = (0., 45., 90.) # add ZeemanMultiplet model of D-alpha line to the plasma -zeeman_structure = adas.zeeman_structure(deuterium_I_656) +zeeman_structure = atomic_data.zeeman_structure(deuterium_I_656.element, deuterium_I_656.charge, deuterium_I_656.transition) plasma.models = [ ExcitationLine(deuterium_I_656, lineshape=ZeemanMultiplet, lineshape_args=[zeeman_structure]), @@ -118,7 +119,7 @@ plt.title(r'D$\alpha$ spectrum observed at different angles' + '\nbetween ray and magnetic field') # add ZeemanMultiplet model of Be II 527 nm line to the plasma -zeeman_structure = adas.zeeman_structure(beryllium_II_527) +zeeman_structure = atomic_data.zeeman_structure(beryllium_II_527.element, beryllium_II_527.charge, beryllium_II_527.transition) plasma.models = [ ExcitationLine(beryllium_II_527, lineshape=ZeemanMultiplet, lineshape_args=[zeeman_structure]),