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

Re-applied Black formatting to tardis after excluding undesired directories #1213

Merged
merged 4 commits into from
Jul 29, 2020
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
32 changes: 28 additions & 4 deletions asv/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@

LINE_SIZE = 10000000


class TimeSuite:
"""
An example benchmark that times the performance of various kinds
of iterating over dictionaries in Python.
"""

def setup(self):
self.line = np.arange(LINE_SIZE, 1, -1).astype(np.float64)

def time_binarysearch(self):
for _ in range(LINE_SIZE):
montecarlo.binary_search_wrapper(self.line, np.random.random() * LINE_SIZE, 0, LINE_SIZE - 1)
montecarlo.binary_search_wrapper(
self.line, np.random.random() * LINE_SIZE, 0, LINE_SIZE - 1
)

def time_compute_distance2outer(self):
for _ in range(1000000):
Expand All @@ -25,7 +29,7 @@ def time_compute_distance2outer(self):
montecarlo.compute_distance2outer_wrapper(0.3, 1.0, 1.0)
montecarlo.compute_distance2outer_wrapper(0.3, -1.0, 1.0)
montecarlo.compute_distance2outer_wrapper(0.5, 0.0, 1.0)

def time_compute_distance2inner(self):
for _ in range(1000000):
montecarlo.compute_distance2inner_wrapper(1.5, -1.0, 1.0)
Expand All @@ -34,8 +38,28 @@ def time_compute_distance2inner(self):

def time_compute_distance2line(self):
for _ in range(1000000):
montecarlo.compute_distance2line_wrapper(2.20866912e+15, -0.251699059004, 1.05581082105e+15, 1.06020910733e+15, 1693440.0, 5.90513983371e-07, 1.0602263591e+15, 1.06011723237e+15, 2)
montecarlo.compute_distance2line_wrapper(2.23434667994e+15, -0.291130548401, 1.05581082105e+15, 1.06733618121e+15, 1693440.0, 5.90513983371e-07, 1.06738407486e+15, 1.06732933961e+15, 3)
montecarlo.compute_distance2line_wrapper(
2.20866912e15,
-0.251699059004,
1.05581082105e15,
1.06020910733e15,
1693440.0,
5.90513983371e-07,
1.0602263591e15,
1.06011723237e15,
2,
)
montecarlo.compute_distance2line_wrapper(
2.23434667994e15,
-0.291130548401,
1.05581082105e15,
1.06733618121e15,
1693440.0,
5.90513983371e-07,
1.06738407486e15,
1.06732933961e15,
3,
)

def time_compute_distance2electron(self):
for _ in range(1000000):
Expand Down
70 changes: 42 additions & 28 deletions docs/physics/plasma/plasma_plots/lte_ionization_balance.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

#Making 2 Figures for ionization balance and level populations
# Making 2 Figures for ionization balance and level populations

plt.figure(1).clf()
ax1 = plt.figure(1).add_subplot(111)
Expand All @@ -16,73 +16,87 @@
ax2 = plt.figure(2).add_subplot(111)

# expanding the tilde to the users directory
#atom_fname = os.path.join(os.path.dirname(base.__file__), 'data', 'atom_data.h5')
# atom_fname = os.path.join(os.path.dirname(base.__file__), 'data', 'atom_data.h5')

# reading in the HDF5 File
atom_data = AtomData.from_hdf(atom_fname)

#The atom_data needs to be prepared to create indices. The Class needs to know which atomic numbers are needed for the
#calculation and what line interaction is needed (for "downbranch" and "macroatom" the code creates special tables)
atom_data.prepare_atom_data([14], 'scatter')
# The atom_data needs to be prepared to create indices. The Class needs to know which atomic numbers are needed for the
# calculation and what line interaction is needed (for "downbranch" and "macroatom" the code creates special tables)
atom_data.prepare_atom_data([14], "scatter")

