STCI 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Download_Euclid.py +77 -0
- STCI.py +21 -0
- Tian_color.py +1644 -0
- stci-0.1.0.dist-info/METADATA +110 -0
- stci-0.1.0.dist-info/RECORD +8 -0
- stci-0.1.0.dist-info/WHEEL +5 -0
- stci-0.1.0.dist-info/licenses/LICENSE +21 -0
- stci-0.1.0.dist-info/top_level.txt +3 -0
Download_Euclid.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import astropy.units as u
|
|
6
|
+
import numpy as np
|
|
7
|
+
from astropy.coordinates import SkyCoord
|
|
8
|
+
from astropy.io import fits
|
|
9
|
+
from astroquery.esa.euclid.core import EuclidClass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
BANDS = ("VIS", "NIR_Y", "NIR_J", "NIR_H")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _query(ra: float, dec: float) -> str:
|
|
16
|
+
return (
|
|
17
|
+
"SELECT file_name, file_path, filter_name, product_id "
|
|
18
|
+
"FROM dr1.mosaic_product "
|
|
19
|
+
"WHERE (product_type like '%Mer%Mosaic%') "
|
|
20
|
+
"AND ((instrument_name='VIS' AND filter_name='VIS') "
|
|
21
|
+
"OR (instrument_name='NISP' AND filter_name IN ('NIR_Y','NIR_J','NIR_H'))) "
|
|
22
|
+
"AND category='SCIENCE' AND fov IS NOT NULL AND "
|
|
23
|
+
f"INTERSECTS(CIRCLE('ICRS',{ra},{dec},0.0166667),fov)=1 "
|
|
24
|
+
"ORDER BY product_id ASC"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _is_all_zero(path: Path) -> bool:
|
|
29
|
+
with fits.open(path, memmap=False) as hdul:
|
|
30
|
+
data = next(hdu.data for hdu in hdul if hdu.data is not None)
|
|
31
|
+
return np.count_nonzero(np.nan_to_num(data, nan=0.0)) == 0
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def EUC_download(ra, dec, size, path, cred):
|
|
35
|
+
"""
|
|
36
|
+
Download Euclid DR1 VIS/Y/J/H FITS cutouts.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
ra, dec : float
|
|
41
|
+
Target coordinates in degrees.
|
|
42
|
+
size : float
|
|
43
|
+
Cutout radius in arcsec.
|
|
44
|
+
path : str or Path
|
|
45
|
+
Output directory.
|
|
46
|
+
cred : str or Path
|
|
47
|
+
Euclid credentials file.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
outdir = Path(path)
|
|
51
|
+
outdir.mkdir(parents=True, exist_ok=True)
|
|
52
|
+
coord = SkyCoord(float(ra), float(dec), unit="deg")
|
|
53
|
+
|
|
54
|
+
euclid = EuclidClass(environment="IDR")
|
|
55
|
+
euclid.login(credentials_file=str(cred))
|
|
56
|
+
|
|
57
|
+
rows = euclid.launch_job(_query(float(ra), float(dec)), verbose=False).get_results()
|
|
58
|
+
outputs = {}
|
|
59
|
+
|
|
60
|
+
for band in BANDS:
|
|
61
|
+
for i, row in enumerate(rows[rows["filter_name"] == band], start=1):
|
|
62
|
+
outfile = outdir / f"{band}_tile{i}.fits"
|
|
63
|
+
euclid.get_cutout(
|
|
64
|
+
file_path=f"{row['file_path']}/{row['file_name']}",
|
|
65
|
+
instrument="None",
|
|
66
|
+
id=str(row["product_id"]),
|
|
67
|
+
coordinate=coord,
|
|
68
|
+
radius=u.Quantity(float(size), u.arcsec),
|
|
69
|
+
output_file=str(outfile),
|
|
70
|
+
)
|
|
71
|
+
if outfile.stat().st_size > 0 and not _is_all_zero(outfile):
|
|
72
|
+
outputs[band] = outfile
|
|
73
|
+
break
|
|
74
|
+
if band not in outputs:
|
|
75
|
+
raise RuntimeError(f"No non-zero {band} cutout found.")
|
|
76
|
+
|
|
77
|
+
return outputs
|
STCI.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Public entry point for STCI."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from Tian_color import * # noqa: F401,F403
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def Euclidimg(ra, dec, size, path, cred, output_jpg="Euclid_color.jpg"):
|
|
9
|
+
"""Download Euclid FITS cutouts and render one color JPEG."""
|
|
10
|
+
|
|
11
|
+
from Download_Euclid import EUC_download
|
|
12
|
+
|
|
13
|
+
outdir = Path(path)
|
|
14
|
+
fits_paths = EUC_download(ra, dec, size, outdir, cred)
|
|
15
|
+
jpg_path = outdir / output_jpg
|
|
16
|
+
mk_colorimg(
|
|
17
|
+
[fits_paths["NIR_J"], fits_paths["NIR_Y"], fits_paths["VIS"]],
|
|
18
|
+
output_jpg=jpg_path,
|
|
19
|
+
input_mode="raw",
|
|
20
|
+
)
|
|
21
|
+
return {"fits": fits_paths, "jpg": jpg_path}
|