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

chore: update pre-commit hooks #198

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ repos:
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.2"
rev: "v0.9.1"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.13.0"
rev: "v1.14.1"
hooks:
- id: mypy
files: flint|tests
Expand All @@ -57,7 +57,7 @@ repos:
- types-PyYAML

- repo: https://github.com/crate-ci/typos
rev: v1.29.4
rev: dictgen-v0.3.1
hooks:
- id: typos

Expand Down Expand Up @@ -87,7 +87,7 @@ repos:
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.30.0"
rev: "0.31.0"
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
12 changes: 6 additions & 6 deletions flint/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
logger.info(f"Copying {total} files into {copy_out_path}")
for count, file in enumerate(files_to_copy):
if file.is_file():
logger.info(f"{count+1} of {total}, copying file {file}")
logger.info(f"{count + 1} of {total}, copying file {file}")
shutil.copy(file, copy_out_path)
elif file.is_dir():
# TODO: Add an option to tar folders into the final location
logger.info(f"{count+1} of {total}, copying folder {file}")
logger.info(f"{count + 1} of {total}, copying folder {file}")

Check warning on line 84 in flint/archive.py

View check run for this annotation

Codecov / codecov/patch

flint/archive.py#L84

Added line #L84 was not covered by tests
shutil.copytree(file, copy_out_path / file.name)
else:
not_copied.append(file)
Expand All @@ -108,9 +108,9 @@
bool: True if the ``tar``s exit code is 0, False otherwise
"""
tarball = Path(tarball) # trust nothing
assert (
tarball.exists() and tarball.is_file()
), f"{tarball} is not a file or does not exist"
assert tarball.exists() and tarball.is_file(), (
f"{tarball} is not a file or does not exist"
)
assert tarball.suffix == ".tar", f"{tarball=} appears to not have a .tar extension"

cmd = f"tar -tvf {tarball!s}"
Expand Down Expand Up @@ -155,7 +155,7 @@
logger.info(f"Opening {tar_out_path}")
with tarfile.open(tar_out_path, "w") as tar:
for count, file in enumerate(files_to_tar):
logger.info(f"{count+1} of {total}, adding {file!s}")
logger.info(f"{count + 1} of {total}, adding {file!s}")
tar.add(file, arcname=file.name)

logger.info(f"Created {tar_out_path}")
Expand Down
6 changes: 3 additions & 3 deletions flint/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
field_names = tab.getcol("NAME")
field_idx = np.argwhere([fn == good_field_name for fn in field_names])[0]

assert (
len(field_idx) == 1
), f"More than one matching field name found. This should not happen. {good_field_name=} {field_names=}"
assert len(field_idx) == 1, (

Check warning on line 70 in flint/bandpass.py

View check run for this annotation

Codecov / codecov/patch

flint/bandpass.py#L70

Added line #L70 was not covered by tests
f"More than one matching field name found. This should not happen. {good_field_name=} {field_names=}"
)

field_idx = field_idx[0]
logger.info(f"{good_field_name} FIELD_ID is {field_idx}")
Expand Down
24 changes: 12 additions & 12 deletions flint/bptools/preflagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def flags_over_threshold(
bool: Whether the number of flags has reached a threshold
"""

assert (
0.0 <= thresh <= 1.0
), f"The provided {thresh=} should be a fraction between 0 to 1. "
assert 0.0 <= thresh <= 1.0, (
f"The provided {thresh=} should be a fraction between 0 to 1. "
)

