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: Fix linting percent #1572

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion continuous_integration/environment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies:
- cftime
- setuptools
- shapely
- ruff
- ruff==0.4.2
- mda-xdrlib
- xradar
- pip
Expand Down
2 changes: 1 addition & 1 deletion examples/plotting/plot_rhi_cfradial.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

for snum in radar.sweep_number["data"]:
fixed_angle = radar.fixed_angle["data"][snum]
title = "HSRHI Az=%.3f" % (fixed_angle)
title = f"HSRHI Az={fixed_angle:.3f}"
ax = fig.add_subplot(nplots, 1, snum + 1)
display.plot(
"reflectivity_horizontal",
Expand Down
2 changes: 1 addition & 1 deletion examples/plotting/plot_rhi_cfradial_singlescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# nplots = radar.nsweeps

fixed_angle = radar.fixed_angle["data"][0]
title = "HSRHI Az=%.3f" % (fixed_angle)
title = f"HSRHI Az={fixed_angle:.3f}"
ax = fig.add_subplot(1, 1, 1)
display.plot(
"reflectivity_horizontal",
Expand Down
4 changes: 2 additions & 2 deletions pyart/aux_io/gamic_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def read_gamic(
valid_range_from_file=True,
units_from_file=True,
pulse_width=None,
**kwargs
**kwargs,
):
"""
Read a GAMIC hdf5 file.
Expand Down Expand Up @@ -167,7 +167,7 @@ def read_gamic(
if not gfile.is_file_single_scan_type():
raise NotImplementedError("Mixed scan_type volume.")
if scan_type not in ["ppi", "rhi"]:
message = "Unknown scan type: %s, reading as RHI scans." % (scan_type)
message = f"Unknown scan type: {scan_type}, reading as RHI scans."
warnings.warn(message)
scan_type = "rhi"

Expand Down
4 changes: 2 additions & 2 deletions pyart/aux_io/odim_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def read_odim_h5(
include_fields=None,
include_datasets=None,
exclude_datasets=None,
**kwargs
**kwargs,
):
"""
Read a ODIM_H5 file.
Expand Down Expand Up @@ -130,7 +130,7 @@ def read_odim_h5(
with h5py.File(filename, "r") as hfile:
odim_object = _to_str(hfile["what"].attrs["object"])
if odim_object not in ["PVOL", "SCAN", "ELEV", "AZIM"]:
raise NotImplementedError("object: %s not implemented." % (odim_object))
raise NotImplementedError(f"object: {odim_object} not implemented.")

# determine the number of sweeps by the number of groups which
# begin with dataset
Expand Down
2 changes: 1 addition & 1 deletion pyart/aux_io/radx_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def read_radx_grid(filename, exclude_fields=None, **kwargs):
field_dic["data"].shape = field_shape
fields[field] = field_dic
else:
warnings.warn("Field %s skipped due to incorrect shape" % (field))
warnings.warn(f"Field {field} skipped due to incorrect shape")

# radar_ variables
if "radar_latitude" in dset.variables:
Expand Down
2 changes: 1 addition & 1 deletion pyart/aux_io/sinarame_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def read_sinarame_h5(
hfile = h5py.File(filename, "r")
SINARAME_object = _to_str(hfile["what"].attrs["object"])
if SINARAME_object not in ["PVOL", "SCAN", "ELEV", "AZIM"]:
raise NotImplementedError("object: %s not implemented." % (SINARAME_object))
raise NotImplementedError(f"object: {SINARAME_object} not implemented.")

# determine the number of sweeps by the number of groups which
# begin with dataset
Expand Down
2 changes: 1 addition & 1 deletion pyart/core/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def add_field(self, field_name, field_dict, replace_existing=False):
if "data" not in field_dict:
raise KeyError('Field dictionary must contain a "data" key')
if field_name in self.fields and replace_existing is False:
raise ValueError("A field named %s already exists" % (field_name))
raise ValueError(f"A field named {field_name} already exists")
if field_dict["data"].shape != (self.nz, self.ny, self.nx):
raise ValueError("Field has invalid shape")

Expand Down
4 changes: 2 additions & 2 deletions pyart/core/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def add_field(self, field_name, dic, replace_existing=False):
"""
# check that the field dictionary to add is valid
if field_name in self.fields and replace_existing is False:
err = "A field with name: %s already exists" % (field_name)
err = f"A field with name: {field_name} already exists"
raise ValueError(err)
if "data" not in dic:
raise KeyError("dic must contain a 'data' key")
Expand Down Expand Up @@ -892,7 +892,7 @@ def add_field_like(

"""
if existing_field_name not in self.fields:
err = "field %s does not exist in object" % (existing_field_name)
err = f"field {existing_field_name} does not exist in object"
raise ValueError(err)
dic = {}
for k, v in self.fields[existing_field_name].items():
Expand Down
6 changes: 3 additions & 3 deletions pyart/correct/unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def dealias_unwrap_phase(
vel_field=None,
corr_vel_field=None,
skip_checks=False,
**kwargs
**kwargs,
):
"""
Dealias Doppler velocities using multi-dimensional phase unwrapping
Expand Down Expand Up @@ -270,7 +270,7 @@ def _is_radar_sweep_aligned(radar, diff=0.1):
elif radar.scan_type == "rhi":
angles = radar.elevation["data"]
else:
raise ValueError("invalid scan_type: %s" % (radar.scan_type))
raise ValueError(f"invalid scan_type: {radar.scan_type}")
starts = radar.sweep_start_ray_index["data"]
ends = radar.sweep_end_ray_index["data"]
ref_angles = angles[starts[0] : ends[0] + 1]
Expand Down Expand Up @@ -302,6 +302,6 @@ def _is_sweep_sequential(radar, sweep_number):
# equivalent variable to an angle.
angles = radar.time["data"]
else:
raise ValueError("invalid scan_type: %s" % (radar.scan_type))
raise ValueError(f"invalid scan_type: {radar.scan_type}")
rolled_angles = np.roll(angles, -np.argmin(angles))
return np.all(np.diff(rolled_angles) >= 0)
2 changes: 1 addition & 1 deletion pyart/graph/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def generate_az_rhi_title(radar, field, azimuth):
"""
time_str = generate_radar_time_begin(radar).isoformat() + "Z"
l1 = f"{generate_radar_name(radar)} {time_str} "
l2 = "Azimuth: %.1f deg" % azimuth
l2 = f"Azimuth: {azimuth:.1f} deg"
field_name = generate_field_name(radar, field)
return l1 + "\n" + l2 + "\n" + field_name

Expand Down
12 changes: 6 additions & 6 deletions pyart/graph/radardisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def plot(self, field, sweep=0, **kwargs):
elif self.scan_type == "vpt":
self.plot_vpt(field, **kwargs)
else:
raise ValueError("unknown scan_type % s" % (self.scan_type))
raise ValueError(f"unknown scan_type {self.scan_type: }")
return

def plot_ray(
Expand Down Expand Up @@ -255,7 +255,7 @@ def plot_ppi(
raster=False,
title_datetime_format=None,
title_use_sweep_time=True,
**kwargs
**kwargs,
):
"""
Plot a PPI.
Expand Down Expand Up @@ -426,7 +426,7 @@ def plot_rhi(
raster=False,
title_datetime_format=None,
title_use_sweep_time=True,
**kwargs
**kwargs,
):
"""
Plot a RHI.
Expand Down Expand Up @@ -609,7 +609,7 @@ def plot_vpt(
ticks=None,
ticklabs=None,
raster=False,
**kwargs
**kwargs,
):
"""
Plot a VPT scan.
Expand Down Expand Up @@ -791,7 +791,7 @@ def plot_azimuth_to_rhi(
ticks=None,
ticklabs=None,
raster=False,
**kwargs
**kwargs,
):
"""
Plot pseudo-RHI scan by extracting the vertical field associated
Expand Down Expand Up @@ -1280,7 +1280,7 @@ def plot_colorbar(
fig=None,
ticks=None,
ticklabs=None,
**kwargs
**kwargs,
):
"""
Plot a colorbar.
Expand Down
4 changes: 2 additions & 2 deletions pyart/graph/radardisplay_airborne.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def plot(self, field, sweep=0, **kwargs):
elif self.scan_type == "vpt":
self.plot_sweep_grid(field, sweep, **kwargs)
else:
raise ValueError("unknown scan_type % s" % (self.scan_type))
raise ValueError(f"unknown scan_type {self.scan_type: }")
return

def plot_sweep_grid(
Expand Down Expand Up @@ -146,7 +146,7 @@ def plot_sweep_grid(
raster=False,
ticks=None,
ticklabs=None,
**kwargs
**kwargs,
):
"""
Plot a sweep as a grid.
Expand Down
4 changes: 2 additions & 2 deletions pyart/io/cfradial.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ def write_cfradial(
# Do not try to write instrument parameter whose dimensions are
# not known, rather issue a warning and skip the parameter
message = (
"Unknown instrument parameter: %s, " % (k) + "not written to file."
f"Unknown instrument parameter: {k}, " + "not written to file."
)
warnings.warn(message)

Expand Down Expand Up @@ -812,7 +812,7 @@ def _create_ncvar(dic, dataset, name, dimensions):
# create array from list, etc.
data = dic["data"]
if isinstance(data, np.ndarray) is not True:
warnings.warn("Warning, converting non-array to array:%s" % name)
warnings.warn(f"Warning, converting non-array to array:{name}")
data = np.array(data)

# convert string/unicode arrays to character arrays
Expand Down
2 changes: 1 addition & 1 deletion pyart/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _test_arguments(dic):
if dic:
import warnings

warnings.warn("Unexpected arguments: %s" % dic.keys())
warnings.warn(f"Unexpected arguments: {dic.keys()}")


def make_time_unit_str(dtobj):
Expand Down
6 changes: 3 additions & 3 deletions pyart/io/mdv_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def write_grid_mdv(filename, grid, mdv_field_names=None, field_write_order=None)
d["data_element_nbytes"] = 4
else:
raise TypeError(
"Unsuported encoding %s, encoding must be "
f"Unsuported encoding {dtype}, encoding must be "
"uint8, uint16 or float32 as specfied by "
"the '_Write_as_dtype key" % dtype
"the '_Write_as_dtype key"
)
d["compression_type"] = 3 # zlib

Expand Down Expand Up @@ -233,7 +233,7 @@ def read_grid_mdv(
file_field_names=False,
exclude_fields=None,
delay_field_loading=False,
**kwargs
**kwargs,
):
"""
Read a MDV file to a Grid Object.
Expand Down
4 changes: 2 additions & 2 deletions pyart/io/mdv_radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def read_mdv(
exclude_fields=None,
include_fields=None,
delay_field_loading=False,
**kwargs
**kwargs,
):
"""
Read a MDV file.
Expand Down Expand Up @@ -96,7 +96,7 @@ def read_mdv(
scan_type = mdvfile.projection

if scan_type not in ["ppi", "rhi"]:
raise NotImplementedError("No support for scan_type %s." % scan_type)
raise NotImplementedError(f"No support for scan_type {scan_type}.")

# time
time = filemetadata("time")
Expand Down
4 changes: 2 additions & 2 deletions pyart/io/nexrad_cdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_nexrad_cdm(
exclude_fields=None,
include_fields=None,
station=None,
**kwargs
**kwargs,
):
"""
Read a Common Data Model (CDM) NEXRAD Level 2 file.
Expand Down Expand Up @@ -99,7 +99,7 @@ def read_nexrad_cdm(
dattrs = dataset.ncattrs()
dvars = dataset.variables
if "cdm_data_type" not in dattrs or dataset.cdm_data_type != "RADIAL":
raise OSError("%s is not a valid CDM NetCDF file" % (filename))
raise OSError(f"{filename} is not a valid CDM NetCDF file")

# determine the scan information
scan_info = _scan_info(dvars)
Expand Down
2 changes: 1 addition & 1 deletion pyart/io/uf_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def make_mandatory_header(self, ray_num):
sweep_mode_number = UF_SWEEP_MODES[self.radar.scan_type]
else:
warnings.warn(
"Unknown scan_type: %s, defaulting to PPI" % (self.radar.scan_type)
f"Unknown scan_type: {self.radar.scan_type}, defaulting to PPI"
)
sweep_mode_number = UF_SWEEP_MODES["ppi"]
header["sweep_mode"] = sweep_mode_number
Expand Down
4 changes: 2 additions & 2 deletions pyart/map/gates_to_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def map_gates_to_grid(
nb=1.0,
bsp=1.0,
dist_factor=(1.0, 1.0, 1.0),
**kwargs
**kwargs,
):
"""
Map gates from one or more radars to a Cartesian grid.
Expand Down Expand Up @@ -343,5 +343,5 @@ def _parse_roi_func(
elif roi_func == "dist_beam":
roi_func = DistBeamRoI(h_factor, nb, bsp, min_radius, offsets)
else:
raise ValueError("unknown roi_func: %s" % roi_func)
raise ValueError(f"unknown roi_func: {roi_func}")
return roi_func
8 changes: 4 additions & 4 deletions pyart/map/grid_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def grid_from_radars(
grid_limits,
gridding_algo="map_gates_to_grid",
copy_field_dtypes=True,
**kwargs
**kwargs,
):
"""
Map one or more radars to a Cartesian grid returning a Grid object.
Expand Down Expand Up @@ -296,7 +296,7 @@ def map_to_grid(
h_factor=(1.0, 1.0, 1.0),
nb=1.0,
bsp=1.0,
**kwargs
**kwargs,
):
"""
Map one or more radars to a Cartesian grid.
Expand Down Expand Up @@ -469,7 +469,7 @@ def map_to_grid(
if weighting_function.upper() not in ["CRESSMAN", "BARNES2", "BARNES", "NEAREST"]:
raise ValueError("unknown weighting_function")
if algorithm not in ["kd_tree"]:
raise ValueError("unknown algorithm: %s" % algorithm)
raise ValueError(f"unknown algorithm: {algorithm}")
badval = get_fillvalue()

# parse the grid_projection
Expand Down Expand Up @@ -655,7 +655,7 @@ def map_to_grid(
elif roi_func == "dist_beam":
roi_func = _gen_roi_func_dist_beam(h_factor, nb, bsp, min_radius, offsets)
else:
raise ValueError("unknown roi_func: %s" % roi_func)
raise ValueError(f"unknown roi_func: {roi_func}")

# create array to hold interpolated grid data and roi if requested
grid_data = np.ma.empty((nz, ny, nx, nfields), dtype=np.float64)
Expand Down
4 changes: 2 additions & 2 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def add_field(self, field_name, dic, replace_existing=False):
"""
# check that the field dictionary to add is valid
if field_name in self.fields and replace_existing is False:
err = "A field with name: %s already exists" % (field_name)
err = f"A field with name: {field_name} already exists"
raise ValueError(err)
if "data" not in dic:
raise KeyError("dic must contain a 'data' key")
Expand Down Expand Up @@ -431,7 +431,7 @@ def add_field(self, field_name, dic, replace_existing=False):
"""
# check that the field dictionary to add is valid
if field_name in self.fields and replace_existing is False:
err = "A field with name: %s already exists" % (field_name)
err = f"A field with name: {field_name} already exists"
raise ValueError(err)
if "data" not in dic:
raise KeyError("dic must contain a 'data' key")
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_auto_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_autoread_raises():
@pytest.mark.parametrize("i", headers)
def test_determine_filetype(i):
string, filetype = i
check_filetype.description = "determine filetype: %s" % (filetype)
check_filetype.description = f"determine filetype: {filetype}"
check_filetype(string, filetype)


Expand Down
Loading
Loading