#Initializing the NebularPlasma class using the from_abundance class method.
#This classmethod is normally only needed to test individual plasma classes
#Usually the plasma class just gets the number densities from the model class
# Initializing the NebularPlasma class using the from_abundance class method.
# This classmethod is normally only needed to test individual plasma classes
# Usually the plasma class just gets the number densities from the model class
assert True, (
'This script needs a proper rewrite and should use the new'
'"assemble_plasma" function.')
"This script needs a proper rewrite and should use the new"
'"assemble_plasma" function.'
)
# TODO: Uncomment and fix the next line
# lte_plasma = assemble_plasma({'Si':1.0}, 1e-14*u.g/u.cm**3, atom_data, 10*u.day)
lte_plasma = None
lte_plasma.update_radiationfield([10000], [1.0])

#Initializing a dataframe to store the ion populations and level populations for the different temperatures
# Initializing a dataframe to store the ion populations and level populations for the different temperatures
ion_number_densities = pd.DataFrame(index=lte_plasma.ion_populations.index)
level_populations = pd.DataFrame(index=lte_plasma.level_populations.ix[14, 1].index)
level_populations = pd.DataFrame(
index=lte_plasma.level_populations.ix[14, 1].index
)
t_rads = np.linspace(2000, 20000, 100)

#Calculating the different ion populations and level populuatios for the given temperatures
# Calculating the different ion populations and level populuatios for the given temperatures
for t_rad in t_rads:
lte_plasma.update_radiationfield([t_rad], ws=[1.0])
#getting total si number density
# getting total si number density
si_number_density = lte_plasma.number_densities.get_value(14, 0)
#Normalizing the ion populations
# Normalizing the ion populations
ion_density = lte_plasma.ion_populations / si_number_density
ion_number_densities[t_rad] = ion_density

#normalizing the level_populations for Si II
current_level_population = lte_plasma.level_populations[0].ix[14, 1] / lte_plasma.ion_populations.get_value((14, 1), 0)
# normalizing the level_populations for Si II
current_level_population = lte_plasma.level_populations[0].ix[
14, 1
] / lte_plasma.ion_populations.get_value((14, 1), 0)

#normalizing with statistical weight
# normalizing with statistical weight
current_level_population /= atom_data.levels.ix[14, 1].g

level_populations[t_rad] = current_level_population

ion_colors = ['b', 'g', 'r', 'k']
ion_colors = ["b", "g", "r", "k"]

for ion_number in [0, 1, 2, 3]:
current_ion_density = ion_number_densities.ix[14, ion_number]
ax1.plot(current_ion_density.index, current_ion_density.values, '%s-' % ion_colors[ion_number],
label='Si %s W=1.0' % tardis.util.base.int_to_roman(ion_number + 1).upper())
ax1.plot(
current_ion_density.index,
current_ion_density.values,
"%s-" % ion_colors[ion_number],
label="Si %s W=1.0"
% tardis.util.base.int_to_roman(ion_number + 1).upper(),
)


#only plotting every 5th radiation temperature
# only plotting every 5th radiation temperature
t_rad_normalizer = colors.Normalize(vmin=2000, vmax=20000)
t_rad_color_map = plt.cm.ScalarMappable(norm=t_rad_normalizer, cmap=plt.cm.jet)

for t_rad in t_rads[::5]:
ax2.plot(level_populations[t_rad].index, level_populations[t_rad].values, color=t_rad_color_map.to_rgba(t_rad))
ax2.plot(
level_populations[t_rad].index,
level_populations[t_rad].values,
color=t_rad_color_map.to_rgba(t_rad),
)
ax2.semilogy()

t_rad_color_map.set_array(t_rads)
cb = plt.figure(2).colorbar(t_rad_color_map)

ax1.set_xlabel('T [K]')
ax1.set_ylabel('Number Density Fraction')
ax1.set_xlabel("T [K]")
ax1.set_ylabel("Number Density Fraction")
ax1.legend()

ax2.set_xlabel('Level Number for Si II')
ax2.set_ylabel('Number Density Fraction')
cb.set_label('T [K]')
ax2.set_xlabel("Level Number for Si II")
ax2.set_ylabel("Number Density Fraction")
cb.set_label("T [K]")

plt.show()
104 changes: 66 additions & 38 deletions docs/physics/plasma/plasma_plots/nebular_ionization_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
import pandas as pd

#Making 2 Figures for ionization balance and level populations
# Making 2 Figures for ionization balance and level populations

