Skip to content

Commit

Permalink
make the pipeline compatible with the HSC configure
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-superonion committed Dec 15, 2024
1 parent 7a1e3a7 commit 8a0cb9d
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 39 deletions.
5 changes: 4 additions & 1 deletion examples/anacal_dm/hsc_calibration/skymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
config.skyMap["discrete"].decList = [41.269] # degrees
config.skyMap["discrete"].radiusList = [5.0] # degrees
config.skyMap["discrete"].pixelScale = 0.168 # HSC arcsec/pixel
config.skyMap["discrete"].patchInnerDimensions = [500, 500] # in pixels # change it to [5000, 5000]
config.skyMap["discrete"].patchInnerDimensions = [
500,
500,
] # in pixels # change it to [5000, 5000]
config.skyMap["discrete"].projection = "TAN"
config.skyMap["discrete"].tractOverlap = 0
config.name = "hsc_sim"
6 changes: 5 additions & 1 deletion xlens/process_pipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from . import (
fpfs_force, fpfs_joint, fpfs_multiband, systematics_multiband, hsc,
fpfs_force,
fpfs_joint,
fpfs_multiband,
systematics_multiband,
hsc,
detect_multiband,
)

Expand Down
24 changes: 13 additions & 11 deletions xlens/process_pipe/detect_multiband.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from lsst.pipe.base import (
Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections,
Struct,
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
)
import lsst.pipe.base.connectionTypes as cT
from lsst.pex.config import ConfigurableField
Expand All @@ -12,7 +15,7 @@
class DetectCoaddSourcesConnections(
PipelineTaskConnections,
dimensions=("tract", "patch", "band", "skymap"),
defaultTemplates={"inputCoaddName": "deep", "outputCoaddName": "deep"}
defaultTemplates={"inputCoaddName": "deep", "outputCoaddName": "deep"},
):
detectionSchema = cT.InitOutput(
doc="Schema of the detection catalog",
Expand All @@ -23,31 +26,30 @@ class DetectCoaddSourcesConnections(
doc="Exposure post detection",
name="{outputCoaddName}Coadd_calexp",
storageClass="ExposureF",
dimensions=("tract", "patch", "band", "skymap")
dimensions=("tract", "patch", "band", "skymap"),
)
outputBackgrounds = cT.Output(
doc="Output Backgrounds used in detection",
name="{outputCoaddName}Coadd_calexp_background",
storageClass="Background",
dimensions=("tract", "patch", "band", "skymap")
dimensions=("tract", "patch", "band", "skymap"),
)
outputSources = cT.Output(
doc="Detected sources catalog",
name="{outputCoaddName}Coadd_det",
storageClass="SourceCatalog",
dimensions=("tract", "patch", "band", "skymap")
dimensions=("tract", "patch", "band", "skymap"),
)


class DetectCoaddSourcesConfig(
PipelineTaskConfig,
pipelineConnections=DetectCoaddSourcesConnections
PipelineTaskConfig, pipelineConnections=DetectCoaddSourcesConnections
):
"""Configuration parameters for the DetectCoaddSourcesTask
"""
"""Configuration parameters for the DetectCoaddSourcesTask"""

detection = ConfigurableField(
target=DynamicDetectionTask, doc="Source detection",
target=DynamicDetectionTask,
doc="Source detection",
)
idGenerator = SkyMapIdGeneratorConfig.make_field()

Expand All @@ -60,7 +62,7 @@ def setDefaults(self):
self.detection.reEstimateBackground = False
self.detection.background.useApprox = False
self.detection.background.binSize = 4096
self.detection.background.undersampleStyle = 'REDUCE_INTERP_ORDER'
self.detection.background.undersampleStyle = "REDUCE_INTERP_ORDER"
# Suppress large footprints that overwhelm the deblender
self.detection.doTempWideBackground = True
# Include band in packed data IDs that go into object IDs (None -> "as
Expand Down
6 changes: 3 additions & 3 deletions xlens/process_pipe/fpfs_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def run(
assert isinstance(self.config, FpfsForcePipeConfig)
det_names = ["y", "x", "fpfs_w", "fpfs_dw_dg1", "fpfs_dw_dg2"]
det = (
joint_catalog[det_names].to_pandas(
index=False
).to_records(index=False)
joint_catalog[det_names]
.to_pandas(index=False)
.to_records(index=False)
)
catalog = [det]
for band in exposure_handles_dict.keys():
Expand Down
8 changes: 4 additions & 4 deletions xlens/process_pipe/hsc/systematics_multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ def get_noise_corr(self, exposure):
"the estimated image noise variance should be positive."
)

window_array = (exposure.mask.array == 0).astype(
np.float32
)[1000: 3000, 1000: 3000]
window_array = (exposure.mask.array == 0).astype(np.float32)[
1000:3000, 1000:3000
]
noise_array = (
np.asarray(
exposure.getMaskedImage().image.array,
dtype=np.float32,
)[1000: 3000, 1000: 3000]
)[1000:3000, 1000:3000]
* window_array
)

Expand Down
12 changes: 9 additions & 3 deletions xlens/process_pipe/measure_multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class MeasureMergedCoaddSourcesConnections(
"sources",
name="ref_cat",
storageClass="SimpleCatalog",
dimensions=("tract", "patch", "skymap",),
dimensions=(
"tract",
"patch",
"skymap",
),
deferLoad=True,
multiple=True,
minimum=0,
Expand Down Expand Up @@ -140,8 +144,10 @@ class MeasureMergedCoaddSourcesConfig(
doWriteMatchesDenormalized = Field(
dtype=bool,
default=False,
doc=("Write reference matches in denormalized format? "
"This format uses more disk space, but more convenient to read."),
doc=(
"Write reference matches in denormalized format? "
"This format uses more disk space, but more convenient to read."
),
deprecated="Reference matching will be removed after v29.",
)
psfCache = Field(dtype=int, default=100, doc="Size of psfCache")
Expand Down
4 changes: 1 addition & 3 deletions xlens/processor/fpfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def rotate90(image):
else:
noise_array = None
if detection is not None:
detection = np.array(
detection[["y", "x", "is_peak", "mask_value"]]
)
detection = np.array(detection[["y", "x", "is_peak", "mask_value"]])

if not self.config.use_average_psf:
psf_object = utils.LsstPsf(psf=lsst_psf, npix=self.config.npix)
Expand Down
10 changes: 5 additions & 5 deletions xlens/putils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def chunk_list(lst, num_chunks):
return chunks


butler_setup_script = '''
butler_setup_script = """
butler create .
butler register-skymap ./ --config-file skymap.py
butler register-instrument ./ lsst.obs.subaru.HyperSuprimeCam
'''
"""

sky_map_script = '''
sky_map_script = """
config.name = "hsc"
config.skyMap = "rings"
Expand All @@ -38,7 +38,7 @@ def chunk_list(lst, num_chunks):
config.skyMap["rings"].projection = "TAN"
config.skyMap["rings"].tractOverlap = 1.0 / 60
config.skyMap["rings"].pixelScale = 0.168 # arcsec/pixel
'''
"""


def run(
Expand Down Expand Up @@ -107,7 +107,7 @@ def run(
["bash", "butler_setup.sh"],
capture_output=True,
text=True,
check=True
check=True,
)
assert result.returncode == 0

Expand Down
4 changes: 2 additions & 2 deletions xlens/putils/torque/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
template_string = '''#!/bin/bash
template_string = """#!/bin/bash
#PBS -S /bin/bash
#PBS -N ${jobname}
Expand All @@ -18,4 +18,4 @@
pipetask run -b ./ -j ${tasks_per_node} -i ${input_collection} -o ${output_collection} -p ${config_file_name} -d "skymap='${skymap_name}' AND tract in (${tract_list}) AND band in ('g', 'r', 'i', 'z', 'y')" --register-dataset-types --skip-existing --clobber-outputs
'''
"""
3 changes: 2 additions & 1 deletion xlens/sim_pipe/multibandSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from lsst.skymap import BaseSkyMap

from ..simulator.multiband import (
MultibandSimShearTask, MultibandSimHaloTask,
MultibandSimShearTask,
MultibandSimHaloTask,
)


Expand Down
7 changes: 2 additions & 5 deletions xlens/simulator/multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def validate(self):
self.__class__.irng, self, "We require 0 <= irng < 10"
)


def setDefaults(self):
super().setDefaults()
self.survey_name = self.survey_name.lower()
Expand Down Expand Up @@ -296,12 +295,10 @@ def run(
print("No correlation, variance:", variance)
else:
noise_corr = noiseCorrImage.getArray()
variance = np.amax(
noise_corr
)
variance = np.amax(noise_corr)
noise_corr = noise_corr / variance
ny, nx = noise_corr.shape
assert noise_corr[ny//2, nx//2] == 1
assert noise_corr[ny // 2, nx // 2] == 1
print("With correlation, variance:", variance)
noise_std = np.sqrt(variance)

Expand Down

0 comments on commit 8a0cb9d

Please sign in to comment.