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

Minimal ruff #457

Merged
merged 4 commits into from
Feb 20, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ hera_qm/data/test_output
hera_qm/GIT_INFO
hera_qm/data/test_output/ant_metrics_output.json
hera_qm/_version.py

artifacts/*
result.md
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-ast
- id: check-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: mixed-line-ending
args: ['--fix=no']


- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.4
hooks:
# Run the linter.
- id: ruff
args: [--fix]
3 changes: 1 addition & 2 deletions hera_qm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019 the HERA Project
# Licensed under the MIT License

Expand Down Expand Up @@ -26,7 +25,7 @@
from . import ant_metrics # noqa
from . import auto_metrics # noqa
from . import firstcal_metrics # noqa
from . import omnical_metrics # noqa
from . import omnical_metrics # noqa
from . import metrics_io # noqa
from . import ant_class # noqa
from . import time_series_metrics # noqa
195 changes: 97 additions & 98 deletions hera_qm/ant_class.py

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions hera_qm/ant_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019 the HERA Project
# Licensed under the MIT License

Expand All @@ -7,7 +6,6 @@
from copy import deepcopy
import os
import shutil
import re
import warnings
from . import __version__
from . import utils, metrics_io
Expand Down Expand Up @@ -67,9 +65,9 @@ def get_ant_metrics_dict():


def calc_corr_stats(data_sum, data_diff=None):
"""For all baselines, calculate average cross-correlation between even and odd in order
"""For all baselines, calculate average cross-correlation between even and odd in order
to identify dead, cross-polarized, and non-time-locked antennas. Time and channels where
either the even or odd data (or both) are zero are ignored, but if either even or odd
either the even or odd data (or both) are zero are ignored, but if either even or odd
is entirely zero, the corr_stat will be np.nan.

Parameters
Expand Down Expand Up @@ -142,7 +140,7 @@ def load_antenna_metrics(filename):
# High level functionality for HERA
#######################################################################

class AntennaMetrics():
class AntennaMetrics:
"""Container for holding data and meta-data for ant metrics calculations.

This class creates an object for holding relevant visibility data and metadata,
Expand Down Expand Up @@ -205,7 +203,7 @@ def __init__(self, sum_files, diff_files=None, apriori_xants=[],
History to append to the metrics files when writing out files.

"""

from hera_cal.io import HERADataFastReader
from hera_cal.utils import split_bl, comply_pol, split_pol, join_pol
# prevents the need for importing again later
Expand Down Expand Up @@ -242,21 +240,21 @@ def __init__(self, sum_files, diff_files=None, apriori_xants=[],
assert len(self.bls) > 0, 'Make sure we have data'

# Figure out polarizations in the data
self.pols = set([bl[2] for bl in self.bls])
self.pols = {bl[2] for bl in self.bls}
self.cross_pols = [pol for pol in self.pols if split_pol(pol)[0] != split_pol(pol)[1]]
self.same_pols = [pol for pol in self.pols if split_pol(pol)[0] == split_pol(pol)[1]]

# Figure out which antennas are in the data
self.ants = sorted(set([ant for bl in self.bls for ant in split_bl(bl)]))
self.antnums = sorted(set([ant[0] for ant in self.ants]))
self.antpols = sorted(set([ant[1] for ant in self.ants]))
self.ants = sorted({ant for bl in self.bls for ant in split_bl(bl)})
self.antnums = sorted({ant[0] for ant in self.ants})
self.antpols = sorted({ant[1] for ant in self.ants})
self.ants_per_antpol = {antpol: sorted([ant for ant in self.ants if ant[1] == antpol]) for antpol in self.antpols}

# Parse apriori_xants
self.apriori_xants = set()
for ant in apriori_xants:
if isinstance(ant, int):
self.apriori_xants.update(set((ant, ap) for ap in self.antpols))
self.apriori_xants.update({(ant, ap) for ap in self.antpols})
elif isinstance(ant, tuple):
assert len(ant) == 2
ap = comply_pol(ant[1])
Expand Down Expand Up @@ -366,7 +364,7 @@ def _corr_cross_pol_metrics_per_ant(self):
cross_pol_metrics = np.nanmax(np.nanmean(matrix_pol_diffs, axis=1), axis=0)

per_ant_corr_cross_pol_metrics = {}
for _, ants in self.ants_per_antpol.items():
for ants in self.ants_per_antpol.values():
per_ant_corr_cross_pol_metrics.update(dict(zip(ants, cross_pol_metrics)))
return per_ant_corr_cross_pol_metrics

Expand All @@ -380,7 +378,7 @@ def _run_all_metrics(self):
}
for name, metric in metrics.items():
noninf_metric = {k:v for k, v in metric.items() if np.isfinite(v)}
if not name in self.final_metrics:
if name not in self.final_metrics:
self.final_metrics[name] = {}
self.final_metrics[name].update(noninf_metric)
self.all_metrics.update({self.iter: metrics})
Expand Down Expand Up @@ -427,7 +425,7 @@ def iterative_antenna_metrics_and_flagging(self, crossCut=0, deadCut=0.4, verbos
if verbose:
print(f'On iteration {iteration} we flag {crossed_ant} with cross-pol corr metric of {crossMetrics[worstCrossAnt]}.')
elif (worstDeadCutDiff < worstCrossCutDiff) and (worstDeadCutDiff < 0):
dead_ants = set([worstDeadAnt])
dead_ants = {worstDeadAnt}
for dead_ant in dead_ants:
self.xants[dead_ant] = iteration
self.dead_ants.append(dead_ant)
Expand Down
Loading
Loading