Skip to content

Commit

Permalink
Update TARDIS environment after replacing PyNE (#1948)
Browse files Browse the repository at this point in the history
* first revision of env file

* changes from astropy 4 (deprecated blackbody functions)

* move qt import in gui test

* downgrade pandas

* pin radioactive decay again

* fix changes from astropy 4 (deprecated blackbody functions)

* fix changes from astropy 4 (unit conversion bug)

* fix changes from astropy 4 (unit conversion bug) viz module

* fix changes from astropy 4 (deprecated blackbody functions) opacity calc

* import constants from tardis in opacities

* upgrade black

* remove pickle backport

* use astropy.constants v3 for astropy.units

* remove pinned deps fixed upstream

* pin astropy v5 again
  • Loading branch information
epassaro authored Apr 21, 2022
1 parent 507c50f commit 665bb0f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
python-version: 3.x

- name: Install Black
run: pip install black==21.12b0
run: pip install black==22.3

- name: Run Black
run: black --check tardis
12 changes: 5 additions & 7 deletions tardis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

# ----------------------------------------------------------------------------

from tardis.base import run_tardis
from tardis.io.util import yaml_load_config_file as yaml_load
from astropy import physical_constants, astronomical_constants

physical_constants.set('codata2014')
astronomical_constants.set('iau2012')

# ----------------------------------------------------------------------------
# pyne holds Python 3.7 on macOS, but refdata is pickled with protocol 5 (3.8.3)

if sys.version_info < (3, 8, 3):
import pickle5

sys.modules["pickle"] = pickle5
from tardis.base import run_tardis
from tardis.io.util import yaml_load_config_file as yaml_load
13 changes: 7 additions & 6 deletions tardis/analysis/opacities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import logging
import numpy as np
import astropy.units as units
import astropy.constants as csts
from astropy.modeling.blackbody import blackbody_nu
from tardis import constants as const
from astropy.modeling.models import Blackbody

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -320,7 +320,7 @@ def _calc_expansion_opacity(self):
tmp
* self.nu_bins[i]
/ (self.nu_bins[i + 1] - self.nu_bins[i])
/ (csts.c * self.t_exp)
/ (const.c * self.t_exp)
)

