Skip to content

Commit

Permalink
style: use f-strings to accommodate updated ruff rules (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiegelx authored Dec 6, 2024
1 parent e610c6d commit cf8a905
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions draco/analysis/beamform.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def setup(self, manager):
if self.collapse_ha:
self.log.info(
"Tracking source for declination dependent amount of time "
"[%d seconds at equator]" % self.timetrack
f"[{self.timetrack:0.0f} seconds at equator]"
)
else:
raise NotImplementedError(
Expand All @@ -130,7 +130,7 @@ def setup(self, manager):

else:
self.log.info(
"Tracking source for fixed amount of time [%d seconds]" % self.timetrack
f"Tracking source for fixed amount of time [{self.timetrack:0.0f} seconds]"
)

def process(self):
Expand Down
7 changes: 3 additions & 4 deletions draco/analysis/dayenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def process(self, stream):
weight[:, bb] *= flag_low[:, np.newaxis].astype(np.float32)

else:
self.log.debug("There are %d unique masks/filters." % len(index))
self.log.debug(f"There are {len(index):d} unique masks/filters.")
for ii, ind in enumerate(index):
vis[:, bb, ind] = np.matmul(NF[ii], bvis[:, ind])
weight[:, bb, ind] = tools.invert_no_zero(
Expand Down Expand Up @@ -663,8 +663,7 @@ def process(self, ringmap):
ecut = self._get_cut(el, **kwargs)

self.log.debug(
"Filtering el %0.3f, %d of %d. [%0.3f micro-sec]"
% (el, ee, nel, ecut)
f"Filtering el {el:0.3f}, {ee:d} of {nel:d}. [{ecut:0.3f} micro-sec]"
)

erm = np.ascontiguousarray(rm[slc])
Expand Down Expand Up @@ -837,7 +836,7 @@ def process(self, stream):
if not np.any(flag):
continue

self.log.debug("Filtering freq %d of %d." % (ff, nfreq))
self.log.debug(f"Filtering freq {ff:d} of {nfreq:d}.")

# Construct the filters
m_cut = np.abs(self._get_cut(nu, db))
Expand Down
4 changes: 2 additions & 2 deletions draco/analysis/sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def process(self, data):

if not np.all(stack_flag):
self.log.warning(
"There are %d stacked baselines that are masked "
"in the telescope instance." % np.sum(~stack_flag)
f"There are {np.sum(~stack_flag):0.0f} stacked baselines that are "
"masked in the telescope instance."
)

ps = data.prod[stack_new["prod"]]
Expand Down
4 changes: 2 additions & 2 deletions draco/analysis/sidereal.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _process_current_lsd(self):
ts = tod.concatenate(self._timestream_list)

# Add attributes for the LSD and a tag for labelling saved files
ts.attrs["tag"] = "lsd_%i" % lsd
ts.attrs["tag"] = f"lsd_{lsd:d}"
ts.attrs["lsd"] = lsd

# Clear the timestream list since these days have already been processed
Expand Down Expand Up @@ -248,7 +248,7 @@ def process(self, data):
sdata.vis[:] = sts
sdata.weight[:] = ni
sdata.attrs["lsd"] = self.start
sdata.attrs["tag"] = "lsd_%i" % self.start
sdata.attrs["tag"] = f"lsd_{self.start:d}"

return sdata

Expand Down
6 changes: 3 additions & 3 deletions draco/analysis/sourcestack.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def process(self, stack):
self.nmock += 1

self.log.info(
"Collected frequency stack. Current size is %d." % len(self.stack)
f"Collected frequency stack. Current size is {len(self.stack):d}."
)

if (len(self.stack) % self.ngroup) == 0:
Expand All @@ -389,8 +389,8 @@ def _reset(self):
Then, empty the list, reset the stack counter, and increment the group counter.
"""
self.log.info(
"We have accumulated %d mock realizations. Saving to file. [group %03d]"
% (self.nmock, self.counter)
f"We have accumulated {self.nmock:d} mock realizations. "
f"Saving to file. [group {self.counter:03d}]"
)

mock = np.arange(self.nmock, dtype=np.int64)
Expand Down
4 changes: 2 additions & 2 deletions draco/analysis/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def process(self, ss):

if not np.all(stack_flag):
self.log.warning(
"There are %d stacked baselines that are masked "
"in the telescope instance." % np.sum(~stack_flag)
f"There are {np.sum(~stack_flag):0.0f} stacked baselines "
"that are masked in the telescope instance."
)

ss_prod = ss.prod[stack_new["prod"]]
Expand Down
2 changes: 1 addition & 1 deletion draco/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def _create_dtype(self, columns):
dt = []
for ci, (name, dtype) in enumerate(columns):
if not isinstance(name, str):
raise ValueError("Column %i is invalid" % ci)
raise ValueError(f"Column {ci:d} is invalid")
dt.append((name, dtype))

return dt
Expand Down
2 changes: 1 addition & 1 deletion draco/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _list_of_filegroups(groups: Union[list[dict], dict]) -> list[dict]:
raise ConfigError(f"Expected type dict in file groups (got {type(group)}).")

if "tag" not in group:
group["tag"] = "group_%i" % gi
group["tag"] = f"group_{gi:d}"

flist = []

Expand Down
2 changes: 1 addition & 1 deletion draco/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self):

rank_length = int(math.log10(MPI.COMM_WORLD.size)) + 1

mpi_fmt = "[MPI %%(mpi_rank)%id/%%(mpi_size)%id]" % (rank_length, rank_length)
mpi_fmt = f"[MPI %(mpi_rank){rank_length:d}d/%(mpi_size){rank_length:d}d]"
filt = MPILogFilter(level_all=self.level_all, level_rank0=self.level_rank0)

# This uses the fact that caput.pipeline.Manager has already
Expand Down
2 changes: 1 addition & 1 deletion draco/synthesis/gain.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def process(self):
gain = mpiarray.MPIArray.wrap(gain_comb, axis=1, comm=data.comm)
gain_data.gain[:] = gain
gain_data.attrs["lsd"] = self._current_lsd
gain_data.attrs["tag"] = "lsd_%i" % self._current_lsd
gain_data.attrs["tag"] = f"lsd_{self._current_lsd:d}"

# Increment current lsd
self._current_lsd += 1
Expand Down
5 changes: 2 additions & 3 deletions draco/util/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ def extract_diagonal(utmat, axis=1):
# Check that this nside is correct
if utmat.shape[axis] != (nside * (nside + 1) // 2):
msg = (
"Array length (%i) of axis %i does not correspond upper triangle\
of square matrix"
% (utmat.shape[axis], axis)
f"Array length ({utmat.shape[axis]:d}) of axis {axis:d} does not "
"correspond upper triangle of square matrix"
)
raise RuntimeError(msg)

Expand Down

0 comments on commit cf8a905

Please sign in to comment.