Skip to content

Commit

Permalink
moving PhotoZShiftFactory to source
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimerzp committed Jul 19, 2024
1 parent 89fc70a commit 6f9efe5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 49 deletions.
21 changes: 1 addition & 20 deletions firecrown/likelihood/number_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SourceGalaxyPhotoZShift,
SourceGalaxySelectField,
SourceGalaxySystematic,
PhotoZShiftFactory,
Tracer,
)
from firecrown.metadata.two_point import InferredGalaxyZDist
Expand Down Expand Up @@ -476,26 +477,6 @@ def get_scale(self):
assert self.current_tracer_args
return self.current_tracer_args.scale


class PhotoZShiftFactory(BaseModel):
"""Factory class for PhotoZShift objects."""

model_config = ConfigDict(extra="forbid", frozen=True)

type: Annotated[
Literal["PhotoZShiftFactory"],
Field(description="The type of the systematic."),
] = "PhotoZShiftFactory"

def create(self, bin_name: str) -> PhotoZShift:
"""Create a PhotoZShift object with the given tracer name."""
return PhotoZShift(bin_name)

def create_global(self) -> PhotoZShift:
"""Create a PhotoZShift object with the given tracer name."""
raise ValueError("PhotoZShift cannot be global.")


class LinearBiasSystematicFactory(BaseModel):
"""Factory class for LinearBiasSystematic objects."""

Expand Down
22 changes: 20 additions & 2 deletions firecrown/likelihood/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from abc import abstractmethod
from dataclasses import dataclass, replace
from typing import Generic, Sequence, TypeVar, final
from typing import Generic, Sequence, TypeVar, final, Annotated, Literal

from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
import numpy as np
import numpy.typing as npt
import pyccl
Expand All @@ -32,7 +33,6 @@ class SourceSystematic(Updatable):
def read(self, sacc_data: sacc.Sacc):
"""Call to allow this object to read from the appropriate sacc data."""


class Source(Updatable):
"""An abstract source class (e.g., a sample of lenses).
Expand Down Expand Up @@ -248,6 +248,24 @@ def apply(self, tools: ModelingTools, tracer_arg: _SourceGalaxyArgsT):
dndz=dndz,
)

class PhotoZShiftFactory(BaseModel):
"""Factory class for PhotoZShift objects."""

model_config = ConfigDict(extra="forbid", frozen=True)

type: Annotated[
Literal["PhotoZShiftFactory"],
Field(description="The type of the systematic."),
] = "PhotoZShiftFactory"

def create(self, bin_name: str) -> PhotoZShift:
"""Create a PhotoZShift object with the given tracer name."""
return PhotoZShift(bin_name)

def create_global(self) -> PhotoZShift:
"""Create a PhotoZShift object with the given tracer name."""
raise ValueError("PhotoZShift cannot be global.")


class SourceGalaxySelectField(
SourceGalaxySystematic[_SourceGalaxyArgsT], Generic[_SourceGalaxyArgsT]
Expand Down
28 changes: 1 addition & 27 deletions firecrown/likelihood/weak_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SourceGalaxyPhotoZShift,
SourceGalaxySelectField,
SourceGalaxySystematic,
PhotoZShiftFactory,
Tracer,
)
from firecrown.metadata.two_point import InferredGalaxyZDist
Expand Down Expand Up @@ -430,33 +431,6 @@ def create_global(self) -> TattAlignmentSystematic:
"""
return TattAlignmentSystematic(None)


class PhotoZShiftFactory(BaseModel):
"""Factory class for PhotoZShift objects."""

model_config = ConfigDict(extra="forbid", frozen=True)

type: Annotated[
Literal["PhotoZShiftFactory"], Field(description="The type of the systematic.")
] = "PhotoZShiftFactory"

def create(self, bin_name: str) -> PhotoZShift:
"""Create a PhotoZShift object.
:param inferred_zdist: The inferred galaxy redshift distribution for
the created PhotoZShift object.
:return: The created PhotoZShift object.
"""
return PhotoZShift(bin_name)

def create_global(self) -> PhotoZShift:
"""Create a PhotoZShift object.
:return: The created PhotoZShift object.
"""
raise ValueError("PhotoZShift cannot be global")


WeakLensingSystematicFactory = Annotated[
MultiplicativeShearBiasFactory
| LinearAlignmentSystematicFactory
Expand Down

0 comments on commit 6f9efe5

Please sign in to comment.