Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cherab/adas/__init__.py
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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
573 changes: 0 additions & 573 deletions cherab/adas/adas.py

This file was deleted.

6 changes: 3 additions & 3 deletions cherab/adas/adas4xx/__init__.py
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
26 changes: 23 additions & 3 deletions cherab/adas/adas4xx/adas405.py
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions cherab/adas/adas6xx/__init__.py
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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
68 changes: 39 additions & 29 deletions cherab/adas/adas6xx/adas603.py
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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
134 changes: 107 additions & 27 deletions cherab/adas/install.py
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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':
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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': total_power_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, 'fractional_abundance': fractionl_abundances[:, :, i]}

repository.update_fractional_abundances(data, repository_path=repository_path)


def _locate_adas_file(file_path, adas_home=None):

path = None
Expand Down
6 changes: 3 additions & 3 deletions cherab/adas/parse/__init__.py
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
20 changes: 0 additions & 20 deletions cherab/adas/rates/__init__.pxd

This file was deleted.

Loading