diff --git a/tardis/analysis/opacities.py b/tardis/analysis/opacities.py index 60d18b37549..4b8428c55b8 100644 --- a/tardis/analysis/opacities.py +++ b/tardis/analysis/opacities.py @@ -1,15 +1,18 @@ """This module provides an opacity calculator class with which the opacities -and optical depth information may be extracted from Tardis runs.""" +and optical depth information may be extracted from Tardis runs. +""" import logging -import numpy as np + import astropy.units as units -from tardis import constants as const +import numpy as np from astropy.modeling.models import Blackbody +from tardis import constants as const + logger = logging.getLogger(__name__) -class opacity_calculator(object): +class opacity_calculator: """Basic Tardis opacity and optical depth calculator Given the model object of a Tardis run and a frequency grid, detailed @@ -223,7 +226,8 @@ def nu_bins(self): @property def kappa_exp(self): """bound-bound opacity according to the expansion opacity formalism per - frequency bin and cell""" + frequency bin and cell + """ if self._kappa_exp is None: self._kappa_exp = self._calc_expansion_opacity() return self._kappa_exp @@ -272,7 +276,8 @@ def planck_delta_tau(self): @property def planck_tau(self): """Planck-mean optical depth, integrated from the surface to - corresponding inner shell radius""" + corresponding inner shell radius + """ if self._planck_tau is None: planck_tau = self._calc_integrated_planck_optical_depth() self._planck_tau = planck_tau @@ -297,7 +302,6 @@ def _calc_expansion_opacity(self): kappa_exp : astropy.units.Quantity ndarray expansion opacity array (shape Nbins x Nshells) """ - index = self.mdl.plasma.tau_sobolevs.index line_waves = self.mdl.plasma.atomic_data.lines.loc[index] line_waves = line_waves.wavelength.values * units.AA @@ -337,7 +341,6 @@ def _calc_thomson_scattering_opacity(self): kappa_thom : astropy.units.Quantity ndarray Thomson scattering opacity (shape Nshells) """ - try: sigma_T = const.sigma_T except AttributeError: @@ -367,7 +370,6 @@ def _calc_planck_mean_opacity(self): kappa_planck_mean : astropy.units.Quantity ndarray Planck-mean opacity (shape Nshells) """ - kappa_planck_mean = np.zeros(self.nshells) / units.cm for i in range(self.nshells): @@ -392,7 +394,6 @@ def _calc_planck_optical_depth(self): delta_tau : astropy.units.Quantity ndarray (dimensionless) Planck-mean optical depth (shape Nshells) """ - delta_r = self.r_outer - self.r_inner delta_tau = delta_r * self.planck_kappa diff --git a/tardis/grid/__init__.py b/tardis/grid/__init__.py index 1b5b3213ca9..80499809712 100644 --- a/tardis/grid/__init__.py +++ b/tardis/grid/__init__.py @@ -1,6 +1,6 @@ """ -Storing a grid of TARDIS parameters that -facilitates running large numbers of +Storing a grid of TARDIS parameters that +facilitates running large numbers of simulations easily. """ diff --git a/tardis/grid/base.py b/tardis/grid/base.py index d0090ab493e..b468a5b6828 100644 --- a/tardis/grid/base.py +++ b/tardis/grid/base.py @@ -1,10 +1,10 @@ -import pandas as pd -import numpy as np import copy -import tardis +import numpy as np +import pandas as pd + +import tardis from tardis.io.configuration.config_reader import Configuration -from tardis.io.atom_data import AtomData from tardis.model import SimulationState @@ -30,7 +30,6 @@ def _set_tardis_config_property(tardis_config, key, value): for key in keyitems[1:-1]: tmp_dict = getattr(tmp_dict, key) setattr(tmp_dict, keyitems[-1], value) - return class tardisGrid: @@ -67,8 +66,6 @@ def __init__(self, configFile, gridFrame): self.config = tardis_config self.grid = gridFrame - return - def grid_row_to_config(self, row_index): """ Converts a grid row to a TARDIS config dict. @@ -144,7 +141,6 @@ def save_grid(self, filename): File name to save grid. """ self.grid.to_csv(filename, index=False) - return @classmethod def from_axes(cls, configFile, axesdict): diff --git a/tardis/grid/tests/test_grid.py b/tardis/grid/tests/test_grid.py index 4a793c7e9a4..e6f84281acc 100644 --- a/tardis/grid/tests/test_grid.py +++ b/tardis/grid/tests/test_grid.py @@ -4,11 +4,8 @@ import pandas as pd import tardis - -from pathlib import Path import tardis.grid as grid - DATA_PATH = Path(tardis.__path__[0]) / "grid" / "tests" / "data" diff --git a/tardis/radiation_field/base.py b/tardis/radiation_field/base.py index 4fe0658c20c..5b77762c3a4 100644 --- a/tardis/radiation_field/base.py +++ b/tardis/radiation_field/base.py @@ -1,8 +1,8 @@ import numpy as np from astropy import units as u -from tardis.transport.montecarlo.packet_source import BasePacketSource from tardis.opacities.opacity_state import OpacityState +from tardis.transport.montecarlo.packet_source import BasePacketSource class MonteCarloRadiationFieldState: diff --git a/tardis/util/base.py b/tardis/util/base.py index 5eb2d14fc33..9511787d712 100644 --- a/tardis/util/base.py +++ b/tardis/util/base.py @@ -1,24 +1,24 @@ +import functools import logging import os import re +import warnings from collections import OrderedDict import numexpr as ne import numpy as np import pandas as pd +import tqdm +import tqdm.notebook import yaml -from tardis import constants from astropy import units as u -from radioactivedecay import Nuclide, DEFAULTDATA -from radioactivedecay.utils import parse_nuclide, Z_DICT +from IPython import display, get_ipython +from radioactivedecay import DEFAULTDATA +from radioactivedecay.utils import Z_DICT, parse_nuclide import tardis +from tardis import constants from tardis.io.util import get_internal_data_path -from IPython import get_ipython, display -import tqdm -import tqdm.notebook -import functools -import warnings k_B_cgs = constants.k_B.cgs.value c_cgs = constants.c.cgs.value @@ -129,10 +129,9 @@ def roman_to_int(roman_string): int Returns integer representation of roman_string """ - NUMERALS_SET = set(list(zip(*NUMERAL_MAP))[1]) roman_string = roman_string.upper() - if len(set(list(roman_string.upper())) - NUMERALS_SET) != 0: + if len(set(roman_string.upper()) - NUMERALS_SET) != 0: raise ValueError(f"{roman_string} does not seem to be a roman numeral") i = result = 0 for integer, numeral in NUMERAL_MAP: @@ -211,7 +210,6 @@ def create_synpp_yaml(radial1d_mdl, fname, shell_no=0, lines_db=None): ValueError If the current dataset does not contain necessary reference files """ - logger.warning("Currently only works with Si and a special setup") if radial1d_mdl.atom_data.synpp_refs is not None: raise ValueError( @@ -231,7 +229,6 @@ def create_synpp_yaml(radial1d_mdl, fname, shell_no=0, lines_db=None): logger.debug( "Synpp Ref does not have valid KEY for ref_log_tau in Radial1D Model" ) - pass relevant_synpp_refs = radial1d_mdl.atom_data.synpp_refs[ radial1d_mdl.atom_data.synpp_refs["ref_log_tau"] > -50 @@ -364,7 +361,6 @@ def species_string_to_tuple(species_string): MalformedSpeciesError If the inputted string does not match the species format """ - try: element_symbol, ion_number_string = re.match( r"^(\w+)\s*(\d+)", species_string @@ -420,7 +416,6 @@ def parse_quantity(quantity_string): MalformedQuantityError If string is not properly formatted for Astropy Quantity """ - if not isinstance(quantity_string, str): raise MalformedQuantityError(quantity_string) @@ -494,7 +489,6 @@ def reformat_element_symbol(element_string): str Returned reformatted element symbol """ - return element_string[0].upper() + element_string[1:].lower() @@ -515,12 +509,11 @@ def is_valid_nuclide_or_elem(input_nuclide): Bool indicating if the input nuclide is contained in the decay dataset or is a valid element. """ - try: parse_nuclide(input_nuclide, DEFAULTDATA.nuclides, "ICRP-107") is_nuclide = True except: - is_nuclide = True if input_nuclide in Z_DICT.values() else False + is_nuclide = input_nuclide in Z_DICT.values() return is_nuclide @@ -775,7 +768,6 @@ def deprecated(func): Parameters ---------- - func : function """