number_flagged = np.sum(flags)
# Use the shape in case multi-dimensional array passed in
Expand Down Expand Up @@ -468,9 +468,9 @@ def flag_mean_xxyy_amplitude_ratio(
bool: Whether data should be flagged (True) or not (False)
"""

assert (
xx_complex_gains.shape == yy_complex_gains.shape
), f"Input xx and yy shapes do not match. {xx_complex_gains.shape=} {yy_complex_gains.shape=}"
assert xx_complex_gains.shape == yy_complex_gains.shape, (
f"Input xx and yy shapes do not match. {xx_complex_gains.shape=} {yy_complex_gains.shape=}"
)
logger.info("Calculating mean ratios. ")

xx_amplitudes = np.abs(xx_complex_gains)
Expand Down Expand Up @@ -514,9 +514,9 @@ def construct_mesh_ant_flags(mask: np.ndarray) -> np.ndarray:
np.ndarray: Output array where antennas have common sets of flags
"""

assert (
len(mask.shape) == 3
), f"Expect array of shape (ant, channel, pol), received {mask.shape=}"
assert len(mask.shape) == 3, (
f"Expect array of shape (ant, channel, pol), received {mask.shape=}"
)
accumulate_mask = np.zeros_like(mask[0], dtype=bool)

nant = mask.shape[0]
Expand Down Expand Up @@ -562,9 +562,9 @@ def construct_jones_over_max_amp_flags(
np.ndarray: Boolean array of equal shape to `complex_gains`, with `True` indicating a flag
"""

assert (
complex_gains.shape[-1] == 4
), f"Expected last dimension to be length 4, received {complex_gains.shape=}"
assert complex_gains.shape[-1] == 4, (
f"Expected last dimension to be length 4, received {complex_gains.shape=}"
)

logger.info(f"Creating mask for Jones with amplitudes of {max_amplitude=}")
complex_gains = complex_gains.copy()
Expand Down
18 changes: 9 additions & 9 deletions flint/bptools/smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def divide_bandpass_by_ref_ant_preserve_phase(
Returns:
np.ndarray: The normalised bandpass solutions
"""
assert (
len(complex_gains.shape) == 3
), f"The shape of the input complex gains should be of rank 3 in form (ant, chan, pol). Received {complex_gains.shape}"
assert len(complex_gains.shape) == 3, (
f"The shape of the input complex gains should be of rank 3 in form (ant, chan, pol). Received {complex_gains.shape}"
)

logger.info(
f"Dividing bandpass gain solutions using reference antenna={ref_ant}, using correct phasor"
Expand Down Expand Up @@ -113,9 +113,9 @@ def divide_bandpass_by_ref_ant(complex_gains: np.ndarray, ref_ant: int) -> np.nd
Returns:
np.ndarray: The normalised bandpass solutions
"""
assert (
len(complex_gains.shape) == 3
), f"The shape of the input complex gains should be of rank 3 in form (ant, chan, pol). Received {complex_gains.shape}"
assert len(complex_gains.shape) == 3, (
f"The shape of the input complex gains should be of rank 3 in form (ant, chan, pol). Received {complex_gains.shape}"
)

logger.info(
f"Dividing bandpass gain solutions using reference antenna={ref_ant} with shifted phasor"
Expand Down Expand Up @@ -234,9 +234,9 @@ def smooth_bandpass_complex_gains(
np.ndarray: Smoothed complex gains
"""

assert (
len(complex_gains.shape) == 3
), f"The shape of the input complex gains should be of rank 3 in form (ant, chan, pol). Received {complex_gains.shape}"
assert len(complex_gains.shape) == 3, (
f"The shape of the input complex gains should be of rank 3 in form (ant, chan, pol). Received {complex_gains.shape}"
)

# Duplicate the original, ya filthy pirate
smoothed_complex_gains = complex_gains.copy()
Expand Down
52 changes: 26 additions & 26 deletions flint/calibrate/aocalibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@
AOSolutions: Structure container the deserialized solutions file
"""

assert (
solutions_path.exists() and solutions_path.is_file()
), f"{solutions_path!s} either does not exist or is not a file. "
assert solutions_path.exists() and solutions_path.is_file(), (
f"{solutions_path!s} either does not exist or is not a file. "
)
logger.info(f"Loading {solutions_path}")

with open(solutions_path) as in_file:
Expand Down Expand Up @@ -470,9 +470,9 @@

# If not all the treasure could be found. At the moment this function will only
# work if the bandpass solutions were made using the default values.
assert all(
[solution_path.exists() for solution_path in solution_paths]
), f"Missing solution file constructed from scanning {bandpass_directory}. Check the directory. "
assert all([solution_path.exists() for solution_path in solution_paths]), (

Check warning on line 473 in flint/calibrate/aocalibrate.py

View check run for this annotation

Codecov / codecov/patch

flint/calibrate/aocalibrate.py#L473

Added line #L473 was not covered by tests
f"Missing solution file constructed from scanning {bandpass_directory}. Check the directory. "
)

calibrate_cmds = [
CalibrateCommand(
Expand Down Expand Up @@ -556,9 +556,9 @@
else:
unknowns.append((key, value))

assert (
len(unknowns) == 0
), f"Unknown types when generating calibrate command: {unknowns}"
assert len(unknowns) == 0, (
f"Unknown types when generating calibrate command: {unknowns}"
)

cmd += f"{ms_path!s} {solutions_path!s}"

Expand Down Expand Up @@ -670,9 +670,9 @@

assert ms.path.exists(), f"The measurement set {ms} was not found. "
assert ms.column is not None, f"{ms} does not have a nominated data_column. "
assert (
solutions_file.exists()
), f"The solutions file {solutions_file} does not exists. "
assert solutions_file.exists(), (

Check warning on line 673 in flint/calibrate/aocalibrate.py

View check run for this annotation

Codecov / codecov/patch

flint/calibrate/aocalibrate.py#L673

Added line #L673 was not covered by tests
f"The solutions file {solutions_file} does not exists. "
)

input_column = ms.column
copy_mode = "-nocopy" if input_column == output_column else "-copy"
Expand Down Expand Up @@ -714,9 +714,9 @@
"""

assert container.exists(), f"The calibrate container {container} does not exist. "
assert (
calibrate_cmd.ms is not None
), "When calibrating the 'ms' field attribute must be defined. "
assert calibrate_cmd.ms is not None, (

Check warning on line 717 in flint/calibrate/aocalibrate.py

View check run for this annotation

Codecov / codecov/patch

flint/calibrate/aocalibrate.py#L717

Added line #L717 was not covered by tests
"When calibrating the 'ms' field attribute must be defined. "
)

run_singularity_command(
image=container,
Expand All @@ -738,12 +738,12 @@
container (Path): Location of the existing solutions file
"""

assert (
container.exists()
), f"The applysolutions container {container} does not exist. "
assert (
apply_solutions_cmd.ms.path.exists()
), f"The measurement set {apply_solutions_cmd.ms} was not found. "
assert container.exists(), (

Check warning on line 741 in flint/calibrate/aocalibrate.py

View check run for this annotation

Codecov / codecov/patch

flint/calibrate/aocalibrate.py#L741

Added line #L741 was not covered by tests
f"The applysolutions container {container} does not exist. "
)
assert apply_solutions_cmd.ms.path.exists(), (

Check warning on line 744 in flint/calibrate/aocalibrate.py

View check run for this annotation

Codecov / codecov/patch

flint/calibrate/aocalibrate.py#L744

Added line #L744 was not covered by tests
f"The measurement set {apply_solutions_cmd.ms} was not found. "
)

run_singularity_command(
image=container,
Expand Down Expand Up @@ -828,9 +828,9 @@
int: The index of the reference antenna that should be used.
"""

assert (
len(bandpass.shape) == 4
), f"Expected a bandpass of shape (times, ant, channels, pol), received {bandpass.shape=}"
assert len(bandpass.shape) == 4, (
f"Expected a bandpass of shape (times, ant, channels, pol), received {bandpass.shape=}"
)

# create the mask of valid solutions
mask = np.isfinite(bandpass)
Expand Down Expand Up @@ -1019,7 +1019,7 @@

flagged = ~np.isfinite(bandpass[time, ant, :, pol])
logger.info(
f"{ant=:02d}, pol={pols[pol]}, flagged {np.sum(flagged) / ant_gains.shape[0] * 100.:.2f}%"
f"{ant=:02d}, pol={pols[pol]}, flagged {np.sum(flagged) / ant_gains.shape[0] * 100.0:.2f}%"
)

for time in range(solutions.nsol):
Expand Down Expand Up @@ -1070,7 +1070,7 @@
total_flagged = np.sum(~np.isfinite(bandpass)) / np.prod(bandpass.shape)
if total_flagged > 0.8:
msg = (
f"{total_flagged*100.:.2f}% of {(solutions_path)!s} is flagged after running the preflagger. "
f"{total_flagged * 100.0:.2f}% of {(solutions_path)!s} is flagged after running the preflagger. "
"That is over 90%. "
f"This surely can not be correct. Likely something has gone very wrong. "
)
Expand Down
6 changes: 3 additions & 3 deletions flint/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ def download_vizier_catalogue(
logger.info(f"catalogue downloaded, contains {len(tablelist[0])} rows")
logger.info(f"Writing {vizier_id=} to {output_path=}")

assert (
len(tablelist) == 1
), f"Table list for {vizier_id=} has unexpected length of {len(tablelist)}"
assert len(tablelist) == 1, (
f"Table list for {vizier_id=} has unexpected length of {len(tablelist)}"
)

# Note all pirates respect the FITS standard@
if description := tablelist[0].meta.get("description", None):
Expand Down
Loading