From 54f54c5f68b7c4215823739cd38b2165d2848be0 Mon Sep 17 00:00:00 2001 From: Bryna Hazelton Date: Mon, 2 Dec 2024 12:01:21 -0800 Subject: [PATCH] Fix new ruff errors related to string formatting of variables --- src/pyuvdata/utils/io/ms.py | 2 +- src/pyuvdata/utils/phasing.py | 2 +- src/pyuvdata/uvdata/mir.py | 13 ++++++------- src/pyuvdata/uvdata/mir_meta_data.py | 9 ++------- src/pyuvdata/uvdata/mir_parser.py | 6 +++--- src/pyuvdata/uvdata/uvfits.py | 12 ++++++------ tests/uvdata/test_mir_parser.py | 2 +- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/pyuvdata/utils/io/ms.py b/src/pyuvdata/utils/io/ms.py index b9fcedff8..226a49bc1 100644 --- a/src/pyuvdata/utils/io/ms.py +++ b/src/pyuvdata/utils/io/ms.py @@ -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]) diff --git a/src/pyuvdata/utils/phasing.py b/src/pyuvdata/utils/phasing.py index f5d890621..a81cd4527 100644 --- a/src/pyuvdata/utils/phasing.py +++ b/src/pyuvdata/utils/phasing.py @@ -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) diff --git a/src/pyuvdata/uvdata/mir.py b/src/pyuvdata/uvdata/mir.py index 0d62fdb80..153704350 100644 --- a/src/pyuvdata/uvdata/mir.py +++ b/src/pyuvdata/uvdata/mir.py @@ -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 += [ @@ -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 @@ -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. diff --git a/src/pyuvdata/uvdata/mir_meta_data.py b/src/pyuvdata/uvdata/mir_meta_data.py index 20e99ead0..4e0933ad4 100644 --- a/src/pyuvdata/uvdata/mir_meta_data.py +++ b/src/pyuvdata/uvdata/mir_meta_data.py @@ -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" ) diff --git a/src/pyuvdata/uvdata/mir_parser.py b/src/pyuvdata/uvdata/mir_parser.py index ad6e297bf..3780542b0 100644 --- a/src/pyuvdata/uvdata/mir_parser.py +++ b/src/pyuvdata/uvdata/mir_parser.py @@ -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: @@ -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" diff --git a/src/pyuvdata/uvdata/uvfits.py b/src/pyuvdata/uvdata/uvfits.py index de912c3c9..b71998972 100644 --- a/src/pyuvdata/uvdata/uvfits.py +++ b/src/pyuvdata/uvdata/uvfits.py @@ -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 @@ -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) diff --git a/tests/uvdata/test_mir_parser.py b/tests/uvdata/test_mir_parser.py index fe7a1dde6..2b4e6abf3 100644 --- a/tests/uvdata/test_mir_parser.py +++ b/tests/uvdata/test_mir_parser.py @@ -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) ], ):