Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
14 changes: 11 additions & 3 deletions docs/source/pipeline_canfar.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,11 @@ Now, create the list of CCDs that have PSF information with
get_ccds_with_psf -v -V v1.6
```

Next, download exposures headers
Next, download exposures headers; indicate (with `-d`) a directory of already
downloaded headers; those will be linked and duplicated download skipped.

```bash
download_headers -i ccds_with_psfs_v1.6.txt -o headers_v1.6 -v
download_headers -i ccds_with_psfs_v1.6.txt -o headers_v1.6 -d headers_v1.3 -v
```

From the headers, the CCD corner coordinates are extracted with
Expand All @@ -504,11 +505,18 @@ extract_field_corners -i headers_v1.6 -v

Then, build the healsparse coverage mask file as
```bash
build_coverage_map
build_coverage_map -i exp_ra_dec_v1.6 -o coverage_v1.6.x.hsp -c 128 -n 131072 -v
```

The healsparse resolutions (128, 131072) match the bit masks.


Use `plot_coverage_map` to create plots of the coverage mask.

Building and plotting for a range of versions is done with
`build_and_plot_coverage_maps.sh`.


## Extra Utilities

### Run in Terminal in Parallel
Expand Down
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies = [
"canfar",
"sf_tools",
"h5py",
"healsparse",
"skyproj",
]


Expand All @@ -33,6 +35,10 @@ lint = [
"black",
"isort"
]
plot = [
"skyproj",
"matplotlib"
]
release = [
"build",
"twine",
Expand All @@ -44,14 +50,20 @@ test = [
"pytest-pydocstyle"
]
fitsio = ["fitsio"]
dev = ["shapepipe[doc,lint,release,test]"]
dev = ["shapepipe[doc,lint,plot,release,test]"]

[project.scripts]
shapepipe_run = "shapepipe.shapepipe_run:main"
summary_run = "shapepipe.summary_run:main"
canfar_submit_job = "shapepipe.canfar_run:run_job"
canfar_monitor = "shapepipe.canfar_run:run_log"
canfar_monitor_log = "shapepipe.canfar_run:run_monitor_log"
get_ccd_with_psfs = "shapepipe.get_ccds_run:run_ccd_psf_handler"
download_headers = "shapepipe.coverage_run:run_download_headers"
extract_field_corners = "shapepipe.coverage_run:run_extract_corners"
build_coverage_map = "shapepipe.coverage_run:run_build_coverage"
plot_coverage_map = "shapepipe.coverage_run:run_plot_coverage"
coverage_pipeline = "shapepipe.coverage_run:run_pipeline"

[tool.pytest.ini_options]
addopts = "--verbose --cov=shapepipe"
Expand Down
180 changes: 19 additions & 161 deletions scripts/python/get_ccds_with_psf.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,192 +9,50 @@

"""


import sys
import numpy as np

from shapepipe.utilities import summary


def get_lines(fname):
"""Get Lines.

Return list of lines read from a text file.

Parameters
----------
fname: str
input file name

Returns:
list
IDs
from shapepipe.utilities.ccd_psf_handler import CcdPsfHandler

"""
IDs = []
with open(fname) as f:
lines = f.readlines()
for line in lines:
IDs.append(line.rstrip())

return IDs

def run_ccd_psf_handler(args=None):
"""Run CCD PSF Handler.

def get_exp_shdu_missing(patches):
"""Get Exp Shdu Missing.

Returns set of missing CCDs (single-exposure single-HDU IDs) from a list of patches.
Create instance and run the CCD PSF handler.

Parameters
----------
patches: list
input patches
args : list, optional
command line arguments

Returns
-------
set
missing CCD IDs
int
exit code

"""
exp_shdu_missing_all = set()

for patch in patches:

path_exp_shdu_missing = f"{patch}/summary/missing_job_32_all.txt"
exp_shdu_missing = get_lines(path_exp_shdu_missing)

print(f"Patch {patch}: Found {len(exp_shdu_missing)} missing ccds", end="; ")

exp_shdu_missing_all.update(exp_shdu_missing)

print(f"cumulative {len(exp_shdu_missing_all)} missing ccds")

print()

return exp_shdu_missing_all


def get_exp(patches):
"""Get Exp.

Return set of exposures from a list of patches.

Parameters
----------
patches: list
input patches

Returns
-------
set
exposure IDs

"""
exp_all = set()

for patch in patches:

path_exp = f"{patch}/exp_numbers.txt"
exp = get_lines(path_exp)

print(f"Patch {patch}: Found {len(exp)} exposures", end="; ")

exp_all.update(exp)

print(f"cumulative {len(exp_all)} exposures")
# Create instance
obj = CcdPsfHandler()

print()
return obj.run(args=args)

return exp_all

def main(argv=None):
"""Main.

def get_ccds_with_psf(patches, n_CCD=40):
"""Get CCDs With PSF.

Return set of CCDs from list of patches.
Main program.

Parameters
----------
patches: list
input patches
argv : list, optional
command line arguments

Returns
-------
set
CCD IDs
int
exit code

"""
# Get missing CCDs
print("=== get missing CCDs ===")
exp_shdu_missing_all = get_exp_shdu_missing(patches)

# Get all exposures used in tiles
print("=== get exposures ===")
exp_all = get_exp(patches)

# Turn exposures into exposure-single-HDU names (CCDs)
exp_shdu_all = summary.get_all_shdus(exp_all, n_CCD)

print(f"Found {len(exp_shdu_all)} CCDs")

return exp_shdu_all


def get_ccds_with_psf_method_2(patches, n_CCD=40):

for patch in patches:
directory = f"{patch}/exp_runs"

for entry in os.scandir(directory):
pass

def save(IDs, path):
"""Save.

Save list of IDs to text file.

Parameters
----------
IDs: set
input IDs

path: str
output file name

"""
with open(path, "w") as f_out:
for ID in IDs:
print(ID, file=f_out)

def main(argv):
"""Main.

Main program.

"""
version = "v1.5"

if version == "v1.4":
n_patch = 7
elif version == "v1.5":
n_patch = 8
else:
raise ValueError(f"Invalid version {version}")

patches = [f'P{x}' for x in np.arange(n_patch) + 1]

print(f"=== get_ccds_with_psf for version {version}, patches {patches} ===")

print("=== method 1: exp_list - missing === ")
exp_shdu_all = get_ccds_with_psf(patches)

save(exp_shdu_all, f"ccds_with_psf_{version}.txt")

#print("=== method 2: star cats === ")
#exp_shdu_all_method_2 = get_ccds_with_psf_method_2(patches)
#save(exp_shdu_all_method_2, f"ccds_with_psf_{version}_method_2.txt")

return 0
return run_ccd_psf_handler(args=argv)


if __name__ == "__main__":
Expand Down
69 changes: 69 additions & 0 deletions scripts/sh/build_and_plot_coverage_maps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Configuration variables

## Catalogue versions
VERSIONS=("v1.3" "v1.4" "v1.5" "v1.6")

## Output directory of plots
OUTPUT_DIR="coverage_map_plots"

# healsparse resolution
BUILD_NSIDE=131072
BUILD_CHANNELS=128

# Common parameters
VERBOSE="-v"

## Colorbar
PLOT_COLORBAR="-C"
PLOT_MIN=1
PLOT_MAX=5

# Plot parameters
## SGC region
SGC_RA_MIN=-20
SGC_RA_MAX=45
SGC_DEC_MIN=18
SGC_DEC_MAX=40

## NGC region
NGC_RA_MIN=110
NGC_RA_MAX=270
NGC_DEC_MIN=28
NGC_DEC_MAX=90

# Create output directory if it doesn't exist
mkdir -p "${OUTPUT_DIR}"

# Loop over versions
for VERSION in "${VERSIONS[@]}"; do
echo "Processing ${VERSION}..."

# Define file paths
INPUT_EXP="exp_ra_dec_${VERSION}.txt"
COVERAGE_MAP="coverage_${VERSION}.x.hsp"

# Build coverage map
echo " Building coverage map from ${INPUT_EXP}..."
CMD="build_coverage_map -i ${INPUT_EXP} -o ${COVERAGE_MAP} -c ${BUILD_CHANNELS} -n ${BUILD_NSIDE} ${VERBOSE}"
echo "$CMD"
$CMD

# Plot SGC region
echo " Plotting SGC region..."
CMD="plot_coverage_map -i ${COVERAGE_MAP} -o ${OUTPUT_DIR}/coverage_${VERSION}_SGC.png ${VERBOSE} ${PLOT_COLORBAR} -R ${SGC_RA_MIN} -r ${SGC_RA_MAX} -D ${SGC_DEC_MIN} -d ${SGC_DEC_MAX} -m ${PLOT_MIN} -M ${PLOT_MAX}"
echo "$CMD"
$CMD

# Plot NGC region
echo " Plotting NGC region..."
CMD="plot_coverage_map -i ${COVERAGE_MAP} -o ${OUTPUT_DIR}/coverage_${VERSION}_NGC.png ${VERBOSE} ${PLOT_COLORBAR} -R ${NGC_RA_MIN} -r ${NGC_RA_MAX} -D ${NGC_DEC_MIN} -d ${NGC_DEC_MAX} -m ${PLOT_MIN} -M ${PLOT_MAX}"
echo "$CMD"
$CMD

echo " Done with ${VERSION}"
echo
done

echo "All versions processed successfully!"
Loading