-
Notifications
You must be signed in to change notification settings - Fork 27
Log Bins for snowglobes.py #206
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
Open
stlgolfer
wants to merge
6
commits into
SNEWS2:main
Choose a base branch
from
stlgolfer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a766c4
Add changes from wrapper
stlgolfer 4c0899e
Working example for log bins error checking
stlgolfer 0374689
Cleanup
stlgolfer 9515f15
Fixed almost all requested changes
stlgolfer 86be5cf
t=0 check for log bins
stlgolfer ac756e0
Change error message
stlgolfer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import os | ||
| import re | ||
| import tarfile | ||
| import math | ||
| from pathlib import Path | ||
| from tempfile import TemporaryDirectory | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| ------- | ||
|
|
@@ -91,6 +94,22 @@ 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==True): | ||
| log_edges = np.asarray([]) | ||
|
|
||
| if tmax < 0 or tmin < 0: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn’t these be |
||
| raise ValueError("Cannot apply log to time windows that are less than 0") | ||
| tstep = math.log10(abs(tmax/tmin))/len(times) | ||
|
|
||
| for i in range(0,len(times)): | ||
| t = (tmin/u.s)*(10**(i*tstep)) | ||
| if t < 0: | ||
|
JostMigenda marked this conversation as resolved.
Outdated
|
||
| raise ValueError("Cannot use negative time coordinates in log scale. Consider adjusting model time window"); | ||
| 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' | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.