litebird_sim 0.12.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. default_imo/schema.json.gz +0 -0
  2. images/logo.png +0 -0
  3. litebird_sim/__init__.py +287 -0
  4. litebird_sim/bandpasses.py +344 -0
  5. litebird_sim/compress.py +41 -0
  6. litebird_sim/constants.py +14 -0
  7. litebird_sim/coordinates.py +314 -0
  8. litebird_sim/datautils/Cls_Planck2018_for_PTEP_2020_r0.fits +0 -0
  9. litebird_sim/datautils/Cls_Planck2018_for_PTEP_2020_tensor_r1.fits +0 -0
  10. litebird_sim/detectors.py +435 -0
  11. litebird_sim/dipole.py +308 -0
  12. litebird_sim/distribute.py +218 -0
  13. litebird_sim/gaindrifts.py +600 -0
  14. litebird_sim/healpix.py +395 -0
  15. litebird_sim/hwp.py +145 -0
  16. litebird_sim/hwp_sys/__init__.py +1 -0
  17. litebird_sim/hwp_sys/bandpass_template_module.py +218 -0
  18. litebird_sim/hwp_sys/examples/HWP_systematics.txt +4 -0
  19. litebird_sim/hwp_sys/examples/MFT_100_h_beta_z.txt +23 -0
  20. litebird_sim/hwp_sys/examples/simple_scan.ipynb +1648 -0
  21. litebird_sim/hwp_sys/hwp_sys.py +1392 -0
  22. litebird_sim/imo/__init__.py +12 -0
  23. litebird_sim/imo/imo.py +178 -0
  24. litebird_sim/imobrowser.py +360 -0
  25. litebird_sim/install_imo.py +278 -0
  26. litebird_sim/io.py +646 -0
  27. litebird_sim/madam.py +461 -0
  28. litebird_sim/mapmaking/__init__.py +32 -0
  29. litebird_sim/mapmaking/binner.py +396 -0
  30. litebird_sim/mapmaking/common.py +567 -0
  31. litebird_sim/mapmaking/destriper.py +2078 -0
  32. litebird_sim/mbs/__init__.py +3 -0
  33. litebird_sim/mbs/fg_models/pysm_ame_1.cfg +21 -0
  34. litebird_sim/mbs/fg_models/pysm_dust_0.cfg +16 -0
  35. litebird_sim/mbs/fg_models/pysm_dust_1.cfg +16 -0
  36. litebird_sim/mbs/fg_models/pysm_dust_4.cfg +32 -0
  37. litebird_sim/mbs/fg_models/pysm_dust_5.cfg +23 -0
  38. litebird_sim/mbs/fg_models/pysm_dust_7.cfg +23 -0
  39. litebird_sim/mbs/fg_models/pysm_dust_8.cfg +24 -0
  40. litebird_sim/mbs/fg_models/pysm_freefree_1.cfg +9 -0
  41. litebird_sim/mbs/fg_models/pysm_synch_0.cfg +14 -0
  42. litebird_sim/mbs/fg_models/pysm_synch_1.cfg +14 -0
  43. litebird_sim/mbs/mbs.py +1016 -0
  44. litebird_sim/mpi.py +62 -0
  45. litebird_sim/noise.py +248 -0
  46. litebird_sim/observations.py +708 -0
  47. litebird_sim/pointings.py +221 -0
  48. litebird_sim/quaternions.py +404 -0
  49. litebird_sim/scan_map.py +217 -0
  50. litebird_sim/scanning.py +904 -0
  51. litebird_sim/simulations.py +1779 -0
  52. litebird_sim/spacecraft.py +448 -0
  53. litebird_sim/toast_destriper/__init__.py +432 -0
  54. litebird_sim/version.py +4 -0
  55. litebird_sim-0.12.0.dist-info/LICENSE +674 -0
  56. litebird_sim-0.12.0.dist-info/METADATA +214 -0
  57. litebird_sim-0.12.0.dist-info/RECORD +73 -0
  58. litebird_sim-0.12.0.dist-info/WHEEL +4 -0
  59. static/report_template.html +47 -0
  60. static/sakura.css +165 -0
  61. templates/madam_parameter_file.txt +44 -0
  62. templates/madam_simulation_file.txt +38 -0
  63. templates/report_appendix.md +66 -0
  64. templates/report_binned_map.md +6 -0
  65. templates/report_binned_map_splits.md +8 -0
  66. templates/report_destriper.md +30 -0
  67. templates/report_dipole.md +9 -0
  68. templates/report_gaindrift.md +25 -0
  69. templates/report_header.md +14 -0
  70. templates/report_noise.md +3 -0
  71. templates/report_pointings.md +8 -0
  72. templates/report_quaternions.md +7 -0
  73. templates/report_scan_map.md +8 -0
