Skip to content

Commit

Permalink
add rubin_roman sims
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-superonion committed Jan 15, 2025
1 parent b4c0a66 commit 225c6a6
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 64 deletions.
74 changes: 17 additions & 57 deletions examples/anacal/example_blended_sim.ipynb

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion xlens/process_pipe/fpfs_joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from typing import Any

import lsst.pipe.base.connectionTypes as cT
import numpy as np
from lsst.meas.base import SkyMapIdGeneratorConfig
from lsst.pex.config import ConfigurableField, Field
from lsst.pipe.base import (
Expand All @@ -38,6 +39,7 @@
Struct,
)
from lsst.utils.logging import LsstLogAdapter
from numpy.typing import NDArray

from ..processor.fpfs import FpfsMeasurementTask

Expand Down Expand Up @@ -66,6 +68,15 @@ class FpfsJointPipeConnections(
multiple=True,
deferLoad=True,
)
truthCatalog = cT.Input(
doc="input truth catalog",
name="{coaddName}Coadd_truthCatalog",
storageClass="ArrowAstropy",
dimensions=("skymap", "tract", "patch", "band"),
minimum=0,
multiple=True,
deferLoad=True,
)
joint_catalog = cT.Output(
doc="Source catalog with joint detection and measurement",
name="{coaddName}Coadd_anacal_joint",
Expand All @@ -90,6 +101,14 @@ class FpfsJointPipeConfig(
default=100,
)
idGenerator = SkyMapIdGeneratorConfig.make_field()
use_truth_detection = Field[bool](
doc="whether to use truth catalog as detection",
default=False,
)
use_dm_detection = Field[bool](
doc="whether to use dm catalog as detection",
default=False,
)

def validate(self):
super().validate()
Expand Down Expand Up @@ -134,9 +153,30 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
correlation_handles_dict = {
handle.dataId["band"]: handle for handle in correlation_handles
}
detection = None
truth_handles = inputs["truthCatalog"]
if self.config.use_truth_detection:
assert len(truth_handles) > 0
tmp_dict = {
handle.dataId["band"]: handle for handle in truth_handles
}
truth_cat = tmp_dict["i"].get()
detection = np.zeros(
len(truth_cat),
dtype=[
("y", "f8"),
("x", "f8"),
("is_peak", "i4"),
("mask_value", "i4"),
],
)
detection["is_peak"] = 1
detection["y"] = truth_cat["image_y"]
detection["x"] = truth_cat["image_x"]
outputs = self.run(
exposure_handles_dict=exposure_handles_dict,
correlation_handles_dict=correlation_handles_dict,
detection=detection,
)
butlerQC.put(outputs, outputRefs)
return
Expand All @@ -146,6 +186,7 @@ def run(
*,
exposure_handles_dict: dict,
correlation_handles_dict: dict | None,
detection: NDArray | None = None,
):
assert isinstance(self.config, FpfsJointPipeConfig)
band = "i"
Expand All @@ -164,7 +205,7 @@ def run(
exposure=exposure,
seed=seed,
noise_corr=noise_corr,
detection=None,
detection=detection,
band=None,
)
catalog = self.fpfs.run(**data)
Expand Down
2 changes: 2 additions & 0 deletions xlens/sim_pipe/multibandSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs) -> None:
# band name
assert butlerQC.quantum.dataId is not None
band = butlerQC.quantum.dataId["band"]
patch = butlerQC.quantum.dataId["patch"]
inputs["band"] = band
inputs["patch"] = patch

# Get unique integer ID for IdFactory and RNG seeds; only the latter
# should really be used as the IDs all come from the input catalog.
Expand Down
2 changes: 2 additions & 0 deletions xlens/simulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import (
base,
galaxies,
multiband,
multiband_defaults,
perturbation,
Expand All @@ -14,4 +15,5 @@
"perturbation",
"multiband_defaults",
"random",
"galaxies",
]
6 changes: 6 additions & 0 deletions xlens/simulator/galaxies/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import cache_tools, skyCatalog

__all__ = [
"skyCatalog",
"cache_tools",
]
8 changes: 8 additions & 0 deletions xlens/simulator/galaxies/cache_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import functools

from astropy.table import Table


@functools.lru_cache(maxsize=8)
def cached_catalog_read(fname):
return Table.read(fname).as_array()
Loading

0 comments on commit 225c6a6

Please sign in to comment.