Skip to content

Commit 09ef9e1

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4c37236 commit 09ef9e1

1 file changed

Lines changed: 55 additions & 26 deletions

File tree

lat_beams/beam_utils.py

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@
44
TODO: Make everything radians
55
"""
66

7-
from logging import Logger
87
import datetime as dt
98
import os
9+
from logging import Logger
10+
from typing import Optional
11+
1012
import astropy.units as u
1113
import h5py
1214
import numpy as np
1315
from astropy.convolution import Gaussian2DKernel, convolve_fft
16+
from jaxtyping import Float, Shaped
1417
from scipy.interpolate import interp1d
1518
from sotodlib.core import AxisManager, Context
16-
from jaxtyping import Float, Shaped
1719
from sotodlib.site_pipeline import jobdb
18-
from typing import Optional
1920

2021
from .utils.jobs import set_tag
2122

2223

23-
def solid_angle(az: Float[np.ndarray, "nx"], el: Float[np.ndarray, "ny"], beam: Float[np.ndarray, "nx ny"], cent: tuple[int, int], r1: float, norm: float) -> float:
24+
def solid_angle(
25+
az: Float[np.ndarray, "nx"],
26+
el: Float[np.ndarray, "ny"],
27+
beam: Float[np.ndarray, "nx ny"],
28+
cent: tuple[int, int],
29+
r1: float,
30+
norm: float,
31+
) -> float:
2432
"""
2533
Compute the integrated solid angle of a beam map.
2634
This uses aperture photometry to handle bias from the background of the map.
@@ -66,7 +74,14 @@ def solid_angle(az: Float[np.ndarray, "nx"], el: Float[np.ndarray, "ny"], beam:
6674
return integral_inner - integral_outer
6775

6876

69-
def estimate_solid_angle(imap : Float[np.ndarray, "nx ny"], model : Float[np.ndarray, "nx ny"], res : float, data_fwhm : float, cent : tuple[int, int], min_sigma: float) -> tuple[float, float, float, float]:
77+
def estimate_solid_angle(
78+
imap: Float[np.ndarray, "nx ny"],
79+
model: Float[np.ndarray, "nx ny"],
80+
res: float,
81+
data_fwhm: float,
82+
cent: tuple[int, int],
83+
min_sigma: float,
84+
) -> tuple[float, float, float, float]:
7085
r"""
7186
Estimate the solid angle of a map given a fit model.
7287
Here we correct for the bias in our solid angle integration by computing:
@@ -134,7 +149,9 @@ def estimate_solid_angle(imap : Float[np.ndarray, "nx ny"], model : Float[np.nda
134149
)
135150

136151

137-
def radial_profile(data : Float[np.ndarray, "nx ny"], center : tuple[int, int]) -> Float[np.ndarray, "nr"]:
152+
def radial_profile(
153+
data: Float[np.ndarray, "nx ny"], center: tuple[int, int]
154+
) -> Float[np.ndarray, "nr"]:
138155
"""
139156
Compute the radial profile of a beam.
140157
@@ -161,7 +178,9 @@ def radial_profile(data : Float[np.ndarray, "nx ny"], center : tuple[int, int])
161178
return radialprofile
162179

163180

164-
def get_fwhm_radial_bins(r : Float[np.ndarray, "nr"], y : Float[np.ndarray, "nr"], interpolate : bool =False) -> float:
181+
def get_fwhm_radial_bins(
182+
r: Float[np.ndarray, "nr"], y: Float[np.ndarray, "nr"], interpolate: bool = False
183+
) -> float:
165184
"""
166185
Estimate FWHM from a radial profile.
167186
@@ -194,10 +213,12 @@ def get_fwhm_radial_bins(r : Float[np.ndarray, "nr"], y : Float[np.ndarray, "nr"
194213
return fwhm
195214

196215

197-
def crop_maps(maps : list[Float[np.ndarray, "nx ny"]], cent : tuple[int, int], extent : int) -> list[Float[np.ndarray, "2extent 2extent"]]:
216+
def crop_maps(
217+
maps: list[Float[np.ndarray, "nx ny"]], cent: tuple[int, int], extent: int
218+
) -> list[Float[np.ndarray, "2extent 2extent"]]:
198219
"""
199220
Crop a list of maps to be smaller.
200-
Note that all input maps will be cropped relative to the same pixel.
221+
Note that all input maps will be cropped relative to the same pixel.
201222
202223
Parameters
203224
----------
@@ -227,7 +248,9 @@ def crop_maps(maps : list[Float[np.ndarray, "nx ny"]], cent : tuple[int, int], e
227248
return maps
228249

229250

230-
def estimate_cent(imap : Float[np.ndarray, "nx ny"], sigma : float =5, buf : int =30) -> tuple[int, int]:
251+
def estimate_cent(
252+
imap: Float[np.ndarray, "nx ny"], sigma: float = 5, buf: int = 30
253+
) -> tuple[int, int]:
231254
"""
232255
Estimate the location of the central pixel of a beam map.
233256
To do this we first smooth the map with a gaussian of size `sigma`,
@@ -264,18 +287,18 @@ def estimate_cent(imap : Float[np.ndarray, "nx ny"], sigma : float =5, buf : int
264287

265288

266289
def process_model(
267-
aman : AxisManager,
268-
solved : Float[np.ndarray, "nx ny"],
269-
model : Float[np.ndarray, "nx ny"],
270-
noise : float,
271-
min_snr : float,
272-
c : tuple[int, int],
273-
map_units : u.Unit,
274-
pixsize : float,
275-
data_fwhm : float,
276-
min_sigma : float,
277-
job : Optional[jobdb.Job],
278-
logger : Optional[Logger],
290+
aman: AxisManager,
291+
solved: Float[np.ndarray, "nx ny"],
292+
model: Float[np.ndarray, "nx ny"],
293+
noise: float,
294+
min_snr: float,
295+
c: tuple[int, int],
296+
map_units: u.Unit,
297+
pixsize: float,
298+
data_fwhm: float,
299+
min_sigma: float,
300+
job: Optional[jobdb.Job],
301+
logger: Optional[Logger],
279302
) -> Optional[AxisManager]:
280303
"""
281304
Convenience function to postproccess a map and it's fit model.
@@ -353,7 +376,9 @@ def process_model(
353376
return aman
354377

355378

356-
def load_beam_fits_from_jobs(fpath : str, joblist : list[jobdb.Job]) -> Shaped[np.ndarray, "nfits"]:
379+
def load_beam_fits_from_jobs(
380+
fpath: str, joblist: list[jobdb.Job]
381+
) -> Shaped[np.ndarray, "nfits"]:
357382
"""
358383
Load beam fits from a list of jobs.
359384
@@ -371,7 +396,7 @@ def load_beam_fits_from_jobs(fpath : str, joblist : list[jobdb.Job]) -> Shaped[n
371396
Loaded fits.
372397
This is a numpy structured array with the following collumns:
373398
374-
* obs_id : str, the obs_id of the fit data
399+
* obs_id : str, the obs_id of the fit data
375400
* wafer_slot : str, the wafer slot of the fit data
376401
* stream_id : str, the stream id of the fit data
377402
* band : str, the band (ie. f090) of the fit data
@@ -434,7 +459,9 @@ def load_beam_fits_from_jobs(fpath : str, joblist : list[jobdb.Job]) -> Shaped[n
434459
return all_fits
435460

436461

437-
def get_fit_vec(all_fits : Shaped[np.ndarray, "nfits"], name : str, fall_back : Optional[str]=None) -> u.Quantity:
462+
def get_fit_vec(
463+
all_fits: Shaped[np.ndarray, "nfits"], name: str, fall_back: Optional[str] = None
464+
) -> u.Quantity:
438465
"""
439466
Get a fit value from all fits in a structured array.
440467
@@ -470,7 +497,9 @@ def get_fit_vec(all_fits : Shaped[np.ndarray, "nfits"], name : str, fall_back :
470497
return dat
471498

472499

473-
def get_split_vec(fits : Shaped[np.ndarray, "nfits"], split : str, ctx : Context, round_to : int =2) -> Shaped[np.ndarray, "nfits"]:
500+
def get_split_vec(
501+
fits: Shaped[np.ndarray, "nfits"], split: str, ctx: Context, round_to: int = 2
502+
) -> Shaped[np.ndarray, "nfits"]:
474503
"""
475504
Get an array of metadata to split fits by.
476505

0 commit comments

Comments
 (0)