plt.figure(1).clf()
ax1 = plt.figure(1).add_subplot(111)
Expand All @@ -18,97 +18,125 @@
ax2 = plt.figure(2).add_subplot(111)

# expanding the tilde to the users directory
atom_fname = os.path.expanduser('~/.tardis/si_kurucz.h5')
atom_fname = os.path.expanduser("~/.tardis/si_kurucz.h5")

# reading in the HDF5 File
atom_data = base.AtomData.from_hdf(atom_fname)

#The atom_data needs to be prepared to create indices. The Class needs to know which atomic numbers are needed for the
#calculation and what line interaction is needed (for "downbranch" and "macroatom" the code creates special tables)
atom_data.prepare_atom_data([14], 'scatter')
# The atom_data needs to be prepared to create indices. The Class needs to know which atomic numbers are needed for the
# calculation and what line interaction is needed (for "downbranch" and "macroatom" the code creates special tables)
atom_data.prepare_atom_data([14], "scatter")

#Initializing the NebularPlasma class using the from_abundance class method.
#This classmethod is normally only needed to test individual plasma classes
#Usually the plasma class just gets the number densities from the model class
nebular_plasma = plasma.NebularPlasma.from_abundance(10000, 0.5, {'Si': 1}, 1e-13, atom_data, 10.)
# Initializing the NebularPlasma class using the from_abundance class method.
# This classmethod is normally only needed to test individual plasma classes
# Usually the plasma class just gets the number densities from the model class
nebular_plasma = plasma.NebularPlasma.from_abundance(
10000, 0.5, {"Si": 1}, 1e-13, atom_data, 10.0
)


#Initializing a dataframe to store the ion populations and level populations for the different temperatures
# Initializing a dataframe to store the ion populations and level populations for the different temperatures
ion_number_densities = pd.DataFrame(index=nebular_plasma.ion_populations.index)
level_populations = pd.DataFrame(index=nebular_plasma.level_populations.ix[14, 1].index)
level_populations = pd.DataFrame(
index=nebular_plasma.level_populations.ix[14, 1].index
)
t_rads = np.linspace(2000, 20000, 100)

#Calculating the different ion populations and level populuatios for the given temperatures
# Calculating the different ion populations and level populuatios for the given temperatures
for t_rad in t_rads:
nebular_plasma.update_radiationfield(t_rad, w=1.0)
#getting total si number density
# getting total si number density
si_number_density = nebular_plasma.number_density.get_value(14)
#Normalizing the ion populations
# Normalizing the ion populations
ion_density = nebular_plasma.ion_populations / si_number_density
ion_number_densities[t_rad] = ion_density

#normalizing the level_populations for Si II
current_level_population = nebular_plasma.level_populations.ix[14, 1] / nebular_plasma.ion_populations.ix[14, 1]
#normalizing with statistical weight
# normalizing the level_populations for Si II
current_level_population = (
nebular_plasma.level_populations.ix[14, 1]
/ nebular_plasma.ion_populations.ix[14, 1]
)
# normalizing with statistical weight
current_level_population /= atom_data.levels.ix[14, 1].g

level_populations[t_rad] = current_level_population

ion_colors = ['b', 'g', 'r', 'k']
ion_colors = ["b", "g", "r", "k"]

for ion_number in [0, 1, 2, 3]:
current_ion_density = ion_number_densities.ix[14, ion_number]
ax1.plot(current_ion_density.index, current_ion_density.values, '%s-' % ion_colors[ion_number],
label='Si %s W=1.0' % tardis.util.base.int_to_roman(ion_number + 1).upper())
ax1.plot(
current_ion_density.index,
current_ion_density.values,
"%s-" % ion_colors[ion_number],
label="Si %s W=1.0"
% tardis.util.base.int_to_roman(ion_number + 1).upper(),
)


#only plotting every 5th radiation temperature
# only plotting every 5th radiation temperature
t_rad_normalizer = colors.Normalize(vmin=2000, vmax=20000)
t_rad_color_map = plt.cm.ScalarMappable(norm=t_rad_normalizer, cmap=plt.cm.jet)

for t_rad in t_rads[::5]:
ax2.plot(level_populations[t_rad].index, level_populations[t_rad].values, color=t_rad_color_map.to_rgba(t_rad))
ax2.plot(
level_populations[t_rad].index,
level_populations[t_rad].values,
color=t_rad_color_map.to_rgba(t_rad),
)
ax2.semilogy()

#Calculating the different ion populations for the given temperatures with W=0.5
# Calculating the different ion populations for the given temperatures with W=0.5
ion_number_densities = pd.DataFrame(index=nebular_plasma.ion_populations.index)
for t_rad in t_rads:
nebular_plasma.update_radiationfield(t_rad, w=0.5)
#getting total si number density
# getting total si number density
si_number_density = nebular_plasma.number_density.get_value(14)
#Normalizing the ion populations
# Normalizing the ion populations
ion_density = nebular_plasma.ion_populations / si_number_density
ion_number_densities[t_rad] = ion_density

#normalizing the level_populations for Si II
current_level_population = nebular_plasma.level_populations.ix[14, 1] / nebular_plasma.ion_populations.ix[14, 1]
#normalizing with statistical weight
# normalizing the level_populations for Si II
current_level_population = (
nebular_plasma.level_populations.ix[14, 1]
/ nebular_plasma.ion_populations.ix[14, 1]
)
# normalizing with statistical weight
current_level_population /= atom_data.levels.ix[14, 1].g

level_populations[t_rad] = current_level_population

#Plotting the ion fractions
# Plotting the ion fractions

for ion_number in [0, 1, 2, 3]:
print("w=0.5")
current_ion_density = ion_number_densities.ix[14, ion_number]
ax1.plot(current_ion_density.index, current_ion_density.values, '%s--' % ion_colors[ion_number],
label='Si %s W=0.5' % tardis.util.base.int_to_roman(ion_number + 1).upper())
ax1.plot(
current_ion_density.index,
current_ion_density.values,
"%s--" % ion_colors[ion_number],
label="Si %s W=0.5"
% tardis.util.base.int_to_roman(ion_number + 1).upper(),
)

for t_rad in t_rads[::5]:
ax2.plot(level_populations[t_rad].index, level_populations[t_rad].values, color=t_rad_color_map.to_rgba(t_rad),
linestyle='--')
ax2.plot(
level_populations[t_rad].index,
level_populations[t_rad].values,
color=t_rad_color_map.to_rgba(t_rad),
linestyle="--",
)
ax2.semilogy()

t_rad_color_map.set_array(t_rads)
cb = plt.figure(2).colorbar(t_rad_color_map)

ax1.set_xlabel('T [K]')
ax1.set_ylabel('Number Density Fraction')
ax1.set_xlabel("T [K]")
ax1.set_ylabel("Number Density Fraction")
ax1.legend()

ax2.set_xlabel('Level Number for Si II')
ax2.set_ylabel('Number Density Fraction')
cb.set_label('T [K]')
ax2.set_xlabel("Level Number for Si II")
ax2.set_ylabel("Number Density Fraction")
cb.set_label("T [K]")

plt.show()
15 changes: 8 additions & 7 deletions docs/physics/pyplot/plot_mu_in_out_packet.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pylab import *
from astropy import units as u, constants as const

x, y = x, y = mgrid[1:1000, 1:1000]
mu_in = x / 500. - 1
mu_out = y / 500. - 1
mu_in = x / 500.0 - 1
mu_out = y / 500.0 - 1
v = 1.1e4 * u.km / u.s
doppler_fac = (1-mu_in * v/const.c)/(1-mu_out * v/const.c)
xlabel('$\mu_{\\rm in}$')
ylabel('$\mu_{\\rm out}$')
imshow(np.rot90(doppler_fac), extent=[-1, 1, -1, 1], cmap='bwr')
doppler_fac = (1 - mu_in * v / const.c) / (1 - mu_out * v / const.c)
xlabel("$\mu_{\\rm in}$")
ylabel("$\mu_{\\rm out}$")
imshow(np.rot90(doppler_fac), extent=[-1, 1, -1, 1], cmap="bwr")
colorbar()
show()
show()
Loading