Skip to content

Commit

Permalink
Prune large DECam CCDs PSF params file (#931)
Browse files Browse the repository at this point in the history
Fixes #922.
  • Loading branch information
zhixiangteoh authored Aug 18, 2023
1 parent e3233c5 commit 84afd3a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
3 changes: 3 additions & 0 deletions data/tests/decals/ccds-annotated-decam-dr9-small.fits
Git LFS file not shown
48 changes: 48 additions & 0 deletions scripts/prune_decam_ccds_annotated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import numpy as np
from astropy.io import fits
from astropy.table import Table

# Script to reduce the size of the ccds-annotated-decam file by only keeping fixed CCDs used for
# DECaLS PSF params. Use to regenerate data/tests/decals/ccds-annotated-decam-dr9-small.fits.

with open("/home/zhteoh/bliss/data/decals/ccds-annotated-decam-dr9.fits", "rb") as f:
ccds_annotated_fits = fits.open(f)

ccds_annotated_table = Table.read("/home/zhteoh/bliss/data/decals/ccds-annotated-decam-dr9.fits")

BRICKNAME = "3366m010"
brick_ccds = Table.read(
f"/home/zhteoh/bliss/data/decals/{BRICKNAME[:3]}/{BRICKNAME}/legacysurvey-{BRICKNAME}-ccds.fits"
)
fixed_ccds = brick_ccds[
(
brick_ccds["image_filename"]
== "decam/CP/V4.8.2a/CP20141020/c4d_141021_015854_ooi_g_ls9.fits.fz"
)
| (
brick_ccds["image_filename"]
== "decam/CP/V4.8.2a/CP20151107/c4d_151108_003333_ooi_r_ls9.fits.fz"
)
| (
brick_ccds["image_filename"]
== "decam/CP/V4.8.2a/CP20130912/c4d_130913_040652_ooi_z_ls9.fits.fz"
)
]
keep_ccds = fixed_ccds["ccdname"]

psf_cols = [
col
for col in ccds_annotated_table.colnames
if col.startswith("psf") or col.startswith("gal") or col.startswith("gauss")
]
brick_ccds_mask = np.isin(ccds_annotated_table["ccdname"], keep_ccds)
keep_cols = psf_cols + ["ccdname", "filter"]
ccds_annotated_table_small = ccds_annotated_table[brick_ccds_mask][keep_cols]

# write ccds_annotated_table_small as astropy table to file
save_location = "/home/zhteoh/bliss/data/tests/decals/ccds-annotated-decam-dr9-small.fits"
with open(save_location, "wb") as f:
ccds_annotated_table_small.write(f, format="fits")

# du -sh /home/zhteoh/bliss/data/decals/ccds-annotated-decam-dr9.fits => 3.8G
# du -sh /home/zhteoh/bliss/data/tests/decals/ccds-annotated-decam-dr9-small.fits => 59M
23 changes: 23 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# pylint: skip-file
import os
import shutil
from pathlib import Path

import pytest
Expand Down Expand Up @@ -47,6 +49,27 @@ def cfg(pytestconfig, cached_data_path, output_path):
return the_cfg


@pytest.fixture(scope="session")
def decals_setup_teardown(cfg):
# replace if needed
original_ccds_annotated_path = cfg.paths.decals + "/ccds-annotated-decam-dr9.fits"
temp_ccds_annotated_path = cfg.paths.decals + "/ccds-annotated-decam-dr9-large.fits"
large_file_existed = os.path.exists(original_ccds_annotated_path)
if large_file_existed:
shutil.move(original_ccds_annotated_path, temp_ccds_annotated_path)
shutil.copyfile(
cfg.paths.data + "/tests/decals/ccds-annotated-decam-dr9-small.fits",
original_ccds_annotated_path,
)

yield

# restore
os.remove(original_ccds_annotated_path)
if large_file_existed:
shutil.move(temp_ccds_annotated_path, original_ccds_annotated_path)


@pytest.fixture(scope="session")
def encoder(cfg):
encoder = instantiate(cfg.encoder).to(cfg.predict.device)
Expand Down
4 changes: 0 additions & 4 deletions tests/test_decals.py

This file was deleted.

0 comments on commit 84afd3a

Please sign in to comment.