Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Update to use f-format strings. Remove glpk version check until we have a working version #1696

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions pyart/_debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ def _debug_info(stream=None):
except:
cylp_available = "MISSING"

try:
import glpk

glpk_version = "%i.%i" % (glpk.env.version)
except:
glpk_version = "MISSING"

try:
import cvxopt.info

Expand Down Expand Up @@ -122,7 +115,6 @@ def _debug_info(stream=None):

print("---- Optional dependencies ----", file=stream)
print("CyLP:", cylp_available, file=stream)
print("PyGLPK version:", glpk_version, file=stream)
print("CVXOPT version:", cvxopt_version, file=stream)
print("Cartopy version:", cartopy_version, file=stream)
print("pytest version:", pytest_version, file=stream)
Expand Down
2 changes: 1 addition & 1 deletion pyart/aux_io/gamicfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, filename):
"""initialize object."""
self._hfile = h5py.File(filename, "r")
self.nsweeps = self._hfile["what"].attrs["sets"]
self._scans = ["scan%i" % (i) for i in range(self.nsweeps)]
self._scans = [f"scan{i}" for i in range(self.nsweeps)]
self.rays_per_sweep = self.how_attrs("ray_count", "int32")
self.total_rays = sum(self.rays_per_sweep)
self.gates_per_sweep = self.how_attrs("bin_count", "int32")
Expand Down
3 changes: 1 addition & 2 deletions pyart/core/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,7 @@ def add_field(self, field_name, dic, replace_existing=False):
if "data" not in dic:
raise KeyError("dic must contain a 'data' key")
if dic["data"].shape != (self.nrays, self.ngates):
t = (self.nrays, self.ngates)
err = "'data' has invalid shape, should be (%i, %i)" % t
err = "'data' has invalid shape, should be ({self.nrays}, {self.ngates})"
raise ValueError(err)
# add the field
self.fields[field_name] = dic
Expand Down
6 changes: 3 additions & 3 deletions pyart/correct/phase_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,13 @@ def LP_solver_cylp_mp(A_Matrix, B_vectors, weights, really_verbose=False, proc=1
# check if equal sized chunks can be distributed to worker processes
if n_rays % chunksize != 0:
print(
"Problem of %d rays cannot be split to %d worker processes!\n\r"
"Fallback to 1 process!" % (n_rays, proc)
"Problem of {n_rays} rays cannot be split to {proc} worker processes!\n\r"
"Fallback to 1 process!"
)
chunksize = n_rays # fall back to one process
proc = 1

print("Calculating with %d processes, %d rays per chunk" % (proc, chunksize))
print(f"Calculating with {proc} processes, {chunksize} rays per chunk")

def worker(model, B_vectors, weights, ray, chunksize, out_q):
"""
Expand Down
6 changes: 2 additions & 4 deletions pyart/correct/region_dealias.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def dealias_region_based(
set_limits=True,
vel_field=None,
corr_vel_field=None,
**kwargs
**kwargs,
):
"""
Dealias Doppler velocities using a region based algorithm.
Expand Down Expand Up @@ -316,9 +316,7 @@ def _find_sweep_interval_splits(nyquist, interval_splits, velocities, nsweep):
max_vel = velocities.max()
min_vel = velocities.min()
if max_vel > nyquist or min_vel < -nyquist:
msg = "Velocities outside of the Nyquist interval found in " "sweep %i." % (
nsweep
)
msg = f"Velocities outside of the Nyquist interval found in sweep {nsweep}."
warnings.warn(msg, UserWarning)
# additional intervals must be added to capture the velocities
# outside the nyquist limits
Expand Down
2 changes: 1 addition & 1 deletion pyart/graph/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def generate_ray_title(radar, field, ray):
l1 = f"{generate_radar_name(radar)} {time_str}"
azim = radar.azimuth["data"][ray]
elev = radar.elevation["data"][ray]
l2 = "Ray: %i Elevation: %.1f Azimuth: %.1f" % (ray, elev, azim)
l2 = f"Ray: {ray} Elevation: {elev:.1f} Azimuth: {azim:.1f}"
field_name = generate_field_name(radar, field)
return l1 + "\n" + l2 + "\n" + field_name

Expand Down
2 changes: 1 addition & 1 deletion pyart/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def stringarray_to_chararray(arr, numchars=None):

arr_numchars = carr.shape[-1]
if numchars <= arr_numchars:
raise ValueError("numchars must be >= %i" % (arr_numchars))
raise ValueError(f"numchars must be >= {arr_numchars}")
chararr = np.zeros(arr.shape + (numchars,), dtype="S1")
chararr[..., :arr_numchars] = carr[:]
return chararr
Expand Down
20 changes: 10 additions & 10 deletions pyart/io/mdv_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,13 @@ def read_a_field(self, fnum, debug=False):
compr_data = self.fileptr.read(compr_info["nbytes_coded"])
encoding_type = field_header["encoding_type"]
if encoding_type == ENCODING_INT8:
fmt = ">%iB" % (nx * ny)
fmt = f">{nx*ny}B"
np_form = ">B"
elif encoding_type == ENCODING_INT16:
fmt = ">%iH" % (nx * ny)
fmt = f">{nx*ny}H"
np_form = ">H"
elif encoding_type == ENCODING_FLOAT32:
fmt = ">%if" % (nx * ny)
fmt = f">{nx*ny}f"
np_form = ">f"
else:
raise NotImplementedError("encoding: ", encoding_type)
Expand Down Expand Up @@ -885,7 +885,7 @@ def _get_chunks(self, debug=False):

else:
if debug:
print("getting unknown chunk %i" % chunk_id)
print(f"getting unknown chunk {chunk_id}")
self.chunk_data[cnum] = self._get_unknown_chunk(cnum)

return radar_info, elevations, calib_info
Expand Down Expand Up @@ -913,7 +913,7 @@ def _write_chunks(self, debug=False):

else:
if debug:
print("writing unknown chunk %i" % chunk_id)
print(f"writing unknown chunk {chunk_id}")
self._write_unknown_chunk(self.chunk_data[cnum])

def _get_radar_info(self):
Expand Down Expand Up @@ -941,14 +941,14 @@ def _get_elevs(self, nbytes):
# the file pointer must be set at the correct location prior to call
SIZE_FLOAT = 4.0
nelevations = np.floor(nbytes / SIZE_FLOAT)
fmt = ">%df" % (nelevations)
fmt = f">{nelevations}f"
packet = struct.unpack(fmt, self.fileptr.read(struct.calcsize(fmt)))
return np.array(packet)

def _write_elevs(self, packet):
"""Write an array of elevation."""
# the file pointer must be set at the correct location prior to call
fmt = ">%df" % (len(packet))
fmt = f">{len(packet)}f"
# cast to string as Python < 2.7.7 pack does not except unicode
fmt = str(fmt)
string = struct.pack(fmt, *packet)
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def _write_unknown_chunk(self, data):
def _get_levels_info(self, nlevels):
"""Get nlevel information, return a dict."""
# the file pointer must be set at the correct location prior to call
fmt = ">%iI %iI" % (nlevels, nlevels)
fmt = f">{nlevels}I {nlevels}I"
if self.fileptr:
packet = struct.unpack(fmt, self.fileptr.read(struct.calcsize(fmt)))
else:
Expand All @@ -1019,7 +1019,7 @@ def _get_levels_info(self, nlevels):
def _write_levels_info(self, nlevels, d):
"""write levels information, return a dict."""
# the file pointer must be set at the correct location prior to call
fmt = "%iI %iI" % (nlevels, nlevels)
fmt = f"{nlevels}I {nlevels}I"
packet = d["vlevel_offsets"] + d["vlevel_nbytes"]
# cast to string as Python < 2.7.7 pack does not except unicode
fmt = str(fmt)
Expand Down Expand Up @@ -1101,7 +1101,7 @@ def _calc_geometry(self):
else:
proj_type = self.field_headers[0]["proj_type"]
message = (
"Unsupported projection type: %i, " % (proj_type)
f"Unsupported projection type: {proj_type}, "
+ "is MDV file in antenna coordinates?"
)
raise NotImplementedError(message)
Expand Down
15 changes: 7 additions & 8 deletions pyart/io/nexrad_level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def __init__(self, filename):
# Read and decode 18 byte Message Header Block
self.msg_header = _unpack_from_buf(buf, bpos, MESSAGE_HEADER)
if self.msg_header["code"] not in SUPPORTED_PRODUCTS:
code = self.msg_header["code"]
code = self.msg_header["code"] # noqa: F841
raise NotImplementedError(
"Level3 product with code %i is not supported" % (code)
"Level3 product with code {code} is not supported"
)
bpos += 18

Expand All @@ -139,10 +139,9 @@ def __init__(self, filename):
supp_ver = SUPPORTED_VERSION_NUMBERS[self.msg_header["code"]]
if ver > supp_ver:
warnings.warn(
"Radar product version is %d. Py-ART implementation \
supports max version of %d. Most recent product version has not \
yet been implemented/tested."
% (ver, supp_ver),
f"Radar product version is {ver}. Py-ART implementation \
supports max version of {supp_ver}. Most recent product version has not \
yet been implemented/tested.",
UserWarning,
)

Expand Down Expand Up @@ -456,7 +455,7 @@ def __call__(self, packet_code):
if packet_code == 28:
xdr.update(self._unpack_prod_desc())
else:
raise NotImplementedError("Unknown XDR Component: %d" % (packet_code))
raise NotImplementedError(f"Unknown XDR Component: {packet_code}")

# Check that we got it all
self.done()
Expand Down Expand Up @@ -530,7 +529,7 @@ def _unpack_components(self):
if i < num - 1:
self.unpack_int() # Another pointer for the 'list' ?
except KeyError:
raise NotImplementedError("Unknown XDR Component: %d" % (code))
raise NotImplementedError(f"Unknown XDR Component: {code}")
break

if num == 1:
Expand Down
2 changes: 1 addition & 1 deletion pyart/io/rsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def read_rsl(
for volume_num in available_vols:
# if a volume number is not recognized it is skipped.
if volume_num not in VOLUMENUM2RSLNAME:
warnings.warn("Unknown Volume Number %d" % volume_num)
warnings.warn(f"Unknown Volume Number {volume_num}")
continue
rsl_field_name = VOLUMENUM2RSLNAME[volume_num]
field_name = filemetadata.get_field_name(rsl_field_name)
Expand Down
2 changes: 1 addition & 1 deletion pyart/retrieve/spectra_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def spectra_moments(radar):
wavelength = radar.ds.attrs["wavelength"]
for i in range(times):
if i % 100 == 0:
print("Dealiasing %d/%d" % (i, times))
print(f"Dealiasing {i}/{times}")
spectra_idx = spectra[i, :, :]
# Get the raw spectra, bins, and wavelength
# Subtract the noise floor from the spectra. Also, return the integration limits
Expand Down
2 changes: 1 addition & 1 deletion pyart/testing/data/make_small_mdv_ppi.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@

# read/write elevs chunk
f.seek(elevs_chunk_offset)
fmt = "%df" % (18)
fmt = f"{18}f"
packet = list(struct.unpack(fmt, f.read(struct.calcsize(fmt))))
out.write(struct.pack(fmt, *packet))

Expand Down
2 changes: 1 addition & 1 deletion pyart/testing/data/make_small_mdv_rhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

# read/write elevs chunk
f.seek(elevs_chunk_offset)
fmt = "%df" % (2)
fmt = f"{2}f"
packet = list(struct.unpack(fmt, f.read(struct.calcsize(fmt))))
out.write(struct.pack(fmt, *packet))

Expand Down
4 changes: 2 additions & 2 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def add_field(self, field_name, dic, replace_existing=False):
raise KeyError("dic must contain a 'data' key")
if dic["data"].shape != (self.nz, self.ny, self.nx):
t = (self.nz, self.ny, self.nx)
err = "'data' has invalid shape, should be (%i, %i)" % t
err = "'data' has invalid shape, should be ({}, {})".format(*t)
raise ValueError(err)
self.fields[field_name] = dic

Expand Down Expand Up @@ -458,7 +458,7 @@ def add_field(self, field_name, dic, replace_existing=False):
raise KeyError("dic must contain a 'data' key")
if dic["data"].shape != (self.nrays, self.ngates):
t = (self.nrays, self.ngates)
err = "'data' has invalid shape, should be (%i, %i)" % t
err = "'data' has invalid shape, should be ({}, {})".format(*t)
raise ValueError(err)
# add the field
self.fields[field_name] = dic
Expand Down
Loading