-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add construct_lightcone_form_filelist #50
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
steven-murray
wants to merge
1
commit into
main
Choose a base branch
from
simple-lightconing
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 all commits
Commits
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 | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,17 @@ | ||||||||
| """Generate lightcones from 21cmFAST output cache.""" | ||||||||
|
|
||||||||
| from collections.abc import Sequence | ||||||||
| from pathlib import Path | ||||||||
| from types import SimpleNamespace | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| from py21cmfast.drivers.lightcone import ( | ||||||||
| AngularLightcone, | ||||||||
| LightCone, | ||||||||
| setup_lightcone_instance, | ||||||||
| ) | ||||||||
| from py21cmfast.io import read_output_struct | ||||||||
| from py21cmfast.io.caching import RunCache | ||||||||
| from py21cmfast.lightcones import Lightconer | ||||||||
| from py21cmfast.lightconers import Lightconer | ||||||||
|
|
||||||||
|
|
||||||||
| def construct_lightcone_from_cache( | ||||||||
|
|
@@ -49,14 +51,17 @@ def construct_lightcone_from_cache( | |||||||
| inputs = cache.inputs | ||||||||
| node_redshifts = sorted(cache.BrightnessTemp.keys(), reverse=True) | ||||||||
|
|
||||||||
| lightconer.validate_options(cache.inputs.matter_options, cache.inputs.astro_options) | ||||||||
| lightconer.validate_options( | ||||||||
| cache.inputs, include_dvdr_in_tau21=False, apply_rsds=False | ||||||||
| ) | ||||||||
|
|
||||||||
| # Create the LightCone instance, loading from file if needed | ||||||||
| lightcone = setup_lightcone_instance( | ||||||||
| lightconer=lightconer, | ||||||||
| inputs=inputs, | ||||||||
| scrollz=node_redshifts, | ||||||||
| global_quantities=global_quantities, | ||||||||
| include_dvdr_in_tau21=False, | ||||||||
| apply_rsds=False, | ||||||||
| photon_nonconservation_data={}, | ||||||||
| ) | ||||||||
|
|
||||||||
|
|
@@ -100,12 +105,74 @@ def construct_lightcone_from_cache( | |||||||
|
|
||||||||
| prev_coeval = coeval | ||||||||
|
|
||||||||
| # last redshift things | ||||||||
| if iz == len(node_redshifts) - 1 and ( | ||||||||
| isinstance(lightcone, AngularLightcone) and lightconer.get_los_velocity | ||||||||
| ): | ||||||||
| lightcone.lightcones["brightness_temp_with_rsds"] = lightcone.compute_rsds( | ||||||||
| n_subcells=inputs.astro_params.N_RSD_STEPS | ||||||||
| ) | ||||||||
| return lightcone | ||||||||
|
|
||||||||
|
|
||||||||
| def construct_lightcone_from_filelist( | ||||||||
| filelist: Sequence[Path], | ||||||||
| lightconer: Lightconer, | ||||||||
| ) -> LightCone: | ||||||||
| """Construct a Lightcone from a list of OutputStruct files. | ||||||||
|
|
||||||||
| This function assumes that the list of files are 21cmFAST output structs, each | ||||||||
| at a different redshift. These may be from a RunCache, but don't need to be. | ||||||||
|
|
||||||||
| Parameters | ||||||||
| ---------- | ||||||||
| filelist | ||||||||
| A list of paths to 21cmFAST output struct files. | ||||||||
| lightconer | ||||||||
| The object used to generate lightcone slices. | ||||||||
| global_quantities | ||||||||
| A list of global quantities to extract. These must exist in the files | ||||||||
| given. | ||||||||
| """ | ||||||||
| boxes = [read_output_struct(fl) for fl in filelist] | ||||||||
| inputs = boxes[0].inputs | ||||||||
| boxes = sorted(boxes, key=lambda b: b.redshift, reverse=True) | ||||||||
| node_redshifts = [b.redshift for b in boxes] | ||||||||
|
|
||||||||
| lightconer.validate_options(inputs, apply_rsds=False, include_dvdr_in_tau21=False) | ||||||||
|
|
||||||||
| # Create the LightCone instance, loading from file if needed | ||||||||
| lightcone = setup_lightcone_instance( | ||||||||
| lightconer=lightconer, | ||||||||
| inputs=inputs, | ||||||||
| scrollz=node_redshifts, | ||||||||
| photon_nonconservation_data={}, | ||||||||
| include_dvdr_in_tau21=False, | ||||||||
| apply_rsds=False, | ||||||||
| ) | ||||||||
|
|
||||||||
| lightcone._last_completed_node = -1 | ||||||||
| lightcone._last_completed_lcidx = ( | ||||||||
| np.sum( | ||||||||
| lightcone.lightcone_redshifts | ||||||||
| >= node_redshifts[lightcone._last_completed_node] | ||||||||
| ) | ||||||||
| - 1 | ||||||||
| ) | ||||||||
|
|
||||||||
| prev_box = None | ||||||||
| for box in boxes: | ||||||||
|
||||||||
| for box in boxes: | |
| for box in boxes: | |
| # TODO: Remove this hack when upgrading to a newer version of 21cmFAST that natively supports this. |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring references a
global_quantitiesparameter that doesn't exist in the function signature. This parameter should be removed from the documentation or added to the function.