Skip to content

Commit

Permalink
Tidy up of unused imports (#5002)
Browse files Browse the repository at this point in the history
* all_sky_search unused imports

* bank unused imports

* hwinj unused imports

* live and minifollowups unused imports

* population unused imports

* workflo/workflow_comparison unused imports

* docs and examples

* inference unused imports

* plotting unused imports

* codes in bin

* pygrb

* pycbc modules and a couple of missed bins

* Fix unused imports in tests, add CI workflow to run tests

* Update .github/workflows/check_code.yml

Co-authored-by: Tito Dal Canton <[email protected]>

* typo

* Test GPT-fixed action definer

* re-add removed import

* revert to original

---------

Co-authored-by: Tito Dal Canton <[email protected]>
  • Loading branch information
GarethCabournDavies and titodalcanton authored Jan 9, 2025
1 parent 1e5f12f commit 0695e8d
Show file tree
Hide file tree
Showing 134 changed files with 105 additions and 282 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/check_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Flake8 check
on: [pull_request]
jobs:
flake8_unused_imports:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install flake8
run: pip install flake8
- name: Checking executables for unused imports
run: flake8 --select=F401 $(find bin -type f -name pycbc_*)
- name: Checking modules for unused imports
run: |
flake8 --select=F401 $(find pycbc | grep '\.py$' | grep -v -e __init__ -e 'version.py')
- name: Checking tests for unused imports
run: |
flake8 --select=F401 $(find test | grep '\.py$' | grep -v test_schemes)
5 changes: 2 additions & 3 deletions bin/all_sky_search/pycbc_add_statmap
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
with more than one ifo combination available. Cluster to keep foreground
coincs with the highest stat value.
"""
import igwn_segments as segments
import numpy as np, argparse, logging, pycbc, pycbc.events, pycbc.io
import igwn_segments as segments
import pycbc.version
import pycbc.conversions as conv
from pycbc.events import coinc, significance
import sys, copy
from pycbc.events import significance

def get_ifo_string(fi):
# Returns a string of a space-separated list of ifos from input file.
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_apply_rerank
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Rewrite statmap file and rerank candidates using the statistic values
generated from the followup of candidates.
"""
import numpy, argparse, logging, pycbc
import numpy, argparse, pycbc
from pycbc.io import HFile
from pycbc.conversions import sec_to_year
from pycbc.events import significance
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_coinc_findtrigs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import copy, argparse, logging, numpy, numpy.random
import shutil, uuid, os.path, atexit
from igwn_segments import infinity
import pycbc
from pycbc.events import veto, coinc, stat, ranking, cuts
from pycbc.events import veto, coinc, stat, cuts
from pycbc.io import HFile
from pycbc import pool, init_logging
from numpy.random import seed, shuffle
Expand Down
4 changes: 2 additions & 2 deletions bin/all_sky_search/pycbc_coinc_statmap
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ the capability of doing hierarchical removal of foreground triggers that are
louder than all of the background triggers. We use this to properly assess
the FANs of any other gravitational waves in the dataset.
"""
import argparse, itertools
import lal, logging, numpy
import argparse
import logging, numpy
from pycbc.events import veto, coinc, significance
import pycbc.pnutils, pycbc.io
import sys
Expand Down
4 changes: 2 additions & 2 deletions bin/all_sky_search/pycbc_coinc_statmap_inj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ The program combines coincident output files generated
by pycbc_coinc_findtrigs to generated a mapping between SNR and FAP, along
with producing the combined foreground and background triggers
"""
import argparse, logging, itertools, copy, pycbc.io, numpy, lal
from pycbc.events import veto, coinc, significance
import argparse, logging, pycbc.io, numpy
from pycbc.events import significance
import pycbc.conversions as conv
from pycbc import init_logging

Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_combine_coincident_events
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The resulting file would contain triggers from the full set of input files
"""
import numpy
import argparse
import logging

import pycbc
from pycbc.io import HFile
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_combine_statmap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ combinations at the time of coincidence. This clusters to find the most
significant foreground, but leaves the background triggers alone.
"""

import numpy, argparse, logging, pycbc, pycbc.events, pycbc.io, lal
import numpy, argparse, logging, pycbc, pycbc.events, pycbc.io
import igwn_segments as segments

parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_exclude_zerolag
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ coincidences from *any* coincidence type with ifar above a certain threshold
"""

import numpy as np, argparse, logging, pycbc, pycbc.io
from pycbc.events import veto, coinc, significance
from pycbc.events import veto, significance
import pycbc.conversions as conv

parser = argparse.ArgumentParser()
Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_fit_sngls_by_template
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# Public License for more details.


import sys, h5py
import argparse, logging

import copy, numpy as np
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_fit_sngls_over_multiparam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Public License for more details.


import sys, argparse, logging, numpy
import argparse, logging, numpy
from scipy.stats import norm

import pycbc
Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_fit_sngls_over_param
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# Public License for more details.


import sys
import argparse, logging

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_get_loudest_params
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Finds the loudest snr or newsnr event within a given time window, parses the
parameters of the template, and writes them to an hdf and/or stdout.
"""

import lal
import numpy as np
import argparse
import logging
Expand Down
3 changes: 0 additions & 3 deletions bin/all_sky_search/pycbc_make_bayestar_skymap
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ import shutil
import logging
import os
import glob
import sys
import random
import tempfile

from ligo.lw import lsctables, utils as ligolw_utils

import pycbc
from pycbc import init_logging
from pycbc.waveform import bank as wavebank
from pycbc.io import WaveformArray
from pycbc.io.ligolw import LIGOLWContentHandler
Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_plot_kde_vals
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from pycbc import init_logging, add_common_pycbc_options
from pycbc.io import HFile
import logging

parser = argparse.ArgumentParser(description=__doc__)
add_common_pycbc_options(parser)
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_prepare_xml_for_gracedb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from pycbc.io.ligolw import (
snr_series_to_xml,
)
from pycbc.psd import interpolate
from pycbc.types import FrequencySeries, TimeSeries, load_timeseries
from pycbc.types import FrequencySeries, load_timeseries
from pycbc.types import MultiDetOptionAction
from pycbc.results import generate_asd_plot, generate_snr_plot

Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_reduce_template_bank
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Reduce a template bank using some input parameter cuts
"""


import numpy
import logging
import argparse
import pycbc
Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_rerank_passthrough
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/env python
"""Dummy script to pass through stat files and test reranking"""
import numpy, argparse, logging, pycbc
import argparse, logging, pycbc
from pycbc.io import HFile

parser = argparse.ArgumentParser()
Expand Down
7 changes: 2 additions & 5 deletions bin/all_sky_search/pycbc_sngls_findtrigs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/env python
import argparse, logging, h5py, numpy as np
from igwn_segments import infinity
import argparse, logging, numpy as np
from numpy.random import seed, shuffle

import pycbc
from pycbc.events import veto, coinc, stat
import pycbc.conversions as conv
from pycbc import io
from pycbc.events import cuts, trigger_fits as trfits
from pycbc.events.veto import indices_outside_times
from pycbc.events import cuts
from pycbc.types.optparse import MultiDetOptionAction
from pycbc import init_logging

Expand Down
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_sngls_pastro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import pycbc, pycbc.io, copy
import argparse, logging, numpy as np
from ligo.lw import lsctables, utils as ligolw_utils
from pycbc import conversions as conv
from pycbc.events import veto, stat, ranking, coinc, single as sngl
from pycbc.events import veto
from pycbc.io.ligolw import LIGOLWContentHandler
from igwn_segments import segment, segmentlist
import matplotlib
Expand Down
6 changes: 2 additions & 4 deletions bin/all_sky_search/pycbc_sngls_statmap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ by pycbc_sngls_findtrigs to generate a mapping between SNR and FAP/FAR, along
with producing the combined foreground and background triggers.
"""

import argparse, itertools
import argparse
import logging, numpy, copy
from pycbc.events import veto, coinc
from pycbc.events import triggers, trigger_fits as trstats
from pycbc.events import veto
from pycbc.events import significance
import pycbc.pnutils, pycbc.io
import sys
import pycbc.conversions as conv

class fw(object):
Expand Down
7 changes: 2 additions & 5 deletions bin/all_sky_search/pycbc_sngls_statmap_inj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ by pycbc_sngls_findtrigs to generate a mapping between SNR and FAP/FAR, along
with producing the combined foreground and background triggers.
"""

import argparse, itertools
import lal, logging, numpy
from pycbc.events import veto, coinc
from pycbc.events import triggers, trigger_fits as trstats
import argparse
import logging, numpy
from pycbc.events import significance
import pycbc.pnutils, pycbc.io
import sys
import pycbc.conversions as conv

class fw(object):
Expand Down
1 change: 0 additions & 1 deletion bin/all_sky_search/pycbc_template_kde_calc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import numpy, operator, argparse, logging
from pycbc import init_logging, add_common_pycbc_options
import pycbc.conversions as convert
from pycbc import libutils
from pycbc.events import triggers
from pycbc.io import HFile
Expand Down
2 changes: 0 additions & 2 deletions bin/all_sky_search/pycbc_upload_single_event_to_gracedb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import sys
import argparse
import logging
from ligo.gracedb.rest import GraceDb
import numpy as np

import pycbc
import lal
from pycbc.io.gracedb import gracedb_tag_with_version

parser = argparse.ArgumentParser(description=__doc__)
Expand Down
1 change: 0 additions & 1 deletion bin/bank/pycbc_aligned_bank_cat
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import pycbc
import pycbc.psd
import pycbc.strain
import pycbc.version
from pycbc.waveform import get_waveform_filter_length_in_time
from pycbc.io.ligolw import LIGOLWContentHandler
from pycbc.io.hdf import HFile

Expand Down
1 change: 0 additions & 1 deletion bin/bank/pycbc_brute_bank
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import numpy
import logging
import argparse
import pickle
import numpy.random
from scipy.stats import gaussian_kde

Expand Down
1 change: 0 additions & 1 deletion bin/bank/pycbc_coinc_bank2hdf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with their template.
"""
import argparse
import logging
import numpy

import pycbc
from pycbc.waveform import bank
Expand Down
1 change: 0 additions & 1 deletion bin/bank/pycbc_geom_aligned_bank
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import pycbc.strain
import pycbc.version
import pycbc.tmpltbank
import pycbc.workflow as wf
import pycbc.workflow.pegasus_workflow as pwf
from pycbc.workflow import WorkflowConfigParser
from pycbc.workflow.core import resolve_url_to_file
from pycbc.io.ligolw import create_process_table
Expand Down
5 changes: 2 additions & 3 deletions bin/hwinj/pycbc_generate_hwinj
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ from pycbc.detector import Detector
from pycbc.inject import InjectionSet, legacy_approximant_name
from pycbc.filter import make_frequency_series
from pycbc.filter import sigmasq
from pycbc.types import Array, FrequencySeries, TimeSeries, zeros
from pycbc.types.optparse import MultiDetOptionAppendAction
from pycbc.types import TimeSeries
from pycbc.types.optparse import convert_to_process_params_dict
from pycbc.io.ligolw import create_process_table
from pycbc.waveform import FilterBank, get_td_waveform, td_approximants, taper_timeseries
from pycbc.waveform import get_td_waveform, td_approximants, taper_timeseries

def _empty_row(obj):
"""Create an empty sim_inspiral or sngl_inspiral row where the columns have
Expand Down
1 change: 0 additions & 1 deletion bin/hwinj/pycbc_plot_hwinj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import logging
import matplotlib as mpl; mpl.use("Agg")
import matplotlib.pyplot as plt
import numpy
import sys

from pycbc import add_common_pycbc_options, init_logging

Expand Down
7 changes: 2 additions & 5 deletions bin/inference/pycbc_inference
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ import os
import sys
import argparse
import logging
import shutil

import numpy

import pycbc
from pycbc import (distributions, transforms, fft,
opt, scheme, pool)
from pycbc.waveform import generator
from pycbc import fft, opt, scheme, pool

from pycbc import inference
from pycbc.inference import (models, burn_in, option_utils)
from pycbc.inference import models
from pycbc.inference.io import loadfile
from pycbc.workflow import configuration

Expand Down
2 changes: 0 additions & 2 deletions bin/inference/pycbc_inference_extract_samples
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ across combined files.
"""

import os
import argparse
import logging
import numpy
import pycbc
from pycbc.inference.io import (ResultsArgumentParser, results_from_cli,
Expand Down
1 change: 0 additions & 1 deletion bin/inference/pycbc_inference_model_stats
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import os
import argparse
import shutil
import logging
import time
import numpy
import tqdm

Expand Down
1 change: 0 additions & 1 deletion bin/inference/pycbc_inference_plot_acceptance_rate
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import logging
from matplotlib import use
use('agg')
import matplotlib.pyplot as plt
import numpy
import pycbc
from pycbc import results
from pycbc.inference import io
Expand Down
2 changes: 0 additions & 2 deletions bin/inference/pycbc_inference_plot_acf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import argparse
import logging
import sys

Expand All @@ -29,7 +28,6 @@ import pycbc
from pycbc import results
from pycbc.inference import io

from pycbc.inference import option_utils
from pycbc.inference.sampler import samplers

# command line usage
Expand Down
1 change: 0 additions & 1 deletion bin/inference/pycbc_inference_plot_acl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import argparse
import logging
import sys

Expand Down
Loading

0 comments on commit 0695e8d

Please sign in to comment.