Skip to content

Commit 3385abf

Browse files
authored
Merge pull request #2509 from eerovaher/svo-fps-wavelengths
Remove default wavelength limits from `svo_fps` `get_filter_index()`
2 parents 3a57b4c + 74ff202 commit 3385abf

File tree

4 files changed

+102
-81
lines changed

4 files changed

+102
-81
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ svo_fps
117117
- Queries with invalid parameter names now raise an ``InvalidQueryError``.
118118
[#2446]
119119

120+
- The default wavelength range used by ``get_filter_index()`` was far too
121+
large. The user must now always specify both upper and lower limits. [#2509]
122+
120123
gaia
121124
^^^^
122125

astroquery/svo_fps/core.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
from . import conf
1010

1111
from ..query import BaseQuery
12-
from astroquery.exceptions import InvalidQueryError
12+
from astroquery.exceptions import InvalidQueryError, TimeoutError
1313

1414

1515
__all__ = ['SvoFpsClass', 'SvoFps']
1616

17-
FLOAT_MAX = np.finfo(np.float64).max
18-
1917
# Valid query parameters taken from
2018
# http://svo2.cab.inta-csic.es/theory/fps/index.php?mode=voservice
2119
_params_with_range = {"WavelengthRef", "WavelengthMean", "WavelengthEff",
@@ -80,19 +78,17 @@ def data_from_svo(self, query, cache=True, timeout=None,
8078
# If no table element found in VOTable
8179
raise IndexError(error_msg)
8280

83-
def get_filter_index(self, wavelength_eff_min=0*u.angstrom,
84-
wavelength_eff_max=FLOAT_MAX*u.angstrom, **kwargs):
81+
def get_filter_index(self, wavelength_eff_min, wavelength_eff_max, **kwargs):
8582
"""Get master list (index) of all filters at SVO
8683
Optional parameters can be given to get filters data for specified
8784
Wavelength Effective range from SVO
8885
8986
Parameters
9087
----------
91-
wavelength_eff_min : `~astropy.units.Quantity` with units of length, optional
92-
Minimum value of Wavelength Effective (default is 0 angstrom)
93-
wavelength_eff_max : `~astropy.units.Quantity` with units of length, optional
94-
Maximum value of Wavelength Effective (default is a very large
95-
quantity FLOAT_MAX angstroms i.e. maximum value of np.float64)
88+
wavelength_eff_min : `~astropy.units.Quantity` with units of length
89+
Minimum value of Wavelength Effective
90+
wavelength_eff_max : `~astropy.units.Quantity` with units of length
91+
Maximum value of Wavelength Effective
9692
kwargs : dict
9793
Passed to `data_from_svo`. Relevant arguments include ``cache``
9894
@@ -104,7 +100,13 @@ def get_filter_index(self, wavelength_eff_min=0*u.angstrom,
104100
query = {'WavelengthEff_min': wavelength_eff_min.to_value(u.angstrom),
105101
'WavelengthEff_max': wavelength_eff_max.to_value(u.angstrom)}
106102
error_msg = 'No filter found for requested Wavelength Effective range'
107-
return self.data_from_svo(query=query, error_msg=error_msg, **kwargs)
103+
try:
104+
return self.data_from_svo(query=query, error_msg=error_msg, **kwargs)
105+
except requests.ReadTimeout:
106+
raise TimeoutError(
107+
"Query did not finish fast enough. A smaller wavelength range might "
108+
"succeed. Try increasing the timeout limit if a large range is needed."
109+
)
108110

109111
def get_transmission_data(self, filter_id, **kwargs):
110112
"""Get transmission data for the requested Filter ID from SVO

astroquery/svo_fps/tests/test_svo_fps.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import pytest
22
import os
33
from astropy import units as u
4+
from requests import ReadTimeout
45

5-
from astroquery.exceptions import InvalidQueryError
6+
from astroquery.exceptions import InvalidQueryError, TimeoutError
67
from astroquery.utils.mocks import MockResponse
78
from ..core import SvoFps
89

@@ -46,7 +47,9 @@ def get_mockreturn(method, url, params=None, timeout=10, cache=None, **kwargs):
4647
return MockResponse(content, **kwargs)
4748

4849

49-
def test_get_filter_index(patch_get):
50+
def test_get_filter_index(patch_get, monkeypatch):
51+
with pytest.raises(TypeError, match="missing 2 required positional arguments"):
52+
SvoFps.get_filter_index()
5053
lambda_min = TEST_LAMBDA*u.angstrom
5154
lambda_max = lambda_min + 100*u.angstrom
5255
table = SvoFps.get_filter_index(lambda_min, lambda_max)
@@ -56,6 +59,17 @@ def test_get_filter_index(patch_get):
5659
# `get_mockreturn` raises `NotImplementedError`.
5760
SvoFps.get_filter_index(lambda_min.to(u.m), lambda_max)
5861

62+
def get_mockreturn_timeout(*args, **kwargs):
63+
raise ReadTimeout
64+
65+
monkeypatch.setattr(SvoFps, '_request', get_mockreturn_timeout)
66+
error_msg = (
67+
r"^Query did not finish fast enough\. A smaller wavelength range might "
68+
r"succeed\. Try increasing the timeout limit if a large range is needed\.$"
69+
)
70+
with pytest.raises(TimeoutError, match=error_msg):
71+
SvoFps.get_filter_index(lambda_min, lambda_max)
72+
5973

6074
def test_get_transmission_data(patch_get):
6175
table = SvoFps.get_transmission_data(TEST_FILTER_ID)

docs/svo_fps/svo_fps.rst

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.. doctest-skip-all
2-
31
.. _astroquery.svo_fps:
42

53
**********************************************************
@@ -17,17 +15,19 @@ from the service as astropy tables.
1715
Get index list of all Filters
1816
-----------------------------
1917

20-
The filter index (all available filters with their properties) can be listed
21-
with `~astroquery.svo_fps.SvoFpsClass.get_filter_index`:
18+
The filter index (the properties of all available filters in a wavelength
19+
range) can be listed with
20+
:meth:`~astroquery.svo_fps.SvoFpsClass.get_filter_index`:
2221

23-
.. code-block:: python
22+
.. doctest-remote-data::
2423

24+
>>> from astropy import units as u
2525
>>> from astroquery.svo_fps import SvoFps
26-
>>> index = SvoFps.get_filter_index()
26+
>>> index = SvoFps.get_filter_index(12_000*u.angstrom, 12_100*u.angstrom)
2727
>>> index.info
28-
<Table masked=True length=5139>
29-
name dtype unit
30-
-------------------- ------- ----
28+
<Table length=14>
29+
name dtype unit
30+
-------------------- ------- ---------------
3131
FilterProfileService object
3232
filterID object
3333
WavelengthUnit object
@@ -41,28 +41,31 @@ with `~astroquery.svo_fps.SvoFpsClass.get_filter_index`:
4141
CalibrationReference object
4242
Description object
4343
Comments object
44-
WavelengthMean float32 AA
45-
WavelengthEff float32 AA
46-
WavelengthMin float32 AA
47-
WavelengthMax float32 AA
48-
WidthEff float32 AA
49-
WavelengthCen float32 AA
50-
WavelengthPivot float32 AA
51-
WavelengthPeak float32 AA
52-
WavelengthPhot float32 AA
53-
FWHM float32 AA
44+
WavelengthRef float64 AA
45+
WavelengthMean float64 AA
46+
WavelengthEff float64 AA
47+
WavelengthMin float64 AA
48+
WavelengthMax float64 AA
49+
WidthEff float64 AA
50+
WavelengthCen float64 AA
51+
WavelengthPivot float64 AA
52+
WavelengthPeak float64 AA
53+
WavelengthPhot float64 AA
54+
FWHM float64 AA
55+
Fsun float64 erg s / (A cm2)
5456
PhotCalID object
5557
MagSys object
56-
ZeroPoint float32 Jy
58+
ZeroPoint float64 Jy
5759
ZeroPointUnit object
58-
Mag0 float32
60+
Mag0 float64
5961
ZeroPointType object
60-
AsinhSoft float32
62+
AsinhSoft float64
6163
TrasmissionCurve object
6264

63-
There are options to downselect based on the minimum
64-
and maximum effective wavelength (``wavelength_eff_min``
65-
and ``wavelength_eff_max``, respectively).
65+
If the wavelength range contains too many entries then a ``TimeoutError`` will
66+
occur. A smaller wavelength range might succeed, but if a large range really is
67+
required then you can use the ``timeout`` argument to allow for a longer
68+
response time.
6669

6770
Get list of Filters under a specified Facilty and Instrument
6871
------------------------------------------------------------
@@ -72,14 +75,13 @@ Filters for an arbitrary combination of Facility & Instrument (the Facility
7275
must be specified, but the Instrument is optional). The data table returned
7376
is of the same form as that from `~astroquery.svo_fps.SvoFpsClass.get_filter_index`:
7477

75-
.. code-block:: python
78+
.. doctest-remote-data::
7679

7780
>>> filter_list = SvoFps.get_filter_list(facility='Keck', instrument='NIRC2')
7881
>>> filter_list.info
79-
80-
<Table masked=True length=11>
81-
name dtype unit
82-
-------------------- ------- ----
82+
<Table length=11>
83+
name dtype unit
84+
-------------------- ------- ---------------
8385
FilterProfileService object
8486
filterID object
8587
WavelengthUnit object
@@ -93,26 +95,27 @@ is of the same form as that from `~astroquery.svo_fps.SvoFpsClass.get_filter_ind
9395
CalibrationReference object
9496
Description object
9597
Comments object
96-
WavelengthMean float32 AA
97-
WavelengthEff float32 AA
98-
WavelengthMin float32 AA
99-
WavelengthMax float32 AA
100-
WidthEff float32 AA
101-
WavelengthCen float32 AA
102-
WavelengthPivot float32 AA
103-
WavelengthPeak float32 AA
104-
WavelengthPhot float32 AA
105-
FWHM float32 AA
98+
WavelengthRef float64 AA
99+
WavelengthMean float64 AA
100+
WavelengthEff float64 AA
101+
WavelengthMin float64 AA
102+
WavelengthMax float64 AA
103+
WidthEff float64 AA
104+
WavelengthCen float64 AA
105+
WavelengthPivot float64 AA
106+
WavelengthPeak float64 AA
107+
WavelengthPhot float64 AA
108+
FWHM float64 AA
109+
Fsun float64 erg s / (A cm2)
106110
PhotCalID object
107111
MagSys object
108-
ZeroPoint float32 Jy
112+
ZeroPoint float64 Jy
109113
ZeroPointUnit object
110-
Mag0 float32
114+
Mag0 float64
111115
ZeroPointType object
112-
AsinhSoft float32
116+
AsinhSoft float64
113117
TrasmissionCurve object
114118

115-
116119
Get transmission data for a specific Filter
117120
-------------------------------------------
118121

@@ -122,40 +125,39 @@ If you know the ``filterID`` of the filter (which you can determine with
122125
transmission curve data using
123126
`~astroquery.svo_fps.SvoFpsClass.get_transmission_data`:
124127

125-
.. code-block:: python
128+
.. doctest-remote-data::
126129

127130
>>> data = SvoFps.get_transmission_data('2MASS/2MASS.H')
128131
>>> print(data)
129132
Wavelength Transmission
130133
AA
131134
---------- ------------
132-
12890.0 0.0
133-
13150.0 0.0
134-
13410.0 0.0
135-
13680.0 0.0
136-
13970.0 0.0
137-
14180.0 0.0
138-
14400.0 0.0005
139-
14620.0 0.0028
140-
14780.0 0.0081
141-
14860.0 0.0287
142-
... ...
143-
18030.0 0.1077
144-
18100.0 0.0707
145-
18130.0 0.0051
146-
18180.0 0.02
147-
18280.0 0.0004
148-
18350.0 0.0
149-
18500.0 1e-04
150-
18710.0 0.0
151-
18930.0 0.0
152-
19140.0 0.0
135+
12890.0 0.0
136+
13150.0 0.0
137+
13410.0 0.0
138+
13680.0 0.0
139+
13970.0 0.0
140+
14180.0 0.0
141+
14400.0 0.0005
142+
14620.0 0.0027999999
143+
14780.0 0.0081000002
144+
14860.0 0.0286999997
145+
... ...
146+
18030.0 0.1076999977
147+
18100.0 0.0706999972
148+
18130.0 0.0051000002
149+
18180.0 0.0199999996
150+
18280.0 0.0004
151+
18350.0 0.0
152+
18500.0 0.0001
153+
18710.0 0.0
154+
18930.0 0.0
155+
19140.0 0.0
153156
Length = 58 rows
154157

155-
156158
These are the data needed to plot the transmission curve for filter:
157159

158-
.. code-block:: python
160+
.. doctest-skip::
159161

160162
>>> import matplotlib.pyplot as plt
161163
>>> plt.plot(data['Wavelength'], data['Transmission'])

0 commit comments

Comments
 (0)