Skip to content

Commit 3c4f214

Browse files
committed
Applied black
1 parent 44ae9ce commit 3c4f214

File tree

8 files changed

+85
-49
lines changed

8 files changed

+85
-49
lines changed

etc/alma-nf-filler/alma_nf_filler_lib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,9 @@ def _compute_grid_params(meta_dict, extent):
12301230
clight = scipy.constants.speed_of_light
12311231
wavelength = clight / meta_dict["spw"]["frequency"][0]
12321232

1233-
telescope = get_proper_telescope(meta_dict["ant"]["telescope"], meta_dict["ant"]["antenna"])
1233+
telescope = get_proper_telescope(
1234+
meta_dict["ant"]["telescope"], meta_dict["ant"]["antenna"]
1235+
)
12341236

12351237
cell_size = wavelength / telescope.diameter / 3.0
12361238

src/astrohack/antenna/antenna_surface.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,24 @@ def __init__(
9292
self.phase = phase_wrapping(self.phase)
9393

9494
self._create_aperture_mask(clip_type, clip_level, exclude_shadows)
95-
self.deviation = self.telescope.phase_to_deviation(self.rad, self.phase, self.wavelength)
95+
self.deviation = self.telescope.phase_to_deviation(
96+
self.rad, self.phase, self.wavelength
97+
)
9698
self.panels = self.telescope.build_panel_list(pmodel, panel_margins)
9799
if not self.reread:
98100
self.panelmodel = pmodel
99101
self.panel_margins = panel_margins
100102
if crop:
101103
self._crop_maps()
102-
self.panel_distribution = self.telescope.attribute_pixels_to_panels(self.panels, self.u_axis, self.v_axis,
103-
self.rad, self.phi, self.deviation,
104-
self.mask)
104+
self.panel_distribution = self.telescope.attribute_pixels_to_panels(
105+
self.panels,
106+
self.u_axis,
107+
self.v_axis,
108+
self.rad,
109+
self.phi,
110+
self.deviation,
111+
self.mask,
112+
)
105113

106114
if nan_out_of_bounds:
107115
self._nan_out_of_bounds()
@@ -225,7 +233,9 @@ def _read_xds(self, inputxds):
225233
self.label = create_dataset_label(
226234
inputxds.attrs["ant_name"], inputxds.attrs["ddi"]
227235
)
228-
self.telescope = get_proper_telescope(inputxds.attrs["telescope_name"], inputxds.attrs["ant_name"])
236+
self.telescope = get_proper_telescope(
237+
inputxds.attrs["telescope_name"], inputxds.attrs["ant_name"]
238+
)
229239

230240
def _define_amp_clip(self, clip_type, clip_level):
231241
self.amplitude_noise = np.where(self.base_mask, np.nan, self.amplitude)
@@ -249,7 +259,9 @@ def _compute_noise_threshold_clip(self, threshold, step_multiplier=0.95):
249259
noise_stats = data_statistics(self.amplitude_noise)
250260

251261
in_disk = np.where(self.rad < self.telescope.diameter / 2.0, 1.0, np.nan)
252-
in_disk = np.where(self.rad < self.telescope.inner_radial_limit, np.nan, in_disk)
262+
in_disk = np.where(
263+
self.rad < self.telescope.inner_radial_limit, np.nan, in_disk
264+
)
253265
n_in_disk = np.nansum(in_disk)
254266
in_disk_amp = in_disk * self.amplitude
255267

@@ -309,7 +321,6 @@ def _nan_out_of_bounds(self):
309321
self.phase = np.where(self.base_mask, self.phase, np.nan)
310322
self.amplitude = np.where(self.base_mask, self.amplitude, np.nan)
311323

312-
313324
def _fetch_panel_ringed(self, ring, panel):
314325
"""
315326
Fetch a panel object from the panel list using its ring and panel numbers,
@@ -427,8 +438,12 @@ def correct_surface(self):
427438
ix, iy = int(corr[0]), int(corr[1])
428439
self.residuals[ix, iy] -= corr[-1]
429440
self.corrections[ix, iy] = -corr[-1]
430-
self.phase_corrections = self.telescope.deviation_to_phase(self.rad, self.corrections, self.wavelength)
431-
self.phase_residuals = self.telescope.deviation_to_phase(self.rad, self.residuals, self.wavelength)
441+
self.phase_corrections = self.telescope.deviation_to_phase(
442+
self.rad, self.corrections, self.wavelength
443+
)
444+
self.phase_residuals = self.telescope.deviation_to_phase(
445+
self.rad, self.residuals, self.wavelength
446+
)
432447
self._build_panel_data_arrays()
433448
self.solved = True
434449

src/astrohack/antenna/telescope.py

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def read(self, filename):
3232
filename: name of the input file
3333
"""
3434
try:
35-
logger.debug('Reading telescope data from: filename')
35+
logger.debug("Reading telescope data from: filename")
3636
xds = xr.open_zarr(filename)
3737
for key in xds.attrs:
3838
setattr(self, key, xds.attrs[key])
@@ -47,10 +47,11 @@ def read(self, filename):
4747
self.file_path = abs_path.parent
4848

4949
def read_from_distro(self, name):
50-
dest_path = "/".join([astrohack.__path__[0], f'data/telescopes/{name.lower()}.zarr'])
50+
dest_path = "/".join(
51+
[astrohack.__path__[0], f"data/telescopes/{name.lower()}.zarr"]
52+
)
5153
self.read(dest_path)
5254

53-
5455
def write(self, filename):
5556
"""
5657
Write the telescope object to an X array .zarr telescope configuration file
@@ -62,7 +63,7 @@ def write(self, filename):
6263
obj_dict.pop("filename", None)
6364
xds = xr.Dataset()
6465
xds.attrs = obj_dict
65-
logger.debug('Writing telescope data to: filename')
66+
logger.debug("Writing telescope data to: filename")
6667
xds.to_zarr(filename, mode="w", compute=True, consolidated=True)
6768
return
6869

@@ -74,7 +75,12 @@ def __repr__(self):
7475
return outstr
7576

7677
def write_to_distro(self):
77-
dest_path = "/".join([astrohack.__path__[0], f'data/telescopes/{self.name.lower().replace(" ", "_")}.zarr'])
78+
dest_path = "/".join(
79+
[
80+
astrohack.__path__[0],
81+
f'data/telescopes/{self.name.lower().replace(" ", "_")}.zarr',
82+
]
83+
)
7884
self.write(dest_path)
7985

8086

@@ -110,7 +116,11 @@ def from_name(cls, name):
110116
def consistency_check(self):
111117
error = False
112118

113-
if not self.n_rings_of_panels == len(self.panel_inner_radii) == len(self.panel_outer_radii):
119+
if (
120+
not self.n_rings_of_panels
121+
== len(self.panel_inner_radii)
122+
== len(self.panel_outer_radii)
123+
):
114124
logger.error(
115125
"Number of panels don't match radii or number of panels list sizes"
116126
)
@@ -119,7 +129,7 @@ def consistency_check(self):
119129
if error:
120130
raise Exception("Failed Consistency check")
121131
else:
122-
print('Consistency passed')
132+
print("Consistency passed")
123133

124134
return
125135

@@ -161,6 +171,7 @@ def _alma_panel_labeling(self, iring, ipanel):
161171

162172
def build_panel_list(self, panel_model, panel_margins):
163173
from time import time
174+
164175
start = time()
165176
if self.name in ["VLA", "VLBA"]:
166177
self._panel_label = self._vla_panel_labeling
@@ -189,7 +200,9 @@ def build_panel_list(self, panel_model, panel_margins):
189200

190201
return panel_list
191202

192-
def attribute_pixels_to_panels(self, panel_list, u_axis, v_axis, radius, phi, deviation, mask):
203+
def attribute_pixels_to_panels(
204+
self, panel_list, u_axis, v_axis, radius, phi, deviation, mask
205+
):
193206
"""
194207
Attribute pixels in deviation to the panels in the panel_list
195208
Args:
@@ -220,9 +233,7 @@ def attribute_pixels_to_panels(self, panel_list, u_axis, v_axis, radius, phi, de
220233
ipanel = panel_map[ix, iy]
221234
if ipanel >= 0:
222235
panel = panel_list[int(ipanel)]
223-
issample, inpanel = panel.is_inside(
224-
radius[ix, iy], phi[ix, iy]
225-
)
236+
issample, inpanel = panel.is_inside(radius[ix, iy], phi[ix, iy])
226237
if inpanel:
227238
if issample and mask[ix, iy]:
228239
panel.add_sample([xc, yc, ix, iy, deviation[ix, iy]])
@@ -231,7 +242,6 @@ def attribute_pixels_to_panels(self, panel_list, u_axis, v_axis, radius, phi, de
231242

232243
return panel_map
233244

234-
235245
def phase_to_deviation(self, radius, phase, wavelength):
236246
acoeff = (wavelength / twopi) / (4.0 * self.focus)
237247
bcoeff = 4 * self.focus**2
@@ -267,34 +277,34 @@ def get_proper_telescope(name: str, antenna_name: str = None):
267277
name = name.lower()
268278
if isinstance(antenna_name, str):
269279
antenna_name = antenna_name.lower()
270-
if 'vla' in name:
271-
if antenna_name is None or 'ea' in antenna_name:
272-
return RingedCassegrain.from_name('vla')
273-
elif 'na' in antenna_name:
274-
print('ngvla antenna not yet supported')
280+
if "vla" in name:
281+
if antenna_name is None or "ea" in antenna_name:
282+
return RingedCassegrain.from_name("vla")
283+
elif "na" in antenna_name:
284+
print("ngvla antenna not yet supported")
275285
return None
276286
else:
277-
raise Exception(f'Unsupported antenna type for the VLA: {antenna_name}')
287+
raise Exception(f"Unsupported antenna type for the VLA: {antenna_name}")
278288

279-
elif 'vlba' in name:
280-
return RingedCassegrain.from_name('vlba')
289+
elif "vlba" in name:
290+
return RingedCassegrain.from_name("vlba")
281291

282-
elif 'alma' in name:
292+
elif "alma" in name:
283293
if antenna_name is None:
284-
raise Exception('ALMA is an heterogenious array and hence an antenna name is needed')
285-
elif 'dv' in antenna_name:
286-
return RingedCassegrain.from_name('alma_dv')
287-
elif 'da' in antenna_name:
288-
return RingedCassegrain.from_name('alma_da')
289-
elif 'tp' in antenna_name:
290-
return RingedCassegrain.from_name('alma_tp')
294+
raise Exception(
295+
"ALMA is an heterogenious array and hence an antenna name is needed"
296+
)
297+
elif "dv" in antenna_name:
298+
return RingedCassegrain.from_name("alma_dv")
299+
elif "da" in antenna_name:
300+
return RingedCassegrain.from_name("alma_da")
301+
elif "tp" in antenna_name:
302+
return RingedCassegrain.from_name("alma_tp")
291303
else:
292-
raise Exception(f'Unsupported antenna type for ALMA: {antenna_name}')
304+
raise Exception(f"Unsupported antenna type for ALMA: {antenna_name}")
293305

294-
elif 'aca' in name:
295-
return RingedCassegrain.from_name('aca_7m')
306+
elif "aca" in name:
307+
return RingedCassegrain.from_name("aca_7m")
296308

297309
else:
298310
return None
299-
300-

src/astrohack/cassegrain_ray_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def apply_holog_phase_fitting_to_rt_xds(
540540
]
541541

542542
# Manipulate VLA telescope object so that it has compatible parameters to the ones in the RT model.
543-
telescope = get_proper_telescope('VLA')
543+
telescope = get_proper_telescope("VLA")
544544
telescope.focus = telescope_pars["focal_length"]
545545
c_fact = telescope_pars["foci_half_distance"]
546546
a_fact = telescope_pars["z_intercept"]

src/astrohack/core/holog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def process_holog_chunk(holog_chunk_params):
4545
ddi = holog_chunk_params["this_ddi"]
4646
convert_to_stokes = holog_chunk_params["to_stokes"]
4747
ref_xds = ant_data_dict[ddi]["map_0"]
48-
telescope = get_proper_telescope(meta_data["telescope_name"], ref_xds.attrs["antenna_name"])
48+
telescope = get_proper_telescope(
49+
meta_data["telescope_name"], ref_xds.attrs["antenna_name"]
50+
)
4951
try:
5052
is_near_field = ref_xds.attrs["near_field"]
5153
except KeyError:
@@ -75,7 +77,9 @@ def process_holog_chunk(holog_chunk_params):
7577

7678
# Current bottleneck
7779
if is_near_field:
78-
distance, focus_offset = telescope.station_distance_dict[holog_chunk_params["alma_osf_pad"]]
80+
distance, focus_offset = telescope.station_distance_dict[
81+
holog_chunk_params["alma_osf_pad"]
82+
]
7983
aperture_grid, u_axis, v_axis, _, used_wavelength = (
8084
calculate_near_field_aperture(
8185
grid=beam_grid,

src/astrohack/utils/zernike_aperture_fitting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,9 @@ def fit_zernike_coefficients(
900900
arm_angle=telescope.arm_shadow_rotation,
901901
)
902902
else:
903-
mask = create_aperture_mask(u_axis, v_axis, telescope.inner_radial_limit, aperture_radius)
903+
mask = create_aperture_mask(
904+
u_axis, v_axis, telescope.inner_radial_limit, aperture_radius
905+
)
904906

905907
# Vectorize grids with only valid points
906908
u_lin = u_grid[mask]

src/astrohack/visualization/diagnostics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,9 @@ def plot_position_corrections(parm_dict, data_dict):
662662
Returns:
663663
PNG file(s) with the correction plots
664664
"""
665-
telescope = get_proper_telescope(data_dict._meta_data["telescope_name"], parm_dict["ant"])
665+
telescope = get_proper_telescope(
666+
data_dict._meta_data["telescope_name"], parm_dict["ant"]
667+
)
666668
destination = parm_dict["destination"]
667669
ref_ant = data_dict._meta_data["reference_antenna"]
668670
combined = parm_dict["combined"]

tests/unit/test_class_telescope.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def test_write(self):
4141
testfile
4242
), "Telescope configuration file not created at the proper location"
4343
assert (
44-
filecmp.cmp(tel.file_path + "/vlba.zarr/.zattrs", testfile + "/.zattrs") == 0
44+
filecmp.cmp(tel.file_path + "/vlba.zarr/.zattrs", testfile + "/.zattrs")
45+
== 0
4546
), ("Telescope configuration " "file is not equal to the " "reference")
4647
shutil.rmtree(testfile)
4748

0 commit comments

Comments
 (0)