Skip to content

Commit

Permalink
feat(sidereal): update SiderealStacker to track effective ra bin centres
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed May 3, 2024
1 parent a2951cd commit 757c5a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
31 changes: 31 additions & 0 deletions draco/analysis/sidereal.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ class SiderealStacker(task.SingleTask):
"""

stack = None
ra_correction = False

tag = config.Property(proptype=str, default="stack")
weight = config.enum(["uniform", "inverse_variance"], default="inverse_variance")
Expand All @@ -591,6 +592,13 @@ def process(self, sdata):
sdata : containers.SiderealStream
Individual sidereal day to add to stack.
"""
# Check that the input container is of the correct type
if (self.stack is not None) and not isinstance(sdata, type(self.stack)):
raise TypeError(
f"type(sdata) (={type(sdata)}) does not match "
f"type(stack) (={type(self.stack)})."
)

sdata.redistribute("freq")

# Get the LSD (or CSD) label out of the input's attributes.
Expand All @@ -609,6 +617,14 @@ def process(self, sdata):
if self.stack is None:
self.stack = containers.empty_like(sdata)

if "effective_ra" in self.stack.datasets:
if self.weight == "uniform":
raise ValueError(
"Uniform weighting is not currently supported with rebinned data."
)

self.ra_correction = True

# Add stack-specific datasets
if "nsample" not in self.stack.datasets:
self.stack.add_dataset("nsample")
Expand Down Expand Up @@ -679,6 +695,21 @@ def process(self, sdata):
# Update the mean.
self.stack.vis[:] += delta_before * tools.invert_no_zero(sum_coeff)

if self.ra_correction:
# Repeat the above process for the `effective_ra` datasets
rebin_weight = sdata.datasets["rebin_weight"][:].local_array
sum_rebin_weight = self.stack.datasets["rebin_weight"][:].local_array

effective_ra = sdata.datasets["effective_ra"][:].local_array
sum_effective_ra = self.stack.datasets["effective_ra"][:].local_array

# Accumulate the inverse variances
sum_rebin_weight += rebin_weight

# Calculate the weighted difference between the new and existing bin centres
delta = rebin_weight * (effective_ra - sum_effective_ra)
sum_effective_ra[:] += delta * tools.invert_no_zero(sum_rebin_weight)

# The calculations below are only required if the sample variance was requested
if self.with_sample_variance:
# Accumulate the sum of squared coefficients.
Expand Down
7 changes: 0 additions & 7 deletions draco/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,13 +1270,6 @@ class SiderealStreamRebin(SiderealStream):
"distributed": True,
"distributed_axis": "freq",
},
"nsample_ra": {
"axes": ["freq", "ra"],
"dtype": np.uint16,
"initialise": False,
"distributed": True,
"distributed_axis": "freq",
},
}


Expand Down

0 comments on commit 757c5a2

Please sign in to comment.