Commit 1863b281 authored by Philipp Oleynik's avatar Philipp Oleynik
Browse files

Integral powerlaw behaves strange in analytic (fast) mode.

parent 6f58b2d4
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (PycharmProjects)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
......
......@@ -25,6 +25,7 @@ def setup_plotstyle(rcParams):
rcParams['xtick.direction'] = 'in'
rcParams['ytick.direction'] = 'in'
rcParams['axes.labelsize'] = 14
rcParams['figure.autolayout'] = False
def plotsave_transparent(rcParams, transparency = True):
......
......@@ -157,3 +157,24 @@ def generate_powerlaw(*, energy_grid = None, power_index = -2, sp_norm = 1.0):
for energy in energy_grid:
spectrum.append(sp_norm * np.power(energy, power_index))
return np.array(spectrum, dtype = float)
def generate_integral_powerlaw(*, energy_grid = None, grid_bin_width = None,
power_index = -2, sp_norm = 1.0, fast = False):
spectrum = [] # np.power(energy_grid[-1], power_index + 1) / (power_index + 1)
if fast:
for energy in energy_grid:
spectrum.append(sp_norm * (
np.power(energy_grid[-1] + grid_bin_width[-1] * 1.00451, power_index + 1) / (power_index + 1) -
np.power(energy, power_index + 1) / (power_index + 1)
))
else:
for energy in energy_grid:
spectrum.append(sp_norm * np.power(energy, power_index))
for energy_i in range(len(energy_grid)):
integral_sp = 0
for energy_j in range(energy_i, len(energy_grid)):
integral_sp += spectrum[energy_j] * grid_bin_width[energy_j]
spectrum[energy_i] = integral_sp
return np.array(spectrum, dtype = float)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment