Skip to content

Commit

Permalink
Autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Sep 2, 2024
1 parent 06399a9 commit ed270b0
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 33 deletions.
4 changes: 2 additions & 2 deletions doc/extensions/pythonscript_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(self):
# Use sphinx logger?
uid = uuid.uuid4().hex[:8]
print("")
print(">> Contents of the script: %s" % uid)
print(f">> Contents of the script: {uid}")
print(content)
print("")

Expand Down Expand Up @@ -87,7 +87,7 @@ def get_image_tag(filename, image_dir, image_rel_dir):
my_uuid = uuid.uuid4().hex
shutil.move(filename, image_dir + os.path.sep + my_uuid + filename)
relative_filename = image_rel_dir + os.path.sep + my_uuid + filename
return '<img src="%s" width="600"><br>' % relative_filename
return f'<img src="{relative_filename}" width="600"><br>'


def make_image_dir(setup, rst_dir):
Expand Down
4 changes: 2 additions & 2 deletions doc/extensions/yt_colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def run(self):
lines = []
for im in images:
im_name = os.path.join("_static", os.path.basename(im))
lines.append(".. image:: %s" % im_name)
lines.append(f".. image:: {im_name}")
lines.append(" :width: 400")
lines.append(" :target: ../../_images/%s" % os.path.basename(im))
lines.append(f" :target: ../../_images/{os.path.basename(im)}")
lines.append("\n")
lines.append("\n")
self.state_machine.insert_input(lines, rst_file)
Expand Down
8 changes: 4 additions & 4 deletions doc/extensions/yt_cookbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ def run(self):
)

im_path = os.path.join(rst_dir, "_static")
images = sorted(glob.glob(os.path.join(im_path, "%s__*.png" % script_name)))
images = sorted(glob.glob(os.path.join(im_path, f"{script_name}__*.png")))
lines = []
lines.append(f"(`{script_bn} <{script_fn}>`__)")
lines.append("\n")
lines.append("\n")
lines.append(".. literalinclude:: %s" % self.arguments[0])
lines.append(f".. literalinclude:: {self.arguments[0]}")
lines.append("\n")
lines.append("\n")
for im in images:
im_name = os.path.join("_static", os.path.basename(im))
lines.append(".. image:: %s" % im_name)
lines.append(f".. image:: {im_name}")
lines.append(" :width: 400")
lines.append(" :target: ../_images/%s" % os.path.basename(im))
lines.append(f" :target: ../_images/{os.path.basename(im)}")
lines.append("\n")
lines.append("\n")
for ext in data_patterns:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_version(filename):
for line in f.readlines():
if line.startswith("__version__"):
return line.split("=")[1].strip()[1:-1]
raise RuntimeError("Could not get version from %s." % filename)
raise RuntimeError(f"Could not get version from {filename}.")


VERSION = get_version("yt_astro_analysis/__init__.py")
Expand Down
2 changes: 2 additions & 0 deletions yt_astro_analysis/cosmological_observation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@

from yt_astro_analysis.cosmological_observation.cosmology_splice import CosmologySplice
from yt_astro_analysis.cosmological_observation.light_cone.api import LightCone

__all__ = ["CosmologySplice", "LightCone"]
2 changes: 2 additions & 0 deletions yt_astro_analysis/cosmological_observation/light_cone/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# -----------------------------------------------------------------------------

from .light_cone import LightCone

__all__ = ["LightCone"]
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def _save_light_cone_solution(self, filename="light_cone.dat"):
mylog.info("Saving light cone solution to %s.", filename)

f = open(filename, "w")
f.write("# parameter_filename = %s\n" % self.parameter_filename)
f.write(f"# parameter_filename = {self.parameter_filename}\n")
f.write("\n")
f.write(
"# Slice Dataset Redshift depth/box "
Expand Down Expand Up @@ -491,10 +491,10 @@ def _save_light_cone_stack(
)

field_node = f"{field}_{weight_field}"
weight_field_node = "weight_field_%s" % weight_field
weight_field_node = f"weight_field_{weight_field}"

if filename is None:
filename = os.path.join(self.output_dir, "%s_data" % self.output_prefix)
filename = os.path.join(self.output_dir, f"{self.output_prefix}_data")

Check warning on line 497 in yt_astro_analysis/cosmological_observation/light_cone/light_cone.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/cosmological_observation/light_cone/light_cone.py#L497

Added line #L497 was not covered by tests
if not (filename.endswith(".h5")):
filename += ".h5"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def run(self):
punits = (
_funits[self.field] * _funits[self.weight_field] * _funits["length"]
)
wunits = fh["weight_field_%s" % self.weight_field].attrs["units"]
wunits = fh[f"weight_field_{self.weight_field}"].attrs["units"]
pwunits = _funits[self.weight_field] * _funits["length"]
assert wunits == str(pwunits.units)
assert units == str(punits.units)
Expand Down
9 changes: 9 additions & 0 deletions yt_astro_analysis/halo_analysis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@
VisibleDeprecationWarning,
stacklevel=2,
)

__all__ = [
"add_quantity",
"add_callback",
"add_filter",
"add_finding_method",
"add_recipe",
"HaloCatalog",
]
17 changes: 8 additions & 9 deletions yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def halo_sphere(halo, radius_field="virial_radius", factor=1.0, field_parameters
"""

dds = halo.halo_catalog.data_ds
center = dds.arr([halo.quantities["particle_position_%s" % axis] for axis in "xyz"])
center = dds.arr([halo.quantities[f"particle_position_{axis}"] for axis in "xyz"])

Check warning on line 60 in yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py#L60

Added line #L60 was not covered by tests
radius = factor * halo.quantities[radius_field]
if radius <= 0.0:
halo.data_object = None
Expand Down Expand Up @@ -255,7 +255,7 @@ def profile(
field: my_profile.standard_deviation[field]
for field in my_profile.standard_deviation
}
variance_storage = "%s_variance" % storage
variance_storage = f"{storage}_variance"

Check warning on line 258 in yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py#L258

Added line #L258 was not covered by tests
if hasattr(halo, variance_storage):
halo_variance_store = getattr(halo, variance_storage)
else:
Expand Down Expand Up @@ -315,7 +315,7 @@ def save_profiles(halo, storage="profiles", filename=None, output_dir="."):
if isinstance(my_profile[field], YTArray):
my_profile[field].convert_to_cgs()
_yt_array_hdf5(profile_group, str(field), my_profile[field])
variance_storage = "%s_variance" % storage
variance_storage = f"{storage}_variance"

Check warning on line 318 in yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py#L318

Added line #L318 was not covered by tests
if hasattr(halo, variance_storage):
my_profile = getattr(halo, variance_storage)
variance_group = fh.create_group("variance")
Expand Down Expand Up @@ -364,7 +364,7 @@ def load_profiles(halo, storage="profiles", fields=None, filename=None, output_d
"%s_%06d.h5" % (filename, halo.quantities["particle_identifier"]),
)
if not os.path.exists(output_file):
raise RuntimeError("Profile file not found: %s." % output_file)
raise RuntimeError(f"Profile file not found: {output_file}.")

Check warning on line 367 in yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py#L367

Added line #L367 was not covered by tests
mylog.info(
"Loading halo %d profile data from %s.",
halo.quantities["particle_identifier"],
Expand Down Expand Up @@ -397,7 +397,7 @@ def load_profiles(halo, storage="profiles", fields=None, filename=None, output_d
my_variance[field] = _hdf5_yt_array(
my_group, field, ds=halo.halo_catalog.halos_ds
)
setattr(halo, "%s_variance" % storage, my_variance)
setattr(halo, f"{storage}_variance", my_variance)

Check warning on line 400 in yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py#L400

Added line #L400 was not covered by tests

fh.close()

Expand Down Expand Up @@ -451,8 +451,7 @@ def virial_quantities(

if overdensity_field not in profile_data:
raise RuntimeError(
"virial_quantities callback requires profile of %s."
% str(overdensity_field)
f"virial_quantities callback requires profile of {str(overdensity_field)}."
)

overdensity = profile_data[overdensity_field]
Expand Down Expand Up @@ -630,7 +629,7 @@ def iterative_center_of_mass(
)

center_orig = halo.halo_catalog.data_ds.arr(
[halo.quantities["particle_position_%s" % axis] for axis in "xyz"]
[halo.quantities[f"particle_position_{axis}"] for axis in "xyz"]
)
sphere = halo.halo_catalog.data_ds.sphere(
center_orig, outer_radius * halo.quantities[radius_field]
Expand All @@ -653,7 +652,7 @@ def iterative_center_of_mass(
)

for i, axis in enumerate("xyz"):
halo.quantities["particle_position_%s" % axis] = sphere.center[i]
halo.quantities[f"particle_position_{axis}"] = sphere.center[i]

Check warning on line 655 in yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_callbacks.py#L655

Added line #L655 was not covered by tests
del sphere


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def quantity_value(halo, field, operator, value, units):
"""

if field not in halo.quantities:
raise RuntimeError("Halo object does not contain %s quantity." % field)
raise RuntimeError(f"Halo object does not contain {field} quantity.")

Check warning on line 34 in yt_astro_analysis/halo_analysis/halo_catalog/halo_filters.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_catalog/halo_filters.py#L34

Added line #L34 was not covered by tests

h_value = halo.quantities[field].in_units(units).to_ndarray()
return eval(f"{h_value} {operator} {value}")
Expand Down
2 changes: 2 additions & 0 deletions yt_astro_analysis/halo_analysis/halo_finding/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
)

from yt_astro_analysis.halo_finding.halo_objects import FOFHaloFinder, HOPHaloFinder

__all__ = ["FOFHaloFinder", "HOPHaloFinder"]
8 changes: 4 additions & 4 deletions yt_astro_analysis/halo_analysis/halo_finding/halo_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def maximum_density_location(self):


class HaloList:
_fields = ["particle_position_%s" % ax for ax in "xyz"]
_fields = [f"particle_position_{ax}" for ax in "xyz"]

def __init__(self, data_source, redshift=-1, ptype="all"):
"""
Expand Down Expand Up @@ -627,7 +627,7 @@ def _parse_output(self):
)
md_i = np.argmax(dens[cp:cp_c])
px, py, pz = (
self.particle_fields["particle_position_%s" % ax][group_indices]
self.particle_fields[f"particle_position_{ax}"][group_indices]
for ax in "xyz"
)
self._max_dens[i] = (dens[cp:cp_c][md_i], px[md_i], py[md_i], pz[md_i])
Expand All @@ -651,7 +651,7 @@ class HOPHaloList(HaloList):

_name = "HOP"
_halo_class = HOPHalo
_fields = ["particle_position_%s" % ax for ax in "xyz"] + ["particle_mass"]
_fields = [f"particle_position_{ax}" for ax in "xyz"] + ["particle_mass"]

def __init__(self, data_source, threshold=160.0, ptype="all"):
self.threshold = threshold
Expand Down Expand Up @@ -740,7 +740,7 @@ def _reposition_particles(self, bounds):
LE, RE = bounds
dw = self.ds.domain_right_edge - self.ds.domain_left_edge
for i, ax in enumerate("xyz"):
arr = self._data_source[self.ptype, "particle_position_%s" % ax]
arr = self._data_source[self.ptype, f"particle_position_{ax}"]

Check warning on line 743 in yt_astro_analysis/halo_analysis/halo_finding/halo_objects.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_finding/halo_objects.py#L743

Added line #L743 was not covered by tests
arr[arr < LE[i] - self.padding] += dw[i]
arr[arr > RE[i] + self.padding] -= dw[i]

Expand Down
3 changes: 3 additions & 0 deletions yt_astro_analysis/halo_analysis/halo_finding/rockstar/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
from yt_astro_analysis.halo_analysis.halo_finding.rockstar.rockstar import (
RockstarHaloFinder,
)


__all__ = ["RockstarHaloFinder"]
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def _setup_parameters(self, ts):
if ptype not in tds.particle_types and ptype != "all":
has_particle_filter = tds.add_particle_filter(ptype)
if not has_particle_filter:
raise RuntimeError("Particle type (filter) %s not found." % (ptype))
raise RuntimeError(f"Particle type (filter) {ptype} not found.")

Check warning on line 304 in yt_astro_analysis/halo_analysis/halo_finding/rockstar/rockstar.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_finding/rockstar/rockstar.py#L304

Added line #L304 was not covered by tests

dd = tds.all_data()
# Get DM particle mass.
Expand Down Expand Up @@ -370,7 +370,7 @@ def run(self, block_ratio=1, callbacks=None, restart=False):
if restart:
restart_file = os.path.join(self.outbase, "restart.cfg")
if not os.path.exists(restart_file):
raise RuntimeError("Restart file %s not found" % (restart_file))
raise RuntimeError(f"Restart file {restart_file} not found")

Check warning on line 373 in yt_astro_analysis/halo_analysis/halo_finding/rockstar/rockstar.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/halo_finding/rockstar/rockstar.py#L373

Added line #L373 was not covered by tests
with open(restart_file) as restart_fh:
for par in restart_fh:
if par.startswith("RESTART_SNAP"):
Expand Down
2 changes: 1 addition & 1 deletion yt_astro_analysis/halo_analysis/tests/test_halo_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run(self):
hc.add_quantity("nstars")
hc.create()

fn = os.path.join(tmpdir, str(dds), "%s.0.h5" % str(dds))
fn = os.path.join(tmpdir, str(dds), f"{str(dds)}.0.h5")

Check warning on line 63 in yt_astro_analysis/halo_analysis/tests/test_halo_catalog.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/halo_analysis/tests/test_halo_catalog.py#L63

Added line #L63 was not covered by tests
ds = load(fn)
ad = ds.all_data()
mi, ma = ad.quantities.extrema("nstars")
Expand Down
2 changes: 2 additions & 0 deletions yt_astro_analysis/ppv_cube/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
# -----------------------------------------------------------------------------

from yt_astro_analysis.ppv_cube.ppv_cube import PPVCube

__all__ = ["PPVCube"]
2 changes: 1 addition & 1 deletion yt_astro_analysis/ppv_cube/ppv_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _v_los(field, data):
elif isinstance(normal, str):

def _v_los(field, data):
return -data["gas", "velocity_%s" % normal]
return -data["gas", f"velocity_{normal}"]

else:
orient = Orientation(normal)
Expand Down
4 changes: 2 additions & 2 deletions yt_astro_analysis/radmc3d_export/RadMC3DInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def write_source_files(self, sources, wavelengths):

# write wavelength information
for wavelength in wavelengths:
fhandle.write("%f \n" % wavelength)
fhandle.write(f"{wavelength:f} \n")

Check warning on line 379 in yt_astro_analysis/radmc3d_export/RadMC3DInterface.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/radmc3d_export/RadMC3DInterface.py#L379

Added line #L379 was not covered by tests

# finally write blackbody temperature for each source
for source in sources:
Expand All @@ -394,7 +394,7 @@ def write_source_files(self, sources, wavelengths):

fhandle.write("%d \n" % nlam)
for wavelength in wavelengths:
fhandle.write("%f \n" % wavelength)
fhandle.write(f"{wavelength:f} \n")

Check warning on line 397 in yt_astro_analysis/radmc3d_export/RadMC3DInterface.py

View check run for this annotation

Codecov / codecov/patch

yt_astro_analysis/radmc3d_export/RadMC3DInterface.py#L397

Added line #L397 was not covered by tests

# done with both
fhandle.close()
Expand Down
2 changes: 2 additions & 0 deletions yt_astro_analysis/radmc3d_export/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
RadMC3DSource,
RadMC3DWriter,
)

__all__ = ["read_radmc3d_image", "RadMC3DSource", "RadMC3DWriter"]

0 comments on commit ed270b0

Please sign in to comment.