Skip to content

Commit

Permalink
Fix new ruff errors related to string formatting of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Dec 2, 2024
1 parent b419d09 commit 54f54c5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/pyuvdata/utils/io/ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ def write_ms_spectral_window(
ch_mask = ... if id_array is None else id_array == spw_id
sw_table.addrows()
sw_table.putcell("NUM_CHAN", idx, np.sum(ch_mask))
sw_table.putcell("NAME", idx, "SPW%d" % spw_id)
sw_table.putcell("NAME", idx, f"SPW{spw_id}")
sw_table.putcell("ASSOC_SPW_ID", idx, spw_id)
sw_table.putcell("ASSOC_NATURE", idx, "") # Blank for now
sw_table.putcell("CHAN_FREQ", idx, freq_array[ch_mask])
Expand Down
2 changes: 1 addition & 1 deletion src/pyuvdata/utils/phasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _rotate_matmul_wrapper(*, xyz_array, rot_matrix, n_rot):
# Do a quick check to make sure that things look sensible
if rot_matrix.shape != (n_rot, 3, 3):
raise ValueError(
"rot_matrix must be of shape (n_rot, 3, 3), where n_rot=%i." % n_rot
f"rot_matrix must be of shape (n_rot, 3, 3), where n_rot={n_rot}."
)
if (xyz_array.ndim == 3) and (
(xyz_array.shape[0] not in [1, n_rot]) or (xyz_array.shape[-2] != 3)
Expand Down
13 changes: 6 additions & 7 deletions src/pyuvdata/uvdata/mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def read_mir(
select_where += [("tel1", "eq", antenna_names)]
select_where += [("tel2", "eq", antenna_names)]
if bls is not None:
select_where += [
("blcd", "eq", ["%i-%i" % (tup[0], tup[1]) for tup in bls])
]
select_where += [("blcd", "eq", [f"{tup[0]}-{tup[1]}" for tup in bls])]
if time_range is not None:
# Have to convert times from UTC JD -> TT MJD for mIR
select_where += [
Expand Down Expand Up @@ -438,9 +436,10 @@ def _init_from_mir_parser(
):
if not np.allclose(val, mir_data.sp_data[item][data_mask]):
warnings.warn(
"Discrepancy in %s for win %i sb %i pol %i. Values of "
"`freq_array` and `channel_width` should be checked for "
"channels corresponding to spw_id %i." % (item, *spdx, spw_id)
f"Discrepancy in {item} for win {spdx[0]} sb {spdx[1]} "
f"pol {spdx[2]}. Values of `freq_array` and `channel_width` "
"should be checked for channels corresponding to spw_id "
f"{spw_id}."
)

# Get the data in the right units and dtype
Expand Down Expand Up @@ -530,7 +529,7 @@ def _init_from_mir_parser(
self.telescope = Telescope()
self._set_telescope_requirements()
self.telescope.Nants = 8
self.telescope.antenna_names = ["Ant%i" % idx for idx in range(1, 9)]
self.telescope.antenna_names = [f"Ant{idx}" for idx in range(1, 9)]
self.telescope.antenna_numbers = np.arange(1, 9)

# Prepare the XYZ coordinates of the antenna positions.
Expand Down
9 changes: 2 additions & 7 deletions src/pyuvdata/uvdata/mir_meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,13 +2947,8 @@ def _writefile(self, filepath=None, *, append_data=False, datamask=...):
with open(filepath, "a" if append_data else "w+") as file:
for antpos in self._data[datamask]:
file.write(
"%i %.17e %.17e %.17e\n"
% (
antpos["antenna"],
antpos["xyz_pos"][0],
antpos["xyz_pos"][1],
antpos["xyz_pos"][2],
)
f"{antpos["antenna"]} {antpos["xyz_pos"][0]:.17e} "
f"{antpos["xyz_pos"][1]:.17e} {antpos["xyz_pos"][2]:.17e}\n"
)


Expand Down
6 changes: 3 additions & 3 deletions src/pyuvdata/uvdata/mir_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,8 +1438,8 @@ def apply_tsys(self, *, invert=False, force=False, use_cont_det=None):
)
except KeyError:
warnings.warn(
"No tsys for blhid %i found (%i-%i baseline, inhid %i). "
"Baseline record will be flagged." % (blhid, jdx, ldx, idx)
f"No tsys for blhid {blhid} found ({jdx}-{ldx} baseline, "
f"inhid {idx}). Baseline record will be flagged."
)

if invert:
Expand Down Expand Up @@ -4094,7 +4094,7 @@ def redoppler_data(
rx_code = np.median(self.bl_data["irec"][self.bl_data["ant1rx"] == 0])
rx_name = self.codes_data["rec"][rx_code]
if rx_name not in ("230", "345"):
raise ValueError("Receiver code %i not recognized." % rx_code)
raise ValueError(f"Receiver code {rx_code} not recognized.")

freq_shift *= 2 if (rx_name == "230") else 3
# We have to do a bit of special handling for the so-called "RxB"
Expand Down
12 changes: 6 additions & 6 deletions src/pyuvdata/uvdata/uvfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,9 @@ def write_uvfits(
fits_tables = [hdu, ant_hdu]
# If needed, add the FQ table
if self.Nspws > 1:
fmt_d = "%iD" % self.Nspws
fmt_e = "%iE" % self.Nspws
fmt_j = "%iJ" % self.Nspws
fmt_d = f"{self.Nspws}D"
fmt_e = f"{self.Nspws}E"
fmt_j = f"{self.Nspws}J"

# TODO Karto: Temp implementation until we fix some other things in UVData
if_freq = start_freq_array - ref_freq
Expand All @@ -1445,9 +1445,9 @@ def write_uvfits(
fits_tables.append(fq_hdu)

# Always write the SU table
fmt_d = "%iD" % self.Nspws
fmt_e = "%iE" % self.Nspws
fmt_j = "%iJ" % self.Nspws
fmt_d = f"{self.Nspws}D"
fmt_e = f"{self.Nspws}E"
fmt_j = f"{self.Nspws}J"

int_zeros = np.zeros(self.Nphase, dtype=int)
flt_zeros = np.zeros(self.Nphase, dtype=np.float64)
Expand Down
2 changes: 1 addition & 1 deletion tests/uvdata/test_mir_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def test_apply_tsys_warn(mir_data):
with check_warnings(
UserWarning,
[
("No tsys for blhid %i found (1-4 baseline, inhid 1)." % idx)
(f"No tsys for blhid {idx} found (1-4 baseline, inhid 1).")
for idx in range(1, 5)
],
):
Expand Down

0 comments on commit 54f54c5

Please sign in to comment.