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

[pre-commit.ci] pre-commit autoupdate #81

Merged
merged 2 commits into from
Jan 28, 2025
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.3
rev: v0.9.3
hooks:
# Run the linter.
- id: ruff
Expand Down
18 changes: 9 additions & 9 deletions arrakis/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def merge_imagesets(image_sets: List[Optional[ImageSet]]) -> ImageSet:
prefix = image_sets[0].prefix

for image_set in image_sets:
assert (
image_set.ms.name == ms.name
), f"{image_set.ms.name=} does not match {ms.name=}"
assert (
image_set.prefix == prefix
), f"{image_set.prefix=} does not match {prefix=}"
assert image_set.ms.name == ms.name, (
f"{image_set.ms.name=} does not match {ms.name=}"
)
assert image_set.prefix == prefix, (
f"{image_set.prefix=} does not match {prefix=}"
)

image_lists = {}
aux_lists = {}
Expand Down Expand Up @@ -936,9 +936,9 @@ def main(
logger.info(f"Searching {msdir} for MS matching {ms_glob_pattern}.")
mslist = sorted(msdir.glob(ms_glob_pattern))

assert (
(len(mslist) > 0) & (len(mslist) == num_beams)
), f"Incorrect number of MS files found: {len(mslist)} / {num_beams} - glob pattern: {ms_glob_pattern}"
assert (len(mslist) > 0) & (len(mslist) == num_beams), (
f"Incorrect number of MS files found: {len(mslist)} / {num_beams} - glob pattern: {ms_glob_pattern}"
)

logger.info(f"Will image {len(mslist)} MS files in {msdir} to {out_dir}")
cleans = []
Expand Down
22 changes: 11 additions & 11 deletions arrakis/linmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def find_images(
image_list: List[Path] = []
for bm in list(set(field_beams["beam_list"])): # Ensure list of beams is unique!
imfile = Path(field_beams[f"{stoke.lower()}_beam{bm}_image_file"])
assert (
imfile.parent.name == src_name
), f"Looking in wrong directory! '{imfile.parent.name}'"
assert imfile.parent.name == src_name, (
f"Looking in wrong directory! '{imfile.parent.name}'"
)
new_imfile = datadir.resolve() / imfile
image_list.append(new_imfile)
image_list = sorted(image_list)
Expand All @@ -92,19 +92,19 @@ def find_images(
weight_list: List[Path] = []
for bm in list(set(field_beams["beam_list"])): # Ensure list of beams is unique!
wgtsfile = Path(field_beams[f"{stoke.lower()}_beam{bm}_weight_file"])
assert (
wgtsfile.parent.name == src_name
), f"Looking in wrong directory! '{wgtsfile.parent.name}'"
assert wgtsfile.parent.name == src_name, (
f"Looking in wrong directory! '{wgtsfile.parent.name}'"
)
new_wgtsfile = datadir.resolve() / wgtsfile
weight_list.append(new_wgtsfile)
weight_list = sorted(weight_list)

assert len(image_list) == len(weight_list), "Unequal number of weights and images"

for im, wt in zip(image_list, weight_list):
assert (
im.parent.name == wt.parent.name
), "Image and weight are in different areas!"
assert im.parent.name == wt.parent.name, (
"Image and weight are in different areas!"
)

return ImagePaths(image_list, weight_list)

Expand Down Expand Up @@ -185,8 +185,8 @@ def genparset(

first_image = image_paths.images[0].resolve().with_suffix("").as_posix()
first_weight = image_paths.weights[0].resolve().with_suffix("").as_posix()
linmos_image_str = f"{first_image[:first_image.find('beam')]}linmos"
linmos_weight_str = f"{first_weight[:first_weight.find('beam')]}linmos"
linmos_image_str = f"{first_image[: first_image.find('beam')]}linmos"
linmos_weight_str = f"{first_weight[: first_weight.find('beam')]}linmos"

parset_file = os.path.join(parset_dir, f"linmos_{stoke}.in")
parset = f"""linmos.names = {image_string}
Expand Down
14 changes: 7 additions & 7 deletions arrakis/makecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ def is_blended_component(sub_df: pd.DataFrame) -> pd.DataFrame:
)
# Sanity check - no single-component sources should be flagged
assert np.array_equal(is_blended.index.values, cat["cat_id"].data), "Index mismatch"
assert not any(
cat["is_blended_flag"] & (cat["N_Gaus"] == 1)
), "Single-component sources cannot be flagged as blended."
assert not any(cat["is_blended_flag"] & (cat["N_Gaus"] == 1)), (
"Single-component sources cannot be flagged as blended."
)
if "index" in cat.colnames:
cat.remove_column("index")
return cat
Expand Down Expand Up @@ -507,7 +507,7 @@ def sn_func(index, signal=None, noise=None):
if "Not enough S/N in the whole set of pixels." not in str(e):
raise e
logger.warning(
f"Failed with target number of RMs per bin of {target_sn}. Trying again with {target_sn-10}"
f"Failed with target number of RMs per bin of {target_sn}. Trying again with {target_sn - 10}"
)
target_sn -= 10
else:
Expand Down Expand Up @@ -943,7 +943,7 @@ def main(
query = {"$and": [{f"beams.{field}": {"$exists": True}}]}
all_island_ids = sorted(beams_col.distinct("Source_ID", query))
tock = time.time()
logger.info(f"Finished beams collection query - {tock-tick:.2f}s")
logger.info(f"Finished beams collection query - {tock - tick:.2f}s")

logger.info("Starting component collection query")
tick = time.time()
Expand Down Expand Up @@ -1023,15 +1023,15 @@ def main(
# )
comps_df.set_index("Source_ID", inplace=True)
tock = time.time()
logger.info(f"Finished component collection query - {tock-tick:.2f}s")
logger.info(f"Finished component collection query - {tock - tick:.2f}s")
logger.info(f"Found {len(comps_df)} components to catalogue. ")

logger.info("Starting island collection query")
tick = time.time()
islands_df = pd.DataFrame(island_col.find({"Source_ID": {"$in": all_island_ids}}))
islands_df.set_index("Source_ID", inplace=True)
tock = time.time()
logger.info(f"Finished island collection query - {tock-tick:.2f}s")
logger.info(f"Finished island collection query - {tock - tick:.2f}s")

if len(comps_df) == 0:
logger.error("No components found for this field.")
Expand Down
8 changes: 4 additions & 4 deletions arrakis/merge_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def genparset(
new_dir: str,
) -> str:
imlist = "[" + ",".join([im.replace(".fits", "") for im in old_ims]) + "]"
weightlist = f"[{','.join([im.replace('.fits', '').replace('.image.restored.','.weights.').replace('.ion','') for im in old_ims])}]"
weightlist = f"[{','.join([im.replace('.fits', '').replace('.image.restored.', '.weights.').replace('.ion', '') for im in old_ims])}]"

im_outname = os.path.join(new_dir, os.path.basename(old_ims[0])).replace(
".fits", ".edge.linmos"
Expand Down Expand Up @@ -288,9 +288,9 @@ def main(
) -> str:
logger.debug(f"{fields=}")

assert (
len(fields) == len(field_dirs)
), f"List of fields must be the same length as length of field dirs. {len(fields)=},{len(field_dirs)=}"
assert len(fields) == len(field_dirs), (
f"List of fields must be the same length as length of field dirs. {len(fields)=},{len(field_dirs)=}"
)

field_dict = {
field: os.path.join(field_dir, "cutouts")
Expand Down
12 changes: 6 additions & 6 deletions arrakis/rmclean_oncuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def rmclean1d(
logger.debug(f"Working on {comp}")
save_name = field if sbid is None else f"{field}_{sbid}"

assert (
comp["rm_outputs_1d"]["field"] == save_name
), f"Field mismatch - expected {save_name} got {comp['rm_outputs_1d']['field']}"
assert comp["rm_outputs_1d"]["field"] == save_name, (
f"Field mismatch - expected {save_name} got {comp['rm_outputs_1d']['field']}"
)

rm1dfiles = comp["rm_outputs_1d"]["rm1dfiles"]
fdfFile = outdir / f"{rm1dfiles['FDF_dirty']}"
Expand Down Expand Up @@ -175,9 +175,9 @@ def rmclean3d(
prefix = f"{iname}_"
rm3dfiles = island["rm_outputs_3d"]["rm3dfiles"]
save_name = field if sbid is None else f"{field}_{sbid}"
assert (
island["rm_outputs_3d"]["field"] == save_name
), f"Field mismatch - expected {save_name} got {island['rm_outputs_3d']['field']}"
assert island["rm_outputs_3d"]["field"] == save_name, (
f"Field mismatch - expected {save_name} got {island['rm_outputs_3d']['field']}"
)

cleanFDF, ccArr, iterCountArr, residFDF, headtemp = do_RMclean_3D.run_rmclean(
fitsFDF=(outdir / rm3dfiles["FDF_real_dirty"]).as_posix(),
Expand Down
8 changes: 4 additions & 4 deletions arrakis/utils/msutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def field_idx_from_ms(ms: str) -> int:
"""Get the field from MS metadata"""
with table(f"{ms}/FIELD", readonly=True, ack=False) as field:
idxs = list(field.SOURCE_ID)
assert len(idxs) == 1 or all(
[idx == idxs[0] for idx in idxs]
), "More than one field in MS"
assert len(idxs) == 1 or all([idx == idxs[0] for idx in idxs]), (
"More than one field in MS"
)
idx = idxs[0]
return idx

Expand Down Expand Up @@ -766,6 +766,6 @@ def wsclean(
elif value:
if "ws_" in key: # Catch for ws_continue command
key.replace("ws_", "")
command += f" -{key.replace('_','-')} {value}"
command += f" -{key.replace('_', '-')} {value}"
command += f" {' '.join(mslist)}"
return command
6 changes: 3 additions & 3 deletions arrakis/utils/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def upload_image_as_artifact_task(
"""
image_type = image_path.suffix.replace(".", "")
assert image_path.exists(), f"{image_path} does not exist"
assert (
image_type in SUPPORTED_IMAGE_TYPES
), f"{image_path} has type {image_type}, and is not supported. Supported types are {SUPPORTED_IMAGE_TYPES}"
assert image_type in SUPPORTED_IMAGE_TYPES, (
f"{image_path} has type {image_type}, and is not supported. Supported types are {SUPPORTED_IMAGE_TYPES}"
)

with open(image_path, "rb") as open_image:
logger.info(f"Encoding {image_path} in base64")
Expand Down
6 changes: 3 additions & 3 deletions arrakis/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def plot_leakage(
overlay[1].set_axislabel("$b$", color="tab:blue")
fig.colorbar(im, ax=ax, label="Fraction", shrink=0.7, pad=0.15)
ax.set_title(
f"Stokes {stokes}/I (binned) - absmed: {np.nanmedian(np.abs(data))*100:0.1f}$\pm${np.nanstd(np.abs(data))*100:0.1f}%",
f"Stokes {stokes}/I (binned) - absmed: {np.nanmedian(np.abs(data)) * 100:0.1f}$\pm${np.nanstd(np.abs(data)) * 100:0.1f}%",
pad=50,
)

Expand Down Expand Up @@ -384,8 +384,8 @@ def plot_rm(
ax.legend()

ax.set(
xlabel=f"RACS / {u.rad/u.m**2:latex_inline}",
ylabel=f"{label} / {u.rad/u.m**2:latex_inline}",
xlabel=f"RACS / {u.rad / u.m**2:latex_inline}",
ylabel=f"{label} / {u.rad / u.m**2:latex_inline}",
aspect="equal",
)
_ = ax_dict["M"].imshow(
Expand Down
24 changes: 12 additions & 12 deletions scripts/casda_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ def main(
cubes = find_cubes(data_dir=data_dir)
# Check if we have a cube for each source
try:
assert len(cubes) == len(
set(polcat["source_id"])
), "Number of cubes does not match number of sources"
assert len(cubes) == len(set(polcat["source_id"])), (
"Number of cubes does not match number of sources"
)
except AssertionError:
logger.warning(
f"Found {len(cubes)} cubes, expected {len(set(polcat['source_id']))}"
Expand Down Expand Up @@ -566,9 +566,9 @@ def main(
with open(outf, "w") as f:
for rid in rem_ids:
f.write(f"{rid}\n")
assert (
len(cubes) == len(set(polcat["source_id"]))
), f"Number of cubes does not match number of sources -- {len(cubes)=} and {len(set(polcat['source_id']))=}"
assert len(cubes) == len(set(polcat["source_id"])), (
f"Number of cubes does not match number of sources -- {len(cubes)=} and {len(set(polcat['source_id']))=}"
)

unique_ids, unique_idx = np.unique(polcat["source_id"], return_index=True)
lookup = {sid: i for sid, i in zip(unique_ids, unique_idx)}
Expand Down Expand Up @@ -609,9 +609,9 @@ def my_sorter(x, lookup=lookup, pbar=pbar):
cat_ids.append(cat_id)
in_idx = np.isin(cat_ids, polcat["cat_id"])
spectra = list(np.array(spectra)[in_idx])
assert len(spectra) == len(
polcat
), f"{len(spectra)=} and {len(polcat)=}" # Sanity check
assert len(spectra) == len(polcat), (
f"{len(spectra)=} and {len(polcat)=}"
) # Sanity check

unique_ids, unique_idx = np.unique(polcat["cat_id"], return_index=True)
lookup = {sid: i for sid, i in zip(unique_ids, unique_idx)}
Expand Down Expand Up @@ -678,9 +678,9 @@ def my_sorter(x, lookup=lookup, pbar=pbar):
in_idx = np.isin(cat_ids, polcat["cat_id"])
plots = list(np.array(plots)[in_idx])

assert (
len(plots) == len(polcat) * 3
), f"{len(plots)=} and {len(polcat)=}" # Sanity check
assert len(plots) == len(polcat) * 3, (
f"{len(plots)=} and {len(polcat)=}"
) # Sanity check

with tqdm(total=len(plots), desc="Sorting plots", file=TQDM_OUT) as pbar:

Expand Down
2 changes: 1 addition & 1 deletion scripts/compute_leakage.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def main(field, datadir, username="admin", password=None):
ax[0, i].imshow(q, origin="lower", vmin=-lim, vmax=lim, cmap=plt.cm.coolwarm)
ax[0, i].axis("off")
ax[0, i].invert_xaxis()
ax[0, i].set_title(f"{f/1e6:0.1f}MHz")
ax[0, i].set_title(f"{f / 1e6:0.1f}MHz")
ax[1, i].imshow(
u,
origin="lower",
Expand Down
4 changes: 2 additions & 2 deletions scripts/find_sbid.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def main(
if not cal and not science and not weight:
logger.info(f"DB info for RACS_{name}:\n")
for i, row in enumerate(sub_tab):
logger.info(f"{space}CAL SBID {i+1}: {row['CAL_SBID']}")
logger.info(f"{space}Science SBID {i+1}: {row['SBID']}\n")
logger.info(f"{space}CAL SBID {i + 1}: {row['CAL_SBID']}")
logger.info(f"{space}Science SBID {i + 1}: {row['SBID']}\n")


def cli():
Expand Down
Loading