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

Log Bins for snowglobes.py #206

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion python/snewpy/snowglobes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import re
import tarfile
import math
from pathlib import Path
from tempfile import TemporaryDirectory

Expand All @@ -40,7 +41,7 @@

logger = logging.getLogger(__name__)

def generate_time_series(model_path, model_type, transformation_type, d, output_filename=None, ntbins=30, deltat=None, snmodel_dict={}):
def generate_time_series(model_path, model_type, transformation_type, d, output_filename=None, ntbins=30, deltat=None, snmodel_dict={}, log_bins=False):
"""Generate time series files in SNOwGLoBES format.

This version will subsample the times in a supernova model, produce energy
Expand All @@ -64,6 +65,8 @@ def generate_time_series(model_path, model_type, transformation_type, d, output_
Length of time slices.
snmodel_dict : dict
Additional arguments for setting up the supernova model. See documentation of relevant ``SupernovaModel`` subclass for available options. (Optional)
log_bins : bool
Use logarithmically-spaced time bins

Returns
-------
Expand Down Expand Up @@ -91,6 +94,20 @@ def generate_time_series(model_path, model_type, transformation_type, d, output_
tedges = np.arange(tmin/u.s, tmax/u.s, dt/u.s)*u.s
times = 0.5*(tedges[1:] + tedges[:-1])

# now process log data
if log_bins:
log_edges = np.asarray([])

if tmax <= 0 or tmin <= 0:
raise ValueError("Cannot apply log to time windows that are less than or equal to 0. Consider adjusting model time window")
tstep = math.log10(abs(tmax/tmin))/len(times)

for i in range(0,len(times)):
t = (tmin/u.s)*(10**(i*tstep))
log_edges = np.append(log_edges,t)
log_edges = log_edges*u.s
times = 0.5*(log_edges[1:] + log_edges[:-1])

# Generate output.
if output_filename is not None:
tfname = output_filename + 'kpc.tar.bz2'
Expand Down