Skip to content

Add HWP Jones Formalism with Band Integration#499

Open
mj-gomes wants to merge 103 commits intomasterfrom
add_jones_to_hwp_harmonics
Open

Add HWP Jones Formalism with Band Integration#499
mj-gomes wants to merge 103 commits intomasterfrom
add_jones_to_hwp_harmonics

Conversation

@mj-gomes
Copy link
Copy Markdown
Contributor

@mj-gomes mj-gomes commented Feb 20, 2026

This PR should now be fully compatible with all the recent changes in the master branch. It uses the multi-frequency capabilities of HealpixMap to ease the simplification of the integration in band.

It is now possible to insert a Jones matrix, or a .csv file like the following:

image

Where we have a column for the frequency in GHz, then one column for each Jones element - amplitude and phase - in both 0f and 2f.

Still left to do before merging:

  • fix ty errors
  • Add test for the band integration
  • Add notebook for the band integration
  • Update docs
  • Optimize trapezoidal integration

@mj-gomes mj-gomes self-assigned this Mar 24, 2026
@mj-gomes mj-gomes added enhancement New feature or request python Pull requests that update python code and removed python Pull requests that update python code labels Mar 24, 2026
- Change the `Calc` name into `HWPFormalism`

- Move the code that loads CSV files containing Jones coefficients into
a new class, `HWPJonesParams` and avoid using files explicitly (this
eases the transition to IMo objects when these CSV files will be stored
there)

- Implement a way to load CSV files from streams and the IMo

- Move the class `NonIdealHWP` in a separate file to prevent circular
imports

- Add typing information (partially)
Copy link
Copy Markdown
Member

@ziotom78 ziotom78 left a comment

Choose a reason for hiding this comment

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

Hi Miguel, I implemented the ability to load the CSV files containing Jones coefficients from the IMo. This required several changes, but now the API is much more similar to the one we use to load DetectorInfo objects and similar:

  • IMo objects are associated with a dataclass (in this case, HWPJonesParams)
  • A static method .from_imo() returns the dataclass
  • The dataclass is passed to functions, not the file name

There is still some work to do because tests do not pass yet using ty. It should be quick to fix them.

Comment on lines +62 to +91
mueller10deg = {
"0f": np.array(
[
[0.961, 8.83 * 1e-5, -7.87 * 1e-6],
[9.60 * 1e-5, 1.88 * 1e-4, 4.87 * 1e-4],
[4.39 * 1e-6, -4.63 * 1e-4, 7.48 * 1e-4],
],
dtype=np.float64,
),
"2f": np.array(
[
[4.89 * 1e-6, 5.15 * 1e-4, 5.16 * 1e-4],
[5.43 * 1e-4, 3.10 * 1e-3, 3.28 * 1e-3],
[5.42 * 1e-4, 2.96 * 1e-3, 3.24 * 1e-3],
],
dtype=np.float64,
),
"4f": np.array(
[
[1.09 * 1e-7, 9.26 * 1e-5, 9.25 * 1e-5],
[8.86 * 1e-5, 0.959, 0.959],
[8.86 * 1e-5, 0.959, 0.959],
],
dtype=np.float64,
),
}

f_factor = (
np.sin(np.deg2rad(0.078 * Theta)) ** 2 / np.sin(np.deg2rad(0.078 * 10)) ** 2
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These seem magic numbers… If they are the coefficients of Mueller matrices for the four frequencies 0f, 2f, and 4f, they should be read from the IMo. (The same for the magic factor 0.078.)

The LBS code is public, and we should not put data related to the instrument here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, these are the obtained values for a hwp at Theta=10º, that we use to make the interpolation when we want to obtain the values for another Theta (according to the interpolation in https://arxiv.org/pdf/2308.00967)

However, these were done for a previous version of the HWP, where we did not have jones matrices, and for a specific frequency, so we can in fact delete them now. I doubt we'll need this interpolation with this specific values again.

return [det_params, bpi]


def fill_tod(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that fill_tod is imported in litebird_sim/__init__.py, a more specific name would be helpful here. What do you think about fill_tod_with_hwp_harmonics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, the name is a bit long but I can't see a better option

@mj-gomes
Copy link
Copy Markdown
Contributor Author

Hi Miguel, I implemented the ability to load the CSV files containing Jones coefficients from the IMo. This required several changes, but now the API is much more similar to the one we use to load DetectorInfo objects and similar:

  • IMo objects are associated with a dataclass (in this case, HWPJonesParams)
  • A static method .from_imo() returns the dataclass
  • The dataclass is passed to functions, not the file name

Thanks a lot!

There is still some work to do because tests do not pass yet using ty. It should be quick to fix them.

Ok, I will look into this so that we can merge this.

@mj-gomes
Copy link
Copy Markdown
Contributor Author

@ziotom78 It is ready to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants