Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff Autofixes (tardis/analysis) #2826

Merged
merged 5 commits into from
Sep 25, 2024
Merged
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
21 changes: 11 additions & 10 deletions tardis/analysis/opacities.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tardis/grid/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
"""

Expand Down
12 changes: 4 additions & 8 deletions tardis/grid/base.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions tardis/grid/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
2 changes: 1 addition & 1 deletion tardis/radiation_field/base.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
28 changes: 10 additions & 18 deletions tardis/util/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -494,7 +489,6 @@ def reformat_element_symbol(element_string):
str
Returned reformatted element symbol
"""

return element_string[0].upper() + element_string[1:].lower()


Expand All @@ -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

Expand Down Expand Up @@ -775,7 +768,6 @@ def deprecated(func):

Parameters
----------

func : function
"""

Expand Down
Loading