@@ -0,0 +1,314 @@
1
+ # -*- encoding: utf-8 -*-
2
+ from numba import njit
3
+ import numpy as np
4
+
5
+ from astropy.coordinates import BarycentricMeanEcliptic
6
+ from astropy.coordinates import SkyCoord
7
+
8
+ from enum import Enum
9
+
10
+ """The coordinate system used by the framework"""
11
+ DEFAULT_COORDINATE_SYSTEM = BarycentricMeanEcliptic()
12
+
13
+ """The time scale used by the framework"""
14
+ DEFAULT_TIME_SCALE = "tdb"
15
+
16
+ ECL_TO_GAL_ROT_MATRIX = (
17
+ SkyCoord(
18
+ x=[1.0, 0.0, 0.0],
19
+ y=[0.0, 1.0, 0.0],
20
+ z=[0.0, 0.0, 1.0],
21
+ frame=DEFAULT_COORDINATE_SYSTEM.name,
22
+ representation_type="cartesian",
23
+ )
24
+ .transform_to("galactic")
25
+ .data.to_cartesian()
26
+ .get_xyz()
27
+ .value
28
+ )
29
+
30
+ NORTH_POLE_VEC = np.tensordot(ECL_TO_GAL_ROT_MATRIX, [0.0, 0.0, 1.0], axes=(1, 0))
31
+
32
+ """
33
+ The coordinate system used to express pointing angles.
34
+ """
35
+ CoordinateSystem = Enum("CoordinateSystem", ["Ecliptic", "Galactic"])
36
+
37
+ _COORD_SYS_TO_HEALPIX = {
38
+ CoordinateSystem.Ecliptic: "ECLIPTIC",
39
+ CoordinateSystem.Galactic: "GALACTIC",
40
+ }
41
+
42
+
43
+ def coord_sys_to_healpix_string(coordsys: CoordinateSystem) -> str:
44
+ """Convert the value of a :class:`.CoordinateSystem` instance into a string
45
+
46
+ The string is suitable to be saved in a FITS file containing a Healpix map"""
47
+ return _COORD_SYS_TO_HEALPIX[coordsys]
48
+
49
+
50
+ def ang2vec(theta, phi):
51
+ """Transform a direction theta,phi to a unit vector.
52
+
53
+ Parameters
54
+ ----------
55
+ theta : float, scalar or array-like
56
+ The angle theta (scalar or shape (N,))
57
+ phi : float, scalar or array-like
58
+ The angle phi (scalar or shape (N,)).
59
+
60
+ Returns
61
+ -------
62
+ vec : array
63
+ The vector(s) corresponding to given angles, shape is (3,) or (3, N).
64
+
65
+ See Also
66
+ --------
67
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L657
68
+ """
69
+ ct, st, cp, sp = np.cos(theta), np.sin(theta), np.cos(phi), np.sin(phi)
70
+ vec = np.empty((3, ct.size), np.float64)
71
+ vec[0, :] = st * cp
72
+ vec[1, :] = st * sp
73
+ vec[2, :] = ct
74
+ return vec.squeeze()
75
+
76
+
77
+ def vec2ang(vx, vy, vz):
78
+ """Transform a vector to angle given by theta,phi.
79
+
80
+ Parameters
81
+ ----------
82
+ vx : float, scalar or array-like
83
+ The x component of the vector (scalar or shape (N,))
84
+ vy : float, scalar or array-like, optional
85
+ The y component of the vector (scalar or shape (N,))
86
+ vz : float, scalar or array-like, optional
87
+ The z component of the vector (scalar or shape (N,))
88
+
89
+ Returns
90
+ -------
91
+ angles : float, array
92
+ The angles in radiants in an array of shape (2, N)
93
+
94
+ See Also
95
+ --------
96
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L610
97
+ """
98
+
99
+ ang = np.empty((2, vx.size))
100
+ ang[0, :] = np.arctan2(np.sqrt(vx**2 + vy**2), vz)
101
+ ang[1, :] = np.arctan2(vy, vx)
102
+ return ang.squeeze()
103
+
104
+
105
+ @njit
106
+ def _ang2galvec_one_sample(theta, phi):
107
+ """Transform a direction (theta, phi) in Ecliptic coordinates to
108
+ a unit vector in Galactic coordinates.
109
+
110
+ Parameters
111
+ ----------
112
+ theta : float, scalar
113
+ The angle θ (colatitude) in Ecliptic coordinates
114
+ phi : float, scalar
115
+ The angle φ (longitude) in Ecliptic coordinates
116
+
117
+ Returns
118
+ -------
119
+ vx, vy, vz : float
120
+ A tuple of three floats
121
+
122
+ See Also
123
+ --------
124
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L657
125
+ """
126
+
127
+ rotmatr = ECL_TO_GAL_ROT_MATRIX
128
+ st = np.sin(theta)
129
+ vx, vy, vz = st * np.cos(phi), st * np.sin(phi), np.cos(theta)
130
+
131
+ return (
132
+ rotmatr[0, 0] * vx + rotmatr[0, 1] * vy + rotmatr[0, 2] * vz,
133
+ rotmatr[1, 0] * vx + rotmatr[1, 1] * vy + rotmatr[1, 2] * vz,
134
+ rotmatr[2, 0] * vx + rotmatr[2, 1] * vy + rotmatr[2, 2] * vz,
135
+ )
136
+
137
+
138
+ @njit
139
+ def _vec2ang_for_one_sample(vx, vy, vz):
140
+ """Transform a vector to angle given by theta,phi.
141
+
142
+ Parameters
143
+ ----------
144
+ vx : float, scalar
145
+ The x component of the vector (scalar)
146
+ vy : float, scalar
147
+ The y component of the vector (scalar))
148
+ vz : float, scalar
149
+ The z component of the vector (scalar)
150
+
151
+ Returns
152
+ -------
153
+ theta, phi : float
154
+ A tuple containing the value of the colatitude and of the longitude
155
+
156
+ See Also
157
+ --------
158
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L610
159
+ """
160
+
161
+ return (np.arctan2(np.sqrt(vx**2 + vy**2), vz), np.arctan2(vy, vx))
162
+
163
+
164
+ @njit
165
+ def _rotate_coordinates_e2g_for_one_sample(pointings_ecl):
166
+ """
167
+ Parameters
168
+ ----------
169
+ pointings_ecl : array
170
+ ``(2)`` array containing the colatitude and the longitude in ecliptic
171
+ coordinates
172
+
173
+ Returns
174
+ -------
175
+ pointings_gal : 2-tuple of floats
176
+ The value of θ and φ (colatitude and longitude) in Galactic coordinates
177
+
178
+ """
179
+
180
+ vec = (_ang2galvec_one_sample(pointings_ecl[0], pointings_ecl[1]),)
181
+ return _vec2ang_for_one_sample(vec[0], vec[1], vec[2])
182
+
183
+
184
+ @njit
185
+ def _rotate_coordinates_and_pol_e2g_for_one_sample(pointings_ecl, pol_angle_ecl):
186
+ """Rotate the angles theta,phi and psi from ecliptic to galactic coordinates
187
+
188
+ Parameters
189
+ ----------
190
+ pointings_ecl : array
191
+ ``(2)`` array containing the colatitude and the longitude in ecliptic
192
+ coordinates
193
+
194
+ pol_angle_ecl : array
195
+ polarization angle (in radians) in ecliptic coordinates
196
+
197
+ Returns
198
+ -------
199
+ pointings_gal : 2-tuple of floats
200
+ The value of θ and φ (colatitude and longitude) in Galactic coordinates
201
+
202
+ pol_angle_gal: float
203
+ polarization angle (in radians) in galactic coordinates
204
+ """
205
+
206
+ vec = _ang2galvec_one_sample(pointings_ecl[0], pointings_ecl[1])
207
+ pointings_gal = _vec2ang_for_one_sample(vec[0], vec[1], vec[2])
208
+
209
+ sinalpha = NORTH_POLE_VEC[0] * vec[1] - NORTH_POLE_VEC[1] * vec[0]
210
+ cosalpha = NORTH_POLE_VEC[2] - vec[2] * (
211
+ NORTH_POLE_VEC[0] * vec[0]
212
+ + NORTH_POLE_VEC[1] * vec[1]
213
+ + NORTH_POLE_VEC[2] * vec[2]
214
+ )
215
+ pol_angle_gal = pol_angle_ecl + np.arctan2(sinalpha, cosalpha)
216
+
217
+ return pointings_gal, pol_angle_gal
218
+
219
+
220
+ @njit
221
+ def _rotate_coordinates_e2g_for_all(pointings_ecl, pointings_gal):
222
+ """
223
+ Parameters
224
+ ----------
225
+ pointings_ecl : array
226
+ ``(N × 2)`` array containing the colatitude and the longitude in ecliptic
227
+ coordinates
228
+
229
+ pointings_gal : array
230
+ ``(N × 2)`` array containing the colatitude and the longitude in galactic
231
+ coordinates
232
+ """
233
+
234
+ for i in range(len(pointings_ecl[:, 0])):
235
+ cur_theta, cur_phi = _rotate_coordinates_e2g_for_one_sample(pointings_ecl[i, :])
236
+ pointings_gal[i, 0] = cur_theta
237
+ pointings_gal[i, 1] = cur_phi
238
+
239
+
240
+ @njit
241
+ def _rotate_coordinates_and_pol_e2g_for_all(
242
+ pointings_ecl, pol_angle_ecl, pointings_gal, pol_angle_gal
243
+ ):
244
+ """
245
+ Parameters
246
+ ----------
247
+ pointings_ecl : array
248
+ ``(N × 2)`` array containing the colatitude and the longitude in ecliptic
249
+ coordinates
250
+
251
+ pol_angle_ecl : array
252
+ ``(N)`` polarization angle (in radians) in ecliptic coordinates
253
+
254
+ pointings_gal : array
255
+ ``(N × 2)`` array containing the colatitude and the longitude in galactic
256
+ coordinates
257
+
258
+ pol_angle_gal: array
259
+ ``(N)`` polarization angle (in radians) in gal actic coordinates
260
+ """
261
+
262
+ for i in range(len(pointings_ecl[:, 0])):
263
+ (
264
+ cur_direction,
265
+ cur_pol_angle,
266
+ ) = _rotate_coordinates_and_pol_e2g_for_one_sample(
267
+ pointings_ecl[i, :], pol_angle_ecl[i]
268
+ )
269
+
270
+ pointings_gal[i, 0] = cur_direction[0]
271
+ pointings_gal[i, 1] = cur_direction[1]
272
+ pol_angle_gal[i] = cur_pol_angle
273
+
274
+
275
+ def rotate_coordinates_e2g(pointings_ecl, pol_angle_ecl=None):
276
+ """Rotate the angles theta,phi and psi from ecliptic to galactic coordinates
277
+
278
+ Parameters
279
+ ----------
280
+ pointings_ecl : array
281
+ ``(N × 2)`` array containing the colatitude and the longitude in ecliptic
282
+ coordinates
283
+
284
+ pol_angle_ecl : array
285
+ ``(N)`` polarization angle (in radians) in ecliptic coordinates, otional
286
+
287
+ Returns
288
+ -------
289
+ pointings_gal : array
290
+ ``(N × 2)`` array containing the colatitude and the longitude in galactic
291
+ coordinates
292
+
293
+ pol_angle_gal: array
294
+ ``(N)`` polarization angle (in radians) in gal actic coordinates, returned
295
+ if pol_angle_ecl is passed
296
+
297
+ See Also
298
+ --------
299
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L578
300
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L537
301
+ https://github.com/healpy/healpy/blob/main/healpy/rotator.py#L357
302
+ """
303
+
304
+ pointings_gal = np.empty_like(pointings_ecl)
305
+
306
+ if type(pol_angle_ecl) is np.ndarray:
307
+ pol_angle_gal = np.empty_like(pol_angle_ecl)
308
+ _rotate_coordinates_and_pol_e2g_for_all(
309
+ pointings_ecl, pol_angle_ecl, pointings_gal, pol_angle_gal
310
+ )
311
+ return pointings_gal, pol_angle_gal
312
+ else:
313
+ _rotate_coordinates_e2g_for_all(pointings_ecl, pointings_gal)
314
+ return pointings_gal