Skip to content

Commit

Permalink
add addNoise task
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-superonion committed Dec 19, 2024
1 parent a1bb891 commit 048de71
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 61 deletions.
2 changes: 1 addition & 1 deletion xlens/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from . import (
catalog,
putils,
process_pipe,
processor,
putils,
sim_pipe,
simulator,
summary_pipe,
Expand Down
6 changes: 3 additions & 3 deletions xlens/process_pipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from . import (
detect_multiband,
force_multiband,
fpfs_force,
fpfs_joint,
systematics_multiband,
hsc,
detect_multiband,
force_multiband,
systematics_multiband,
)

__all__ = [
Expand Down
14 changes: 7 additions & 7 deletions xlens/process_pipe/detect_multiband.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.pipe.base.connectionTypes as cT
from lsst.meas.algorithms import DynamicDetectionTask
from lsst.meas.base import SkyMapIdGeneratorConfig
from lsst.pex.config import ConfigurableField
from lsst.pipe.base import (
Struct,
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
Struct,
)
import lsst.pipe.base.connectionTypes as cT
from lsst.pex.config import ConfigurableField
from lsst.meas.algorithms import DynamicDetectionTask
from lsst.meas.base import SkyMapIdGeneratorConfig
import lsst.afw.table as afwTable
import lsst.afw.math as afwMath


class DetectCoaddSourcesConnections(
Expand Down
20 changes: 10 additions & 10 deletions xlens/process_pipe/measure_multiband.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from lsst.pipe.base import (
Struct,
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
)
import lsst.afw.table as afwTable
import lsst.pipe.base.connectionTypes as cT
from lsst.pex.config import Field, ConfigurableField
from lsst.daf.base import PropertyList
from lsst.meas.algorithms import SetPrimaryFlagsTask
from lsst.meas.astrom import DirectMatchTask
from lsst.meas.base import (
SingleFrameMeasurementTask,
CatalogCalculationTask,
SingleFrameMeasurementTask,
SkyMapIdGeneratorConfig,
)
from lsst.meas.extensions.scarlet.io import updateCatalogFootprints
import lsst.afw.table as afwTable
from lsst.daf.base import PropertyList
from lsst.pex.config import ConfigurableField, Field
from lsst.pipe.base import (
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
Struct,
)
from lsst.skymap import BaseSkyMap


Expand Down
2 changes: 1 addition & 1 deletion xlens/processor/fpfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from lsst.afw.image import ExposureF
from lsst.pex.config import Config, Field, FieldValidationError, ListField
from numpy.typing import NDArray
from ..simulator.random import get_noise_seed, num_rot

from ..simulator.random import get_noise_seed, num_rot
from . import utils
from .base import MeasBaseTask

Expand Down
12 changes: 8 additions & 4 deletions xlens/processor/fpfs_simplesim.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
from lsst.pipe.base import Task
from numpy.typing import NDArray

from .fpfs import FpfsMeasurementTask
from ..simulator.simplesim import SimpleSimShearTask
from .fpfs import FpfsMeasurementTask


class FpfsSimpleSimConfig(Config):
Expand Down Expand Up @@ -78,8 +78,10 @@ def validate(self):
)
if not os.path.isdir(self.simulator.root_dir):
raise FileNotFoundError("Cannot find root_dir")
if self.simulator.draw_image_noise != \
self.fpfs.do_noise_bias_correction:
if (
self.simulator.draw_image_noise
!= self.fpfs.do_noise_bias_correction
):
raise ValueError(
"simulator.draw_image noise not equal"
"fpfs.do_noise_bias_correction"
Expand Down Expand Up @@ -148,7 +150,9 @@ def run(self, ifield: int) -> NDArray:
if os.path.isfile(name):
res = fitsio.read(name)
else:
res = self.process_data(ifield=ifield, mode=mode, rotId=rotId)
res = self.process_data(
ifield=ifield, mode=mode, rotId=rotId
)
self.write_fpfs_src(
ifield=ifield,
mode=mode,
Expand Down
4 changes: 3 additions & 1 deletion xlens/putils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from . import torque
import subprocess

import numpy as np
from astropy.table import Table

from . import torque


def chunk_list(lst, num_chunks):
lst = lst.astype("str")
Expand Down
5 changes: 3 additions & 2 deletions xlens/putils/torque/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import subprocess
import time
from .template import template_string
from string import Template
import subprocess

from .template import template_string

gw_node_list = [
"hpcs005",
Expand Down
2 changes: 1 addition & 1 deletion xlens/sim_pipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import multibandSim, addNoise
from . import addNoise, multibandSim

__all__ = ["multibandSim", "addNoise"]
22 changes: 9 additions & 13 deletions xlens/sim_pipe/addNoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
# GNU General Public License for more details.
#
from typing import Any
import numpy as np
import lsst.afw.image as afwImage

import lsst.afw.image as afwImage
import lsst.pipe.base.connectionTypes as cT
import numpy as np
from lsst.meas.base import SkyMapIdGeneratorConfig
from lsst.pex.config import Field, FieldValidationError
from lsst.pipe.base import (
Struct,
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
Struct,
)
from lsst.pex.config import Field, FieldValidationError

from ..simulator.multiband import get_noise_array
from ..simulator.random import get_noise_seed, num_rot
from ..simulator.multiband_defaults import noise_variance_defaults

from ..simulator.random import get_noise_seed, num_rot


class MultibandSimPipeConnections(
Expand Down Expand Up @@ -59,7 +59,7 @@ class MultibandSimPipeConnections(
)
outputExposure = cT.Output(
doc="Output simulated coadd exposure",
name="{outputCoaddName}_{mode}_rot{rotId}_noise{noiseId}_Coadd_calexp",
name="{outputCoaddName}_noise{noiseId}_{mode}_rot{rotId}_Coadd_calexp",
storageClass="ExposureF",
dimensions=("skymap", "tract", "patch", "band"),
)
Expand Down Expand Up @@ -94,9 +94,7 @@ def validate(self):
)
if self.noiseId < 0 or self.noiseId >= 10:
raise FieldValidationError(
self.__class__.noiseId,
self,
"We require 0 <= noiseId < 10"
self.__class__.noiseId, self, "We require 0 <= noiseId < 10"
)

def setDefaults(self):
Expand Down Expand Up @@ -169,6 +167,4 @@ def run(
exposure.getMaskedImage().image.array[:, :] + noise_array
)

return Struct(
outputExposure=exposure
)
return Struct(outputExposure=exposure)
5 changes: 1 addition & 4 deletions xlens/sim_pipe/multibandSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
from lsst.pipe.tasks.coaddBase import makeSkyInfo
from lsst.skymap import BaseSkyMap

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


class MultibandSimPipeConnections(
Expand Down
10 changes: 8 additions & 2 deletions xlens/simulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from . import base, multiband, multiband_defaults, perturbation, simplesim
from . import random
from . import (
base,
multiband,
multiband_defaults,
perturbation,
random,
simplesim,
)

__all__ = [
"base",
Expand Down
14 changes: 3 additions & 11 deletions xlens/simulator/multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
from numpy.typing import NDArray

from ..processor.utils import resize_array
from ..simulator.random import (
get_noise_seed,
gal_seed_base,
num_rot,
)
from ..simulator.random import gal_seed_base, get_noise_seed, num_rot
from .base import SimBaseTask
from .multiband_defaults import (
mag_zero_defaults,
Expand Down Expand Up @@ -117,19 +113,15 @@ def validate(self):
super().validate()
if self.galId >= 10 or self.galId < 0:
raise FieldValidationError(
self.__class__.galId,
self,
"We require 0 <= galId < 10"
self.__class__.galId, self, "We require 0 <= galId < 10"
)
if self.rotId >= num_rot:
raise FieldValidationError(
self.__class__.rotId, self, "rotId needs to be smaller than 2"
)
if self.noiseId < 0 or self.noiseId >= 10:
raise FieldValidationError(
self.__class__.noiseId,
self,
"We require 0 <= noiseId < 10"
self.__class__.noiseId, self, "We require 0 <= noiseId < 10"
)

def setDefaults(self):
Expand Down
1 change: 0 additions & 1 deletion xlens/simulator/random.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

image_noise_base = 20
gal_seed_base = 10

Expand Down

0 comments on commit 048de71

Please sign in to comment.