Skip to content

Infrastructure improvements for power spectrum fitting #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

albinje
Copy link

@albinje albinje commented May 16, 2025

No description provided.

@albinje albinje requested a review from sjforeman May 16, 2025 17:28
Copy link

@sjforeman sjforeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Albin! There are just a few minor cleanups we should do before merging these updates

print(f"Directory {d} does not match expected format, rejecting")
continue

key = mo.group(1)
print(f"Processing directory: {d}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(f"Processing directory: {d}")
logger.debug(f"Processing directory: {d}")

Let's move to using logger instead of print. (There's a mix of logger and print throughout fitstack, and we should eventually change all the other print statements to use logger for consistency.)

Comment on lines +973 to +975
nu21: float = 1420.40575177, # MHz
z_eff: Optional[float] = None, # effective redshift
cs: float = 299792.458, # speed of light in km/s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nu21: float = 1420.40575177, # MHz
z_eff: Optional[float] = None, # effective redshift
cs: float = 299792.458, # speed of light in km/s
z_eff: Optional[float] = None, # effective redshift

nu21 and the speed of light are defined in cora.util.units, so we should use those definitions.

Comment on lines +979 to +985

# Set default z_eff if None
self.z_eff = z_eff if z_eff is not None else 1.0
cosmo_cora = cosmology.Cosmology()
self.H_z = cosmo_cora.H(self.z_eff) * u.mega_parsec / 1000. # In km/s/Mpc
self.nu21 = nu21
self.cs = cs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Set default z_eff if None
self.z_eff = z_eff if z_eff is not None else 1.0
cosmo_cora = cosmology.Cosmology()
self.H_z = cosmo_cora.H(self.z_eff) * u.mega_parsec / 1000. # In km/s/Mpc
self.nu21 = nu21
self.cs = cs
# Set default z_eff if None
self.z_eff = z_eff if z_eff is not None else 1.0
cosmo_cora = cosmology.Cosmology()
self.H_z = cosmo_cora.H(self.z_eff) * u.mega_parsec / 1000. # In km/s/Mpc

Remove local values of nu21 and cs

Conversion factor
"""

C = (-1.0 / (2 * np.pi * self.nu21)) * (self.cs / self.H_z) * (1 + self.z_eff)**2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
C = (-1.0 / (2 * np.pi * self.nu21)) * (self.cs / self.H_z) * (1 + self.z_eff)**2
C = (-1.0 / (2 * np.pi * u.nu21)) * ((u.c / u.kilo) / self.H_z) * (1 + self.z_eff)**2

Use cora's nu21 and speed of light.

Also, let's add a comment about the assumed units of k_parallel and tau that this factor is converting between.

@@ -1101,7 +1140,9 @@ def multiply_pre_noncomp(self, signal: np.ndarray, **kwargs) -> np.ndarray:
signal : np.ndarray[npol, nkpar, nkperp]
The 2d power spectrum after multiplication with the relative FoG kernel.
"""

# Calculate the conversion factor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Calculate the conversion factor
# Calculate the conversion factor that converts from k_parallel to tau

Comment on lines +1164 to +1165
signal *= (1.0 + (scale0 * C * self.kpar[np.newaxis, :, np.newaxis]) ** 2) / (
1.0 + (scale * C * self.kpar[np.newaxis, :, np.newaxis]) ** 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be useful to have a comment here about the units of kpar and scale0

@@ -424,7 +424,16 @@ def average_data(cnt, pol=None, combine=True, sort=True):
distributed=False,
)
avg.ps2D[:] = np.mean(darr, axis=0)
avg.ps2D_weight[:] = tools.invert_no_zero(np.var(darr, axis=0))
#avg.ps2D_weight[:] = tools.invert_no_zero(np.var(darr, axis=0))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#avg.ps2D_weight[:] = tools.invert_no_zero(np.var(darr, axis=0))

Remove unneeded comment

@albinje albinje closed this Jun 26, 2025
@albinje albinje deleted the auto_ps branch June 26, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants