bbf 0.7.0__tar.gz → 0.7.1__tar.gz
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.
- {bbf-0.7.0 → bbf-0.7.1}/PKG-INFO +2 -1
- {bbf-0.7.0 → bbf-0.7.1}/bbf/filterlib.py +86 -9
- {bbf-0.7.0 → bbf-0.7.1}/bbf/magsys.py +7 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/data/snfactory.parquet +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/gaia.py +67 -50
- {bbf-0.7.0 → bbf-0.7.1}/pixi.lock +8736 -8671
- {bbf-0.7.0 → bbf-0.7.1}/pyproject.toml +2 -1
- {bbf-0.7.0 → bbf-0.7.1}/tests/conftest.py +6 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_compare_sncosmo.py +25 -3
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_filterlib.py +16 -1
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_stellarlib.py +29 -3
- {bbf-0.7.0 → bbf-0.7.1}/CHANGELOG.md +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/CMakeLists.txt +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/LICENSE +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/README.md +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/__init__.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/atmosphere.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/__init__.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/bspline.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/bspline2d.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/cardinal_bspline.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/cardinal_bspline2d.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/projector.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/src/bspline.hpp +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/src/bspline_ext.cpp +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/bspline/utils.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/cache.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/data/Buton_Atmo.dat +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/data/SNIFS_extinction.fits +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/data/palomar_extinction_eac4.dat +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/data/palomar_extinction_merra2.dat +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/filterset.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/sncosmoutils.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/snfilterset.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/__init__.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/calspec.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/data/pickles.parquet +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/pickles.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/snfactory.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/stellarlib/stellarlib.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/bbf/utils.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/snls.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_atmosphere.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_bspline_1d.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_bspline_2d.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_cardinal_bspline.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/test_sncosmoutils.py +0 -0
- {bbf-0.7.0 → bbf-0.7.1}/tests/utils.py +0 -0
{bbf-0.7.0 → bbf-0.7.1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bbf
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: Fast computation of broadband fluxes and magnitudes
|
|
5
5
|
Keywords: astronomy,astrophysics
|
|
6
6
|
Author-Email: Nicolas Regnault <nicolas.regnault@lpnhe.in2p3.fr>
|
|
@@ -27,6 +27,7 @@ Requires-Dist: platformdirs
|
|
|
27
27
|
Requires-Dist: scikit-sparse<0.5
|
|
28
28
|
Requires-Dist: scipy>=1.14
|
|
29
29
|
Requires-Dist: sncosmo>=2.12
|
|
30
|
+
Requires-Dist: gaiahealpixcache>=0.4.0
|
|
30
31
|
Provides-Extra: test
|
|
31
32
|
Requires-Dist: pytest>=6.0; extra == "test"
|
|
32
33
|
Requires-Dist: pytest-cov; extra == "test"
|
|
@@ -6,6 +6,7 @@ import lzma
|
|
|
6
6
|
import pathlib
|
|
7
7
|
import pickle
|
|
8
8
|
import sys
|
|
9
|
+
from copy import deepcopy
|
|
9
10
|
|
|
10
11
|
import matplotlib.pyplot as plt
|
|
11
12
|
import numpy as np
|
|
@@ -78,7 +79,7 @@ class XYBandpass:
|
|
|
78
79
|
|
|
79
80
|
self.to_filter = interp.transforms.to_filter
|
|
80
81
|
self.to_focalplane = interp.transforms.to_focalplane
|
|
81
|
-
|
|
82
|
+
self.effective_filter = kwargs.get("effective_filter", None)
|
|
82
83
|
if not init:
|
|
83
84
|
return
|
|
84
85
|
|
|
@@ -122,9 +123,18 @@ class XYBandpass:
|
|
|
122
123
|
self.spatial_basis = spatial_basis
|
|
123
124
|
|
|
124
125
|
def flux(
|
|
125
|
-
self,
|
|
126
|
+
self,
|
|
127
|
+
stellarlib,
|
|
128
|
+
star,
|
|
129
|
+
x,
|
|
130
|
+
y,
|
|
131
|
+
sensor_id=None,
|
|
132
|
+
airmass=None,
|
|
133
|
+
filter_frame=False,
|
|
134
|
+
**kwargs,
|
|
126
135
|
):
|
|
127
136
|
""" """
|
|
137
|
+
shift_aa = kwargs.get("shift_aa", 0)
|
|
128
138
|
if not filter_frame:
|
|
129
139
|
s_id = sensor_id if sensor_id is not None else self.sensor_id
|
|
130
140
|
xf, yf = self.to_filter(x, y, s_id)
|
|
@@ -132,7 +142,7 @@ class XYBandpass:
|
|
|
132
142
|
xf, yf = x, y
|
|
133
143
|
|
|
134
144
|
Jxy = self.spatial_basis.eval(xf, yf).tocsr()
|
|
135
|
-
G = lgram(stellarlib.basis, self.basis).tocsr()
|
|
145
|
+
G = lgram(stellarlib.basis, BSpline(self.basis.grid + shift_aa)).tocsr()
|
|
136
146
|
P = _pick_matrix(star, len(stellarlib)).tocsr()
|
|
137
147
|
|
|
138
148
|
if "dot_product_mkl" in globals() and not self.force_spgemm:
|
|
@@ -151,6 +161,13 @@ class XYBandpass:
|
|
|
151
161
|
self.atmspec, stellarlib, airmass
|
|
152
162
|
) # (nspec, nairmass)
|
|
153
163
|
FF = FF * refactor
|
|
164
|
+
if (
|
|
165
|
+
hasattr(self, "psf_effective_filter")
|
|
166
|
+
and self.psf_effective_filter is not None
|
|
167
|
+
):
|
|
168
|
+
eff = self.psf_effective_filter(stellarlib.waveeff)
|
|
169
|
+
FF = FF * eff[:, None]
|
|
170
|
+
|
|
154
171
|
flx = (SS * FF.T).sum(axis=1)
|
|
155
172
|
|
|
156
173
|
return flx
|
|
@@ -181,6 +198,12 @@ class XYBandpass:
|
|
|
181
198
|
np.atleast_1d(wl[:, None]), np.atleast_1d(airmass)
|
|
182
199
|
)
|
|
183
200
|
r *= ext.squeeze()
|
|
201
|
+
if (
|
|
202
|
+
hasattr(self, "psf_effective_filter")
|
|
203
|
+
and self.psf_effective_filter is not None
|
|
204
|
+
):
|
|
205
|
+
eff = self.psf_effective_filter(wl)
|
|
206
|
+
r *= eff
|
|
184
207
|
return r
|
|
185
208
|
|
|
186
209
|
# def get_bandpass(self, x, y, sensor_id=None, wl=None, z=0., airmass=None, filter_frame=False):
|
|
@@ -281,9 +304,18 @@ class RadialBandpass:
|
|
|
281
304
|
self.spatial_basis = spatial_basis
|
|
282
305
|
|
|
283
306
|
def flux(
|
|
284
|
-
self,
|
|
307
|
+
self,
|
|
308
|
+
stellarlib,
|
|
309
|
+
star,
|
|
310
|
+
x,
|
|
311
|
+
y,
|
|
312
|
+
sensor_id=None,
|
|
313
|
+
airmass=None,
|
|
314
|
+
filter_frame=False,
|
|
315
|
+
**kwargs,
|
|
285
316
|
):
|
|
286
317
|
""" """
|
|
318
|
+
shift_aa = kwargs.get("shift_aa", 0)
|
|
287
319
|
if not filter_frame:
|
|
288
320
|
s_id = sensor_id if sensor_id is not None else self.sensor_id
|
|
289
321
|
xf, yf = self.to_filter(x, y, s_id)
|
|
@@ -292,7 +324,7 @@ class RadialBandpass:
|
|
|
292
324
|
|
|
293
325
|
rad = np.sqrt(xf**2 + yf**2)
|
|
294
326
|
Jxy = self.spatial_basis.eval(rad).tocsr()
|
|
295
|
-
G = lgram(stellarlib.basis, self.basis).tocsr()
|
|
327
|
+
G = lgram(stellarlib.basis, BSpline(self.basis.grid + shift_aa)).tocsr()
|
|
296
328
|
P = _pick_matrix(star, len(stellarlib)).tocsr()
|
|
297
329
|
|
|
298
330
|
if "dot_product_mkl" in globals() and not self.force_spgemm:
|
|
@@ -309,6 +341,12 @@ class RadialBandpass:
|
|
|
309
341
|
if airmass is not None and self.atmspec is not None:
|
|
310
342
|
refactor = _airmass_refactor(self.atmspec, stellarlib, airmass)
|
|
311
343
|
FF = FF * refactor
|
|
344
|
+
if (
|
|
345
|
+
hasattr(self, "psf_effective_filter")
|
|
346
|
+
and self.psf_effective_filter is not None
|
|
347
|
+
):
|
|
348
|
+
eff = self.psf_effective_filter(stellarlib.waveeff)
|
|
349
|
+
FF = FF * eff[:, None]
|
|
312
350
|
flx = (SS * FF.T).sum(axis=1)
|
|
313
351
|
|
|
314
352
|
# Negative fluxes???
|
|
@@ -339,8 +377,13 @@ class RadialBandpass:
|
|
|
339
377
|
ext = self.atmspec.get_atm_extinction(
|
|
340
378
|
np.atleast_1d(wl[:, None]), np.atleast_1d(airmass)
|
|
341
379
|
)
|
|
342
|
-
|
|
343
380
|
r *= ext.squeeze()
|
|
381
|
+
if (
|
|
382
|
+
hasattr(self, "psf_effective_filter")
|
|
383
|
+
and self.psf_effective_filter is not None
|
|
384
|
+
):
|
|
385
|
+
eff = self.psf_effective_filter(wl)
|
|
386
|
+
r *= eff
|
|
344
387
|
return r
|
|
345
388
|
|
|
346
389
|
def wave_eff(self, x=None, y=None, airmass=None):
|
|
@@ -441,7 +484,9 @@ class Bandpass:
|
|
|
441
484
|
|
|
442
485
|
def flux(self, stellarlib, star=None, x=None, y=None, airmass=None, **kwargs):
|
|
443
486
|
""" """
|
|
444
|
-
|
|
487
|
+
shift_aa = kwargs.get("shift_aa", 0)
|
|
488
|
+
bs = BSpline(self.basis.grid + shift_aa)
|
|
489
|
+
G = lgram(stellarlib.basis, bs)
|
|
445
490
|
P = _pick_matrix(star, len(stellarlib))
|
|
446
491
|
FF = G @ self.coeffs.T
|
|
447
492
|
if airmass is not None and self.atmspec is not None:
|
|
@@ -449,6 +494,13 @@ class Bandpass:
|
|
|
449
494
|
self.atmspec, stellarlib, airmass
|
|
450
495
|
) # (nspec, nairmass)
|
|
451
496
|
FF = FF.reshape(-1, 1) * refactor
|
|
497
|
+
if (
|
|
498
|
+
hasattr(self, "psf_effective_filter")
|
|
499
|
+
and self.psf_effective_filter is not None
|
|
500
|
+
):
|
|
501
|
+
eff = self.psf_effective_filter(stellarlib.waveeff)
|
|
502
|
+
FF = FF * eff[:, None]
|
|
503
|
+
|
|
452
504
|
# look for the doot
|
|
453
505
|
SS = P @ stellarlib.coeffs.T
|
|
454
506
|
flx = (SS * FF.T).sum(axis=1)
|
|
@@ -469,6 +521,12 @@ class Bandpass:
|
|
|
469
521
|
np.atleast_1d(wl[:, None]), np.atleast_1d(airmass)
|
|
470
522
|
)
|
|
471
523
|
r *= ext.squeeze()
|
|
524
|
+
if (
|
|
525
|
+
hasattr(self, "psf_effective_filter")
|
|
526
|
+
and self.psf_effective_filter is not None
|
|
527
|
+
):
|
|
528
|
+
eff = self.psf_effective_filter(wl)
|
|
529
|
+
r *= eff
|
|
472
530
|
return r
|
|
473
531
|
|
|
474
532
|
def wave_eff(self, x=None, y=None, airmass=None):
|
|
@@ -735,6 +793,23 @@ class FilterLib:
|
|
|
735
793
|
else:
|
|
736
794
|
self._bandpasses[band_name] = band
|
|
737
795
|
|
|
796
|
+
def insert_psf_bandpass(self, band_name, psf_name, c_psf, average=False):
|
|
797
|
+
"""Initialize a psf effective filter function as
|
|
798
|
+
1 + c_psf * (\lambda - 500) / 200
|
|
799
|
+
"""
|
|
800
|
+
if average:
|
|
801
|
+
bp = deepcopy(self._average_bandpasses[band_name])
|
|
802
|
+
bp.psf_effective_filter = lambda wl: 1 + c_psf * (wl - 500) / 200
|
|
803
|
+
self._average_bandpasses[psf_name] = bp
|
|
804
|
+
else:
|
|
805
|
+
bp = deepcopy(self._bandpasses[band_name])
|
|
806
|
+
if isinstance(bp, CompositeBandpass):
|
|
807
|
+
for k, v in bp._bandpasses.items():
|
|
808
|
+
v.psf_effective_filter = lambda wl: 1 + c_psf * (wl - 500) / 200
|
|
809
|
+
else:
|
|
810
|
+
bp.psf_effective_filter = lambda wl: 1 + c_psf * (wl - 500) / 200
|
|
811
|
+
self._bandpasses[psf_name] = bp
|
|
812
|
+
|
|
738
813
|
def flux(
|
|
739
814
|
self,
|
|
740
815
|
stellarlib,
|
|
@@ -745,6 +820,7 @@ class FilterLib:
|
|
|
745
820
|
sensor_id=None,
|
|
746
821
|
filter_frame=False,
|
|
747
822
|
airmass=None,
|
|
823
|
+
**kwargs,
|
|
748
824
|
):
|
|
749
825
|
"""Computes the broadband fluxes for a series of measurements.
|
|
750
826
|
|
|
@@ -834,7 +910,7 @@ class FilterLib:
|
|
|
834
910
|
args.airmass,
|
|
835
911
|
)
|
|
836
912
|
|
|
837
|
-
|
|
913
|
+
try:
|
|
838
914
|
fluxes[idx] = bp.flux(
|
|
839
915
|
stellarlib,
|
|
840
916
|
star=star[idx],
|
|
@@ -843,8 +919,9 @@ class FilterLib:
|
|
|
843
919
|
sensor_id=None if sensor_id is None else sensor_id[idx],
|
|
844
920
|
filter_frame=filter_frame,
|
|
845
921
|
airmass=None if airmass is None else airmass[idx],
|
|
922
|
+
**kwargs,
|
|
846
923
|
)
|
|
847
|
-
|
|
924
|
+
except:
|
|
848
925
|
logging.error(
|
|
849
926
|
f"error computing fluxes for: band={band} sensor_id={sensor_id}"
|
|
850
927
|
)
|
|
@@ -69,6 +69,7 @@ class SpecMagsys:
|
|
|
69
69
|
sensor_id=None,
|
|
70
70
|
filter_frame=False,
|
|
71
71
|
airmass=None,
|
|
72
|
+
**kwargs,
|
|
72
73
|
):
|
|
73
74
|
""" """
|
|
74
75
|
# basis = flib.basis if self.basis is None else self.basis
|
|
@@ -83,6 +84,7 @@ class SpecMagsys:
|
|
|
83
84
|
sensor_id=sensor_id,
|
|
84
85
|
filter_frame=filter_frame,
|
|
85
86
|
airmass=airmass,
|
|
87
|
+
**kwargs,
|
|
86
88
|
)
|
|
87
89
|
return flx
|
|
88
90
|
|
|
@@ -96,6 +98,7 @@ class SpecMagsys:
|
|
|
96
98
|
sensor_id=None,
|
|
97
99
|
filter_frame=False,
|
|
98
100
|
airmass=None,
|
|
101
|
+
**kwargs,
|
|
99
102
|
):
|
|
100
103
|
"""return the zero point of the local mag system"""
|
|
101
104
|
rbbflx = self.ref_broadbandflux(
|
|
@@ -107,6 +110,7 @@ class SpecMagsys:
|
|
|
107
110
|
sensor_id=sensor_id,
|
|
108
111
|
filter_frame=filter_frame,
|
|
109
112
|
airmass=airmass,
|
|
113
|
+
**kwargs,
|
|
110
114
|
)
|
|
111
115
|
return 2.5 * np.log10(rbbflx)
|
|
112
116
|
|
|
@@ -121,6 +125,7 @@ class SpecMagsys:
|
|
|
121
125
|
sensor_id=None,
|
|
122
126
|
filter_frame=False,
|
|
123
127
|
airmass=None,
|
|
128
|
+
**kwargs,
|
|
124
129
|
):
|
|
125
130
|
""" """
|
|
126
131
|
flx = flib.flux(
|
|
@@ -132,6 +137,7 @@ class SpecMagsys:
|
|
|
132
137
|
sensor_id=sensor_id,
|
|
133
138
|
filter_frame=filter_frame,
|
|
134
139
|
airmass=airmass,
|
|
140
|
+
**kwargs,
|
|
135
141
|
)
|
|
136
142
|
mag = -2.5 * np.log10(flx)
|
|
137
143
|
zp = self.zero_points(
|
|
@@ -143,6 +149,7 @@ class SpecMagsys:
|
|
|
143
149
|
sensor_id=sensor_id,
|
|
144
150
|
filter_frame=filter_frame,
|
|
145
151
|
airmass=airmass,
|
|
152
|
+
**kwargs,
|
|
146
153
|
)
|
|
147
154
|
return mag + zp
|
|
148
155
|
|
|
Binary file
|
|
@@ -20,9 +20,8 @@ coordinate boundaries.
|
|
|
20
20
|
import logging
|
|
21
21
|
import os
|
|
22
22
|
import pathlib
|
|
23
|
-
import tempfile
|
|
24
23
|
import urllib.request
|
|
25
|
-
|
|
24
|
+
import tempfile
|
|
26
25
|
import gaiaxpy
|
|
27
26
|
import healpy
|
|
28
27
|
import numpy as np
|
|
@@ -30,6 +29,7 @@ import pandas as pd
|
|
|
30
29
|
|
|
31
30
|
# from astropy.table import Table
|
|
32
31
|
from astroquery.gaia import GaiaClass
|
|
32
|
+
import gaiahealpixcache
|
|
33
33
|
|
|
34
34
|
from bbf import get_data_dir
|
|
35
35
|
from bbf.stellarlib import StellarLib
|
|
@@ -104,7 +104,8 @@ def get_pix_range(ra, dec, gaia_dir):
|
|
|
104
104
|
"""
|
|
105
105
|
pixlist = get_pixlist(
|
|
106
106
|
pd.DataFrame({"ra": ra + ra, "dec": dec + dec[::-1]}),
|
|
107
|
-
radius=max(float(np.diff(ra)), float(np.diff(dec))),
|
|
107
|
+
# radius=max(float(np.diff(ra)), float(np.diff(dec))),
|
|
108
|
+
radius=max(float(np.diff(ra)[0]), float(np.diff(dec)[0])),
|
|
108
109
|
)
|
|
109
110
|
|
|
110
111
|
# TODO span range
|
|
@@ -123,7 +124,7 @@ def get_pix_range(ra, dec, gaia_dir):
|
|
|
123
124
|
return [ranges[fi] for fi in f]
|
|
124
125
|
|
|
125
126
|
|
|
126
|
-
def get_ids(ra_min, ra_max, dec_min, dec_max
|
|
127
|
+
def get_ids(ra_min, ra_max, dec_min, dec_max):
|
|
127
128
|
"""Return ids within given footprint
|
|
128
129
|
|
|
129
130
|
:param float ra_min: min ra value in deg
|
|
@@ -132,42 +133,12 @@ def get_ids(ra_min, ra_max, dec_min, dec_max, maxq=5000):
|
|
|
132
133
|
:param float dec_max: max dec value in deg
|
|
133
134
|
:return dataframe ids: gaia source_id, ra, dec
|
|
134
135
|
"""
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
gaia_data_server="https://gea.esac.esa.int/",
|
|
138
|
-
)
|
|
139
|
-
query = (
|
|
140
|
-
f"select TOP {maxq} source_id, ra, dec from gaiadr3.gaia_source "
|
|
141
|
-
f"where has_xp_continuous = 'True' and ra <= {ra_max} and "
|
|
142
|
-
f"ra >= {ra_min} and dec <= {dec_max} and dec >= {dec_min}"
|
|
143
|
-
)
|
|
144
|
-
job = gaia.launch_job_async(query, dump_to_file=False)
|
|
145
|
-
ids = job.get_results()
|
|
146
|
-
ids = pd.DataFrame(np.array(ids))
|
|
147
|
-
|
|
136
|
+
sources = gaiahealpixcache.query_rectangular(ra_min, ra_max, dec_min, dec_max)
|
|
137
|
+
ids = pd.DataFrame(sources[["ra", "dec", "source_id"]])
|
|
148
138
|
logger.info("Selected %s ids within footprint", len(ids))
|
|
149
139
|
return ids
|
|
150
140
|
|
|
151
141
|
|
|
152
|
-
def get_gaia_spectra(ids):
|
|
153
|
-
"""Return gaia spectra matching gaia ids."""
|
|
154
|
-
gaia = GaiaClass(
|
|
155
|
-
gaia_tap_server="https://gea.esac.esa.int/",
|
|
156
|
-
gaia_data_server="https://gea.esac.esa.int/",
|
|
157
|
-
)
|
|
158
|
-
_use = "source_id" if "source_id" in ids.columns else "SOURCE_ID"
|
|
159
|
-
spectra = gaia.load_data(
|
|
160
|
-
ids=ids[_use],
|
|
161
|
-
format="csv",
|
|
162
|
-
data_release="Gaia DR3",
|
|
163
|
-
data_structure="raw",
|
|
164
|
-
retrieval_type="XP_CONTINUOUS",
|
|
165
|
-
avoid_datatype_check=True,
|
|
166
|
-
)
|
|
167
|
-
data = spectra["XP_CONTINUOUS_RAW.csv"][0]
|
|
168
|
-
return data
|
|
169
|
-
|
|
170
|
-
|
|
171
142
|
def retrieve_gaia_data(pixel_range, gaia_dir):
|
|
172
143
|
"""Load Gaia spectra.
|
|
173
144
|
|
|
@@ -211,17 +182,55 @@ def retrieve_gaia_data(pixel_range, gaia_dir):
|
|
|
211
182
|
)
|
|
212
183
|
return calibrated_spectra, sampling * 10
|
|
213
184
|
|
|
185
|
+
# def get_gaia_spectra(ids):
|
|
186
|
+
# """Return gaia spectra matching gaia ids."""
|
|
187
|
+
# gaia = GaiaClass(
|
|
188
|
+
# gaia_tap_server="https://gea.esac.esa.int/",
|
|
189
|
+
# gaia_data_server="https://gea.esac.esa.int/",
|
|
190
|
+
# )
|
|
191
|
+
# _use = "source_id" if "source_id" in ids.columns else "SOURCE_ID"
|
|
192
|
+
# spectra = gaia.load_data(
|
|
193
|
+
# ids=ids[_use],
|
|
194
|
+
# format="csv",
|
|
195
|
+
# data_release="Gaia DR3",
|
|
196
|
+
# data_structure="raw",
|
|
197
|
+
# retrieval_type="XP_CONTINUOUS",
|
|
198
|
+
# avoid_datatype_check=True,
|
|
199
|
+
# )
|
|
200
|
+
# data = spectra["XP_CONTINUOUS_RAW.csv"][0]
|
|
201
|
+
# return data
|
|
202
|
+
|
|
203
|
+
# def _fetch_on_the_fly_ids(ids, basis):
|
|
204
|
+
# logger.info("Retrieve spectra on the fly")
|
|
205
|
+
|
|
206
|
+
# with tempfile.NamedTemporaryFile(suffix=".csv") as tmp:
|
|
207
|
+
# get_gaia_spectra(ids).write(tmp.name, overwrite=True)
|
|
208
|
+
# data, sampling = gaiaxpy.calibrate(tmp.name, save_file=False)
|
|
209
|
+
|
|
210
|
+
# data = data.assign(ra=ids["ra"], dec=ids["dec"])
|
|
211
|
+
# data["flux"] *= 100
|
|
212
|
+
# data["flux_error"] *= 100
|
|
213
|
+
# _use = "source_id" if "source_id" in data.columns else "SOURCE_ID"
|
|
214
|
+
# data = data.set_index(_use) # needed to join
|
|
215
|
+
|
|
216
|
+
# # 2 nm
|
|
217
|
+
# sp = StellarLib(data, basis=basis, wave=sampling * 10, project=False)
|
|
218
|
+
|
|
219
|
+
# # same_wave_grid projection not working
|
|
220
|
+
# sp.coeffs = sp.project(one_by_one=True)
|
|
221
|
+
# return sp
|
|
222
|
+
|
|
223
|
+
def _fetch_on_the_fly_coords(ra_min, ra_max, dec_min, dec_max, basis, continuous_spectra=True):
|
|
214
224
|
|
|
215
|
-
def _fetch_on_the_fly(ids, basis):
|
|
216
225
|
logger.info("Retrieve spectra on the fly")
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
product = "continuous_spectra" if continuous_spectra else "sampled_spectra"
|
|
227
|
+
meta, flux = gaiahealpixcache.query_spectra_rectangular(
|
|
228
|
+
ra_min, ra_max, dec_min, dec_max, product=product,
|
|
229
|
+
)
|
|
230
|
+
data = pd.DataFrame(meta)
|
|
231
|
+
sampling = gaiahealpixcache.spectro_wavelengths() #
|
|
232
|
+
data = data.assign(flux=list(flux)) # todo add flux_error
|
|
223
233
|
data["flux"] *= 100
|
|
224
|
-
data["flux_error"] *= 100
|
|
225
234
|
_use = "source_id" if "source_id" in data.columns else "SOURCE_ID"
|
|
226
235
|
data = data.set_index(_use) # needed to join
|
|
227
236
|
|
|
@@ -234,7 +243,12 @@ def _fetch_on_the_fly(ids, basis):
|
|
|
234
243
|
|
|
235
244
|
|
|
236
245
|
def fetch(
|
|
237
|
-
basis=None,
|
|
246
|
+
basis=None,
|
|
247
|
+
ra_bound=[],
|
|
248
|
+
dec_bound=[],
|
|
249
|
+
gaia_dir=None,
|
|
250
|
+
on_the_fly=True,
|
|
251
|
+
continuous_spectra=True,
|
|
238
252
|
):
|
|
239
253
|
"""Fetch some gaia spectra matching sky coordinate and return them in
|
|
240
254
|
a StellarLib.
|
|
@@ -246,11 +260,14 @@ def fetch(
|
|
|
246
260
|
:return stellarlib sps: a stellar lib object
|
|
247
261
|
|
|
248
262
|
"""
|
|
249
|
-
ids = get_ids(*(ra_bound + dec_bound), maxq=maxq)
|
|
250
|
-
_use = "source_id" if "source_id" in ids.columns else "SOURCE_ID"
|
|
251
|
-
|
|
252
263
|
if on_the_fly:
|
|
253
|
-
return
|
|
264
|
+
return _fetch_on_the_fly_coords(*ra_bound,
|
|
265
|
+
*dec_bound,
|
|
266
|
+
basis,
|
|
267
|
+
continuous_spectra=continuous_spectra)
|
|
268
|
+
|
|
269
|
+
ids = get_ids(*(ra_bound + dec_bound))
|
|
270
|
+
_use = "source_id" if "source_id" in ids.columns else "SOURCE_ID"
|
|
254
271
|
|
|
255
272
|
if gaia_dir is None:
|
|
256
273
|
gaia_dir = get_data_dir() / "gaia"
|
|
@@ -269,7 +286,7 @@ def fetch(
|
|
|
269
286
|
|
|
270
287
|
logger.info("%s spectra within pixel range", len(data))
|
|
271
288
|
data = data.join(ids, how="inner") # join is the fastest option
|
|
272
|
-
data = data.assign(ra=ids["ra"][data.index], dec=ids["dec"][data.index])
|
|
289
|
+
# data = data.assign(ra=ids["ra"][data.index], dec=ids["dec"][data.index])
|
|
273
290
|
logger.info("Xcheck: %s", len(data))
|
|
274
291
|
if len(data) == 0:
|
|
275
292
|
continue
|