Skip to content

Commit fd3209e

Browse files
authored
Merge pull request #461 from litebird/add_syntax_hook
Add syntax hook `py3.10+`
2 parents abe7768 + 717d70d commit fd3209e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+560
-670
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v3.20.0
4+
hooks:
5+
- id: pyupgrade
6+
args: [--py310-plus]
7+
files: '^(litebird_sim)/.*\.py$'
28
- repo: https://github.com/astral-sh/ruff-pre-commit
39
# Ruff version.
4-
rev: v0.11.11
10+
rev: v0.13.0
511
hooks:
612
# Run the linter.
713
- id: ruff

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# HEAD
22

3+
- Add pre-commit hook to keep syntax compliant with `py3.10+` [#461](https://github.com/litebird/litebird_sim/pull/461)
4+
35
- Fix issue [#459](https://github.com/litebird/litebird_sim/issues/459)
46

57
- Fix issue [#457](https://github.com/litebird/litebird_sim/issues/457)

docs/source/scanning.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,11 @@ The following code implements our mock scanning strategy::
575575
import litebird_sim as lbs
576576
from litebird_sim import RotQuaternion
577577
import astropy
578-
from typing import Union
579578

580579
class SimpleScanningStrategy(lbs.ScanningStrategy):
581580
def generate_spin2ecl_quaternions(
582581
self,
583-
start_time: Union[float, astropy.time.Time],
582+
start_time: float | astropy.time.Time,
584583
time_span_s: float,
585584
delta_time_s: float,
586585
) -> RotQuaternion:

litebird_sim/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
31
import numba
42

53
from litebird_sim.mapmaking import (

litebird_sim/bandpasses.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# -*- encoding: utf-8 -*-
2-
31
from dataclasses import dataclass
42

53
import numpy as np
64
import scipy as sp
75
import logging
8-
from typing import Optional, Union
96
from uuid import UUID
107

118
from .imo import Imo
@@ -81,8 +78,8 @@ class BandPassInfo:
8178

8279
bandcenter_ghz: float = 0.0
8380
bandwidth_ghz: float = 0.0
84-
bandlow_ghz: Union[float, None] = None
85-
bandhigh_ghz: Union[float, None] = None
81+
bandlow_ghz: float | None = None
82+
bandhigh_ghz: float | None = None
8683
nsamples_inband: int = 128
8784
name: str = ""
8885
bandtype: str = "top-hat"
@@ -141,7 +138,7 @@ def get_edges(self):
141138
self.bandcenter_ghz + self.bandwidth_ghz / 2,
142139
)
143140

144-
def _get_top_hat_bandpass(self, normalize=False, apodization: Optional[str] = None):
141+
def _get_top_hat_bandpass(self, normalize=False, apodization: str | None = None):
145142
"""
146143
Sample a top-hat bandpass, given the centroid and the bandwidth.
147144
If the `normalize` flag is set to ``True``, the transmission
@@ -244,7 +241,7 @@ def find_central_frequency(self):
244241
)
245242

246243
@staticmethod
247-
def from_imo(imo: Imo, url: Union[UUID, str]):
244+
def from_imo(imo: Imo, url: UUID | str):
248245
"""Create a `BandPassInfo` object from a definition in the IMO
249246
The `url` must either specify a UUID or a full URL to the
250247
object.

litebird_sim/beam_convolution.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# -*- encoding: utf-8 -*-
2-
31
import logging
42
import os
53
from dataclasses import dataclass
6-
from typing import Union, List, Dict, Optional
74

85
import numpy as np
96
import numpy.typing as npt
@@ -57,8 +54,8 @@ def add_convolved_sky_to_one_detector(
5754
pointings_det,
5855
mueller_matrix,
5956
hwp_angle,
60-
convolution_params: Optional[BeamConvolutionParameters] = None,
61-
nside_centering: Union[int, None] = None,
57+
convolution_params: BeamConvolutionParameters | None = None,
58+
nside_centering: int | None = None,
6259
nthreads: int = 0,
6360
):
6461
"""
@@ -206,16 +203,16 @@ def add_convolved_sky_to_one_detector(
206203
def add_convolved_sky(
207204
tod,
208205
pointings,
209-
sky_alms: Union[SphericalHarmonics, Dict[str, SphericalHarmonics]],
210-
beam_alms: Union[SphericalHarmonics, Dict[str, SphericalHarmonics]],
211-
hwp_angle: Union[np.ndarray, None] = None,
212-
mueller_hwp: Union[np.ndarray, None] = None,
213-
input_sky_names: Union[str, None] = None,
214-
input_beam_names: Union[str, None] = None,
215-
convolution_params: Optional[BeamConvolutionParameters] = None,
206+
sky_alms: SphericalHarmonics | dict[str, SphericalHarmonics],
207+
beam_alms: SphericalHarmonics | dict[str, SphericalHarmonics],
208+
hwp_angle: np.ndarray | None = None,
209+
mueller_hwp: np.ndarray | None = None,
210+
input_sky_names: str | None = None,
211+
input_beam_names: str | None = None,
212+
convolution_params: BeamConvolutionParameters | None = None,
216213
input_sky_alms_in_galactic: bool = True,
217214
pointings_dtype=np.float64,
218-
nside_centering: Union[int, None] = None,
215+
nside_centering: int | None = None,
219216
nthreads: int = 0,
220217
):
221218
"""
@@ -230,10 +227,10 @@ def add_convolved_sky(
230227
Pointing information for each detector. If an array, it should have shape
231228
(n_detectors, n_samples, 3). If a callable, it should return pointing data when
232229
passed a detector index.
233-
sky_alms : Union[SphericalHarmonics, Dict[str, SphericalHarmonics]]
230+
sky_alms : SphericalHarmonics | Dict[str, SphericalHarmonics]
234231
Spherical harmonic coefficients representing the sky maps. If a dictionary, keys should
235232
correspond to detector or channel names.
236-
beam_alms : Union[SphericalHarmonics, Dict[str, SphericalHarmonics]]
233+
beam_alms : SphericalHarmonics | Dict[str, SphericalHarmonics]
237234
Spherical harmonic coefficients representing the beam functions. If a dictionary,
238235
keys should correspond to detector or channel names.
239236
hwp_angle : np.ndarray or None, default=None
@@ -332,21 +329,21 @@ def add_convolved_sky(
332329

333330

334331
def add_convolved_sky_to_observations(
335-
observations: Union[Observation, List[Observation]],
336-
sky_alms: Union[
337-
SphericalHarmonics, Dict[str, SphericalHarmonics]
338-
], # at some point optional, taken from the obs
339-
beam_alms: Union[
340-
SphericalHarmonics, Dict[str, SphericalHarmonics]
341-
], # at some point optional, taken from the obs
342-
pointings: Union[npt.ArrayLike, List[npt.ArrayLike], None] = None,
343-
hwp: Optional[HWP] = None,
332+
observations: Observation | list[Observation],
333+
sky_alms: (
334+
SphericalHarmonics | dict[str, SphericalHarmonics]
335+
), # at some point optional, taken from the obs
336+
beam_alms: (
337+
SphericalHarmonics | dict[str, SphericalHarmonics]
338+
), # at some point optional, taken from the obs
339+
pointings: npt.ArrayLike | list[npt.ArrayLike] | None = None,
340+
hwp: HWP | None = None,
344341
input_sky_alms_in_galactic: bool = True,
345-
convolution_params: Optional[BeamConvolutionParameters] = None,
342+
convolution_params: BeamConvolutionParameters | None = None,
346343
component: str = "tod",
347344
pointings_dtype=np.float64,
348-
nside_centering: Union[int, None] = None,
349-
nthreads: Union[int, None] = None,
345+
nside_centering: int | None = None,
346+
nthreads: int | None = None,
350347
):
351348
"""
352349
Applies beam convolution to sky maps and adds the resulting signal to the TOD of one or more observations.
@@ -366,12 +363,12 @@ def add_convolved_sky_to_observations(
366363
keyed by detector/channel names.
367364
pointings : np.ndarray, list of np.ndarray, or None, default=None
368365
Detector pointing matrices. If None, the function extracts pointings from the `Observation` objects.
369-
hwp : Optional[HWP], default=None
366+
hwp : HWP | None, default=None
370367
Half-Wave Plate (HWP) parameters. If None, the function either assumes the information stored in the
371368
`Observation` objects, or, if they are absent, assumes no HWP.
372369
input_sky_alms_in_galactic : bool, default=True
373370
Whether the input sky alms are in Galactic coordinates.
374-
convolution_params : Optional[BeamConvolutionParameters], default=None
371+
convolution_params : BeamConvolutionParameters | None, default=None
375372
Parameters controlling the beam convolution, including resolution limits and numerical precision.
376373
component : str, default="tod"
377374
The name of the TOD component to which the computed data is added.

litebird_sim/beam_synthesis.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
3-
from typing import Optional, Union, List
4-
51
import numpy as np
62
from numpy import sqrt, exp, sin, cos, log
73
from scipy.special import iv as bessel_i
@@ -36,7 +32,7 @@ def alm_index(lmax: int, ell: int, m: int) -> int:
3632

3733

3834
def allocate_alm(
39-
lmax: int, mmax: Optional[int] = None, nstokes: int = 3, dtype=np.complex128
35+
lmax: int, mmax: int | None = None, nstokes: int = 3, dtype=np.complex128
4036
) -> SphericalHarmonics:
4137
"""
4238
Allocate an array to store spherical harmonics coefficients.
@@ -69,10 +65,10 @@ def gauss_beam_to_alm(
6965
lmax: int,
7066
mmax: int,
7167
fwhm_rad: float,
72-
ellipticity: Optional[float] = 1.0,
73-
psi_ell_rad: Optional[float] = 0.0,
74-
psi_pol_rad: Union[float, None] = 0.0,
75-
cross_polar_leakage: Optional[float] = 0.0,
68+
ellipticity: float | None = 1.0,
69+
psi_ell_rad: float | None = 0.0,
70+
psi_pol_rad: float | None = 0.0,
71+
cross_polar_leakage: float | None = 0.0,
7672
) -> SphericalHarmonics:
7773
"""
7874
Compute spherical harmonics coefficients a_ℓm representing a Gaussian beam.
@@ -205,9 +201,9 @@ def gauss_beam_to_alm(
205201
def generate_gauss_beam_alms(
206202
observation: Observation,
207203
lmax: int,
208-
mmax: Optional[int] = None,
209-
channels: Union[FreqChannelInfo, List[FreqChannelInfo], None] = None,
210-
store_in_observation: Optional[bool] = False,
204+
mmax: int | None = None,
205+
channels: FreqChannelInfo | list[FreqChannelInfo] | None = None,
206+
store_in_observation: bool | None = False,
211207
):
212208
"""
213209
Generate Gaussian beam spherical harmonics coefficients for each detector in

litebird_sim/compress.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
31
import numpy as np
42
from numba import njit
53

litebird_sim/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- encoding: utf-8 -*-
21
import numpy as np
32
from astropy.constants import c as c_light
43
from astropy.constants import h, k_B

litebird_sim/coordinates.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- encoding: utf-8 -*-
21
from enum import Enum
3-
from typing import Tuple
42

53
import numpy as np
64
from astropy.coordinates import BarycentricMeanEcliptic
@@ -105,7 +103,7 @@ def vec2ang(vx, vy, vz):
105103
@njit
106104
def _ang2galvec_one_sample(
107105
theta_rad: float, phi_rad: float
108-
) -> Tuple[float, float, float]:
106+
) -> tuple[float, float, float]:
109107
"""Transform a direction (theta, phi) in Ecliptic coordinates to
110108
a unit vector in Galactic coordinates.
111109
@@ -139,7 +137,7 @@ def _ang2galvec_one_sample(
139137

140138

141139
@njit
142-
def _vec2ang_for_one_sample(vx: float, vy: float, vz: float) -> Tuple[float, float]:
140+
def _vec2ang_for_one_sample(vx: float, vy: float, vz: float) -> tuple[float, float]:
143141
"""Transform a vector to angle given by (θ,φ).
144142
145143
Parameters
@@ -168,7 +166,7 @@ def _vec2ang_for_one_sample(vx: float, vy: float, vz: float) -> Tuple[float, flo
168166
@njit
169167
def _rotate_coordinates_and_orientation_e2g_for_one_sample(
170168
theta_ecl_rad: float, phi_ecl_rad: float, psi_ecl_rad: float
171-
) -> Tuple[float, float, float]:
169+
) -> tuple[float, float, float]:
172170
"""Rotate the angles theta,phi and psi from ecliptic to galactic coordinates
173171
174172
Parameters

0 commit comments

Comments
 (0)