Skip to content

Commit

Permalink
Cleaning up dead code (#156)
Browse files Browse the repository at this point in the history
This PR cleans up lots of dead code.
  • Loading branch information
Theodlz authored Oct 1, 2024
1 parent 3612032 commit 8fa5ce0
Show file tree
Hide file tree
Showing 34 changed files with 196 additions and 245 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: '3.12'
cache: 'pip'
cache-dependency-path: setup.py

Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/continous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,34 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.py

- uses: actions/cache@v4
with:
path: |
~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
${{ runner.os }}-pip-
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
python -m pip install --upgrade pip
pip install pytest pytest-runner pytest-rerunfailures coveralls freezegun
pip install -e .
pip install -e ".[test]"
- name: Run tests
run: coverage run -m pytest -v -s
run: |
export NUMBA_DISABLE_JIT=1
python -m coverage run -m pytest -v -s
- name: Run Coveralls
if: ${{ success() }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: '3.12'
cache: 'pip'
cache-dependency-path: setup.py

Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ If you want the latest version, we recommend creating a clean environment:
```commandline
conda create -n gwemopt python=3.11
git clone [email protected]:skyportal/gwemopt.git
pip install -e gwemopt
cd gwemopt
pip install -e .
pre-commit install
```

or if you just want the latest version on Github:
or if you just want the latest version released on PyPI:

```commandline
pip install gwemopt
Expand All @@ -80,7 +81,7 @@ conda install -c astropy astroquery
conda install -c conda-forge voeventlib astropy-healpix python-ligo-lw ligo-segments ligo.skymap ffmpeg
```

And then run `pip install -e gwemopt` again.
And then run `pip install -e .` again.

# Usage

Expand All @@ -91,3 +92,17 @@ gwemopt-run ....
```

where ... corresponds to the various arguments.

# Tests

To run the tests, you'll first need to install gwemopt with the testing dependencies:

```commandline
pip install -e ".[test]"
```

Then you can run the tests using:

```commandline
coverage run -m pytest -v -s
```
2 changes: 0 additions & 2 deletions gwemopt/catalogs/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import healpy as hp
import numpy as np
from astropy.table import Table
from astroquery.vizier import Vizier
from ligo.skymap import distance
from ligo.skymap.bayestar import derasterize
from scipy.stats import norm

Expand Down
1 change: 0 additions & 1 deletion gwemopt/catalogs/mangrove.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import subprocess
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down
1 change: 0 additions & 1 deletion gwemopt/catalogs/nedlvs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import subprocess
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions gwemopt/catalogs/twomrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from astropy import units as u
from astropy.cosmology import WMAP9 as cosmo
from astropy.io.misc.hdf5 import read_table_hdf5, write_table_hdf5
from astropy.table import Table
from astroquery.vizier import Vizier
from scipy.special import gammaincinv

Expand Down
11 changes: 2 additions & 9 deletions gwemopt/chipgaps/decam.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
This module contains the DECamtile class, which is used to calculate decam chip gaps
"""

from array import array

import astropy
import healpy as hp
import numpy as np
from astropy import units as u
from astropy.coordinates import ICRS, SkyCoord
from astropy.wcs import WCS
from mocpy import MOC, mocpy
from mocpy import MOC
from tqdm import tqdm


Expand Down Expand Up @@ -176,7 +173,6 @@ def get_decam_ccds(ra, dec, save_footprint=False):
# ccd_prob = CCDProb(ra, dec)
decam_tile = DECamtile(ra, dec)
ccd_cents_ra = decam_tile.ccd_RA
ccd_cents_dec = decam_tile.ccd_Dec
offsets = np.asarray(
[
decam_tile._wcs[ccd_id].calc_footprint(axes=decam_tile.ccd_size)
Expand Down Expand Up @@ -229,10 +225,7 @@ def get_decam_quadrant_moc(ra, dec, n_threads=None):
stacked = np.stack((ccd_coords.ra.deg, ccd_coords.dec.deg), axis=1)
result = stacked.reshape(-1, ccd_coords.ra.deg.shape[1])
lon_lat_list = [row for row in result]
moc = sum(
MOC.from_polygons(lon_lat_list, max_depth=np.uint8(10), n_threads=n_threads)
)
mocs.append(moc)
mocs.append(sum(MOC.from_polygons(lon_lat_list, False, 10, n_threads)))

return mocs

Expand Down
6 changes: 1 addition & 5 deletions gwemopt/chipgaps/ztf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import astropy
import healpy as hp
import numpy as np
from astropy import units as u
from astropy.coordinates import ICRS, SkyCoord
Expand Down Expand Up @@ -290,9 +289,6 @@ def get_ztf_quadrant_moc(ra, dec, n_threads=None):
stacked = np.stack((ccd_coords.ra.deg, ccd_coords.dec.deg), axis=1)
result = stacked.reshape(-1, ccd_coords.ra.deg.shape[1])
lon_lat_list = [row for row in result]
moc = sum(
MOC.from_polygons(lon_lat_list, max_depth=np.uint8(10), n_threads=n_threads)
)
mocs.append(moc)
mocs.append(sum(MOC.from_polygons(lon_lat_list, False, 10, n_threads)))

return mocs
25 changes: 8 additions & 17 deletions gwemopt/coverage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import copy

import ligo.segments as segments
import numpy as np
import regions
from astropy import units as u
from astropy.coordinates import SkyCoord, get_sun
from astropy.time import Time
from mocpy import MOC
from tqdm import tqdm

import gwemopt.plotting
import gwemopt.scheduler
Expand All @@ -16,7 +14,6 @@
from gwemopt.tiles import (
balance_tiles,
check_overlapping_tiles,
eject_tiles,
optimize_max_tiles,
order_by_observability,
slice_galaxy_tiles,
Expand Down Expand Up @@ -60,7 +57,6 @@ def combine_coverage_structs(coverage_structs):


def read_coverage(params, telescope, filename, moc_struct=None):
nside = params["nside"]
config_struct = params["config"][telescope]
schedule_table = read_schedule(filename)

Expand All @@ -69,7 +65,7 @@ def read_coverage(params, telescope, filename, moc_struct=None):
coverage_struct["filters"] = []
coverage_struct["moc"] = []

for ii, row in schedule_table.iterrows():
for _, row in schedule_table.iterrows():
ra, dec = row["ra"], row["dec"]
tobs = row["tobs"]
limmag = row["limmag"]
Expand Down Expand Up @@ -139,10 +135,9 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):
map_struct_hold = copy.deepcopy(map_struct)

coverage_structs = []
n_scope = 0
full_prob_map = map_struct["skymap"]

for jj, telescope in enumerate(params["telescopes"]):
for telescope in params["telescopes"]:
config_struct = params["config"][telescope]
tile_struct = tile_structs[telescope]

Expand All @@ -167,7 +162,7 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):
params_hold = copy.copy(params)
config_struct_hold = copy.copy(config_struct)

coverage_struct, tile_struct = gwemopt.scheduler.schedule_alternating(
coverage_struct, tile_struct = gwemopt.tiles.schedule_alternating(
params_hold,
config_struct_hold,
telescope,
Expand Down Expand Up @@ -196,24 +191,22 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):
(
coverage_struct,
tile_struct,
) = gwemopt.scheduler.schedule_alternating(
) = gwemopt.tiles.schedule_alternating(
params_hold,
config_struct_hold,
telescope,
map_struct_hold,
tile_struct,
previous_coverage_struct,
)
doReschedule, balanced_fields = balance_tiles(
params_hold, tile_struct, coverage_struct
)
doReschedule, _ = balance_tiles(params_hold, coverage_struct)

if doReschedule:
config_struct_hold = copy.copy(config_struct)
(
coverage_struct,
tile_struct,
) = gwemopt.scheduler.schedule_alternating(
) = gwemopt.tiles.schedule_alternating(
params_hold,
config_struct_hold,
telescope,
Expand Down Expand Up @@ -334,9 +327,7 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):
if params["doBalanceExposure"]:
cnt, ntrials = 0, 10
while cnt < ntrials:
doReschedule, balanced_fields = balance_tiles(
params, tile_struct, coverage_struct
)
doReschedule, _ = balance_tiles(params, coverage_struct)
if doReschedule:
for key in params["unbalanced_tiles"]:
tile_struct[key]["prob"] = 0.0
Expand All @@ -351,7 +342,7 @@ def powerlaw(params, map_struct, tile_structs, previous_coverage_struct=None):

if params["max_nb_tiles"] is not None:
tile_struct, doReschedule = slice_number_tiles(
params, telescope, tile_struct, coverage_struct
params, tile_struct, coverage_struct
)
if doReschedule:
coverage_struct = gwemopt.scheduler.scheduler(
Expand Down
14 changes: 3 additions & 11 deletions gwemopt/efficiency.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import scipy.stats
from astropy.coordinates import SkyCoord
from astropy.time import Time
from ligo.skymap import distance
from scipy.interpolate import interp1d

from gwemopt.io.export_efficiency import (
Expand Down Expand Up @@ -94,9 +93,7 @@ def compute_efficiency(params, map_struct, lightcurve_struct, coverage_struct):
efficiency_struct["dists_inj"] = dists_inj

if params["true_location"]:
det = compute_true_efficiency(
params, map_struct, lightcurve_struct, coverage_struct
)
det = compute_true_efficiency(params, lightcurve_struct, coverage_struct)

lc_name = lightcurve_struct["name"]
save_detection_nondetection(
Expand All @@ -108,10 +105,7 @@ def compute_efficiency(params, map_struct, lightcurve_struct, coverage_struct):
return efficiency_struct


def compute_true_efficiency(params, map_struct, lightcurve_struct, coverage_struct):
nside = params["nside"]
npix = hp.nside2npix(nside)
Ninj = params["Ninj"]
def compute_true_efficiency(params, lightcurve_struct, coverage_struct):
gpstime = params["gpstime"]
mjd_inj = Time(gpstime, format="gps", scale="utc").mjd

Expand All @@ -133,9 +127,7 @@ def compute_true_efficiency(params, map_struct, lightcurve_struct, coverage_stru
lightcurve_mag = lightcurve_struct[filt]
idx = np.where(np.isfinite(lightcurve_mag))[0]

f = interp.interp1d(
lightcurve_t[idx], lightcurve_mag[idx], fill_value="extrapolate"
)
f = interp1d(lightcurve_t[idx], lightcurve_mag[idx], fill_value="extrapolate")
lightcurve_mag_interp = f(mjd)
dist_threshold = (10 ** (((mag - lightcurve_mag_interp) / 5.0) + 1.0)) / 1e6

Expand Down
9 changes: 3 additions & 6 deletions gwemopt/io/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def read_schedule(schedule_path):
return schedule


def export_schedule_xml(xmlfile, map_struct, coverage_struct, config_struct):
def export_schedule_xml(xmlfile, coverage_struct, config_struct):
what = What()

table = Table(name="data", Description=["The datas of GWAlert"])
Expand Down Expand Up @@ -157,9 +157,8 @@ def export_schedule_xml(xmlfile, map_struct, coverage_struct, config_struct):
data = coverage_struct["data"][ii, :]

ra, dec = data[0], data[1]
observ_time, exposure_time, field_id, prob, airmass = (
observ_time, field_id, prob, airmass = (
data[2],
data[4],
data[5],
data[6],
data[7],
Expand Down Expand Up @@ -195,15 +194,14 @@ def export_schedule_xml(xmlfile, map_struct, coverage_struct, config_struct):


def summary(params, map_struct, coverage_struct, catalog_struct=None):

filts = list(set(coverage_struct["filters"]))
for jj, telescope in enumerate(params["telescopes"]):
schedulefile = params["outputDir"].joinpath(f"schedule_{telescope}.dat")
schedulexmlfile = params["outputDir"].joinpath(f"schedule_{telescope}.xml")

config_struct = params["config"][telescope]

export_schedule_xml(schedulexmlfile, map_struct, coverage_struct, config_struct)
export_schedule_xml(schedulexmlfile, coverage_struct, config_struct)

if (params["tilesType"] == "hierarchical") or (params["tilesType"] == "greedy"):
fields = np.zeros((params["Ntiles"][jj], len(filts) + 2))
Expand Down Expand Up @@ -294,7 +292,6 @@ def summary(params, map_struct, coverage_struct, catalog_struct=None):
for tt in tts:
mjds_floor = []
mjds = []
ipixs = np.empty((0, 2))
cum_prob = 0.0
cum_area = 0.0

Expand Down
Loading

0 comments on commit 8fa5ce0

Please sign in to comment.