return kappa_exp.to("1/cm")
Expand All @@ -339,7 +339,7 @@ def _calc_thomson_scattering_opacity(self):
"""

try:
sigma_T = csts.sigma_T
sigma_T = const.sigma_T
except AttributeError:
logger.warning("using astropy < 1.1.1: setting sigma_T manually")
sigma_T = 6.65245873e-29 * units.m ** 2
Expand Down Expand Up @@ -373,13 +373,14 @@ def _calc_planck_mean_opacity(self):
for i in range(self.nshells):
delta_nu = self.nu_bins[1:] - self.nu_bins[:-1]
T = self.mdl.plasma.t_rad[i]
bb_nu = Blackbody(T)

tmp = (
blackbody_nu(self.nu_bins[:-1], T)
bb_nu(self.nu_bins[:-1])
* delta_nu
* self.kappa_tot[:, 0]
).sum()
tmp /= (blackbody_nu(self.nu_bins[:-1], T) * delta_nu).sum()
tmp /= (bb_nu(self.nu_bins[:-1], T) * delta_nu).sum()

kappa_planck_mean[i] = tmp

Expand Down
2 changes: 1 addition & 1 deletion tardis/gui/tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from PyQt5 import QtWidgets
import os
import pytest
from tardis.io.config_reader import Configuration
from tardis.simulation import Simulation
import astropy.units as u

if "QT_API" in os.environ:
from PyQt5 import QtWidgets
from tardis.gui.widgets import Tardis
from tardis.gui.datahandler import SimpleTableModel

Expand Down
4 changes: 2 additions & 2 deletions tardis/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def montecarlo_reabsorbed_luminosity(self):
np.histogram(
self.reabsorbed_packet_nu,
weights=self.reabsorbed_packet_luminosity,
bins=self.spectrum_frequency.value,
bins=self.spectrum_frequency,
)[0],
"erg / s",
)
Expand All @@ -472,7 +472,7 @@ def montecarlo_emitted_luminosity(self):
np.histogram(
self.emitted_packet_nu,
weights=self.emitted_packet_luminosity,
bins=self.spectrum_frequency.value,
bins=self.spectrum_frequency,
)[0],
"erg / s",
)
Expand Down
20 changes: 11 additions & 9 deletions tardis/visualization/tools/sdec_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pandas as pd
import astropy.units as u
import astropy.modeling.blackbody as abb
from astropy.modeling.models import BlackBody

import matplotlib.pyplot as plt
import matplotlib.cm as cm
Expand Down Expand Up @@ -868,7 +868,7 @@ def _calculate_emission_luminosities(self, packets_mode, packet_wvl_range):
self.data[packets_mode].packets_df["nus"][
self.packet_nu_range_mask
][mask_noint],
bins=self.plot_frequency_bins,
bins=self.plot_frequency_bins.value,
weights=weights[mask_noint],
density=False,
)
Expand Down Expand Up @@ -901,7 +901,7 @@ def _calculate_emission_luminosities(self, packets_mode, packet_wvl_range):
self.data[packets_mode].packets_df["nus"][
self.packet_nu_range_mask
][mask_escatter],
bins=self.plot_frequency_bins,
bins=self.plot_frequency_bins.value,
weights=weights[mask_escatter],
density=False,
)
Expand Down Expand Up @@ -938,7 +938,7 @@ def _calculate_emission_luminosities(self, packets_mode, packet_wvl_range):
# Histogram of specific species
hist_el = np.histogram(
group["nus"],
bins=self.plot_frequency_bins,
bins=self.plot_frequency_bins.value,
weights=group["energies"]
/ self.lum_to_flux
/ self.data[packets_mode].time_of_simulation,
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def _calculate_absorption_luminosities(
# Histogram of specific species
hist_el = np.histogram(
group["last_line_interaction_in_nu"],
bins=self.plot_frequency_bins,
bins=self.plot_frequency_bins.value,
weights=group["energies"]
/ self.lum_to_flux
/ self.data[packets_mode].time_of_simulation,
Expand Down Expand Up @@ -1064,11 +1064,13 @@ def _calculate_photosphere_luminosity(self, packets_mode):
Luminosity density lambda (or Flux) of photosphere (inner boundary
of TARDIS simulation)
"""
bb_lam = BlackBody(
self.data[packets_mode].t_inner,
scale=1.0 * u.erg / (u.cm ** 2 * u.AA * u.s * u.sr)
)

L_lambda_ph = (
abb.blackbody_lambda(
self.plot_wavelength,
self.data[packets_mode].t_inner,
)
bb_lam(self.plot_wavelength)
* 4
* np.pi ** 2
* self.data[packets_mode].r_inner[0] ** 2
Expand Down
20 changes: 7 additions & 13 deletions tardis_env3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ channels:
- conda-forge

dependencies:
- python=3.7
- python=3.8
- setuptools
- setuptools_scm
- pip
- numpy=1.19
- scipy=1.5
- pandas=1.0
- astropy=3
- astropy=5.0
- numba=0.53
- numexpr
- radioactivedecay>=0.4.12
Expand All @@ -25,19 +25,17 @@ dependencies:
- jsonschema=3 # Issue #1807
- pytables
- h5py
- pickle5 # Issue #1566
- requests
- tqdm

# Widgets & Visualization
- jupyter
- matplotlib
- notebook
- matplotlib-base
- ipywidgets
- plotly
- qgrid
# - pyside2 # (Qt GUI) Issue #1652

# --- Not required for conda-forge package and Numba integration pipeline ---
# --- Not required for conda-forge package ---

# tardis-sn/nuclear dependencies
- beautifulsoup4
Expand All @@ -56,9 +54,8 @@ dependencies:
- nbconvert
- nbformat
- nbsphinx
- docutils=0.16 # Issue #1522
- snakeviz
- Jinja2=3.0.3 # github.com/spatialaudio/nbsphinx/issues/641
- dot2tex

# Test/Coverage
- pytest
Expand All @@ -68,10 +65,7 @@ dependencies:
- coverage

# Code quality
- black=21.12b0
- black=22.3

# Other
- git-lfs

- pip:
- dot2tex # conda-forge package requires python>=3.8

0 comments on commit 665bb0f

Please sign in to comment.