-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move use_source_factory and use_source_factory_metadata_index to sour…
…ce_factories
- Loading branch information
1 parent
f96a8ec
commit af87f6b
Showing
4 changed files
with
71 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Factory functions for creating sources.""" | ||
|
||
from firecrown.likelihood.number_counts import NumberCountsFactory, NumberCounts | ||
from firecrown.likelihood.weak_lensing import WeakLensingFactory, WeakLensing | ||
from firecrown.metadata_types import InferredGalaxyZDist, Measurement, Galaxies | ||
|
||
|
||
def use_source_factory( | ||
inferred_galaxy_zdist: InferredGalaxyZDist, | ||
measurement: Measurement, | ||
wl_factory: WeakLensingFactory | None = None, | ||
nc_factory: NumberCountsFactory | None = None, | ||
) -> WeakLensing | NumberCounts: | ||
"""Apply the factory to the inferred galaxy redshift distribution.""" | ||
source: WeakLensing | NumberCounts | ||
if measurement not in inferred_galaxy_zdist.measurements: | ||
raise ValueError( | ||
f"Measurement {measurement} not found in inferred galaxy redshift " | ||
f"distribution {inferred_galaxy_zdist.bin_name}!" | ||
) | ||
|
||
match measurement: | ||
case Galaxies.COUNTS: | ||
assert nc_factory is not None | ||
source = nc_factory.create(inferred_galaxy_zdist) | ||
case ( | ||
Galaxies.SHEAR_E | ||
| Galaxies.SHEAR_T | ||
| Galaxies.SHEAR_MINUS | ||
| Galaxies.SHEAR_PLUS | ||
): | ||
assert wl_factory is not None | ||
source = wl_factory.create(inferred_galaxy_zdist) | ||
case _: | ||
raise ValueError(f"Measurement {measurement} not supported!") | ||
return source | ||
|
||
|
||
def use_source_factory_metadata_index( | ||
sacc_tracer: str, | ||
measurement: Measurement, | ||
wl_factory: WeakLensingFactory | None = None, | ||
nc_factory: NumberCountsFactory | None = None, | ||
) -> WeakLensing | NumberCounts: | ||
"""Apply the factory to create a source from metadata only.""" | ||
source: WeakLensing | NumberCounts | ||
match measurement: | ||
case Galaxies.COUNTS: | ||
assert nc_factory is not None | ||
source = nc_factory.create_from_metadata_only(sacc_tracer) | ||
case ( | ||
Galaxies.SHEAR_E | ||
| Galaxies.SHEAR_T | ||
| Galaxies.SHEAR_MINUS | ||
| Galaxies.SHEAR_PLUS | ||
): | ||
assert wl_factory is not None | ||
source = wl_factory.create_from_metadata_only(sacc_tracer) | ||
case _: | ||
raise ValueError(f"Measurement {measurement} not supported!") | ||
return source |
This file contains 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
This file contains 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
This file contains 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