Skip to content

Commit

Permalink
Merge pull request #550 from duytnguyendtn/time_nan
Browse files Browse the repository at this point in the history
Check for nan dateobs before converting to Time
  • Loading branch information
bsipocz committed May 22, 2024
2 parents 3044910 + 013ac08 commit 96b0f7a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 13 deletions.
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ Deprecations and Removals
-------------------------


1.5.2 (unreleased)
==================

Bug Fixes
---------

- Avoid Astropy Time error for SIAResult.dateobs when
VOX:Image_MJDateObs or ssa:DataID.Date is nan. [#550]


1.5.1 (2024-02-21)
==================

Expand Down
12 changes: 8 additions & 4 deletions pyvo/dal/sia.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy.units import Quantity, Unit
import numpy as np

from .query import DALResults, DALQuery, DALService, Record
from .mimetype import mime2extension
Expand Down Expand Up @@ -702,10 +703,13 @@ def dateobs(self):
as an astropy.time.Time instance
"""
dateobs = self.getbyucd("VOX:Image_MJDateObs")
if dateobs:
return Time(dateobs, format="mjd")
else:
return None
try:
if not dateobs or np.isnan(dateobs):
return None
except TypeError:
# np.isnan can only check floats. If can't check for nan, pass it along
pass
return Time(dateobs, format="mjd")

@property
def naxes(self):
Expand Down
12 changes: 8 additions & 4 deletions pyvo/dal/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from astropy.units import spectral as spectral_equivalencies
from astropy.io.votable.tree import Field
from astropy.table import Table
import numpy as np

from .query import DALResults, DALQuery, DALService, Record
from .mimetype import mime2extension
Expand Down Expand Up @@ -696,10 +697,13 @@ def dateobs(self):
observational data that went into the spectrum
"""
dateobs = self.getbyutype("ssa:DataID.Date", decode=True)
if dateobs:
return Time(dateobs, format="iso")
else:
return None
try:
if not dateobs or np.isnan(dateobs):
return None
except TypeError:
# np.isnan can only check floats. If can't check for nan, pass it along
pass
return Time(dateobs, format="iso")

@property
def instr(self):
Expand Down
14 changes: 14 additions & 0 deletions pyvo/dal/tests/data/sia/dataset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
<TD>5.2e-07</TD>
<TD>0.000403806 0.000406123</TD>
</TR>
<TR>
<TD>This should not be the dataurl</TD>
<TD>http://example.com/querydata/image.fits</TD>
<TD>image/fits</TD>
<TD>153280</TD>
<TD/> <!-- Empty VOX:Image_MJDateObs field -->
<TD>Test</TD>
<TD>288.95078924817</TD>
<TD>15.0322239971381</TD>
<TD>Test Observation</TD>
<TD>3.8e-07</TD>
<TD>5.2e-07</TD>
<TD>0.000403806 0.000406123</TD>
</TR>
</TABLEDATA>
</DATA>
</TABLE>
Expand Down
1 change: 1 addition & 0 deletions pyvo/dal/tests/data/ssa/result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<TR><TD>1.0976232720625123E-25</TD><TD>http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&amp;FORMAT=votable&amp;PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380443408220422144</TD><TD>application/x-votable+xml</TD><TD>SPECTRUM-1.0</TD><TD>SPECTRUM</TD><TD>4000</TD><TD>s</TD><TD>A</TD><TD>10**(-17) erg s**(-1) cm**(-2) A**(-1)</TD><TD>SDSS J120022.76+004741.46 GALAXY</TD><TD>sdss</TD><TD>SDSS DR6</TD><TD>ivo://sdss/dr6/spec/2_5/#80443408220422144</TD><TD>2001-01-21 11:23:50Z</TD><TD>6.2.5</TD><TD>ivo://sdss/dr6/spec/2_5/#80443408220422144</TD><TD>SDSS 2.5-M SPEC2 v4_5</TD><TD>OPTICAL</TD><TD>SURVEY</TD><TD>ARCHIVAL</TD><TD>ELTE VO</TD><TD>ivo://jhu/sdss/dr6/spec/2.5#80443408220422144</TD><TD>PUBLIC</TD><TD>180.094830 0.794849</TD><TD>SDSS J120022.76+004741.46</TD><TD>GALAXY</TD><TD>0.139797</TD><TD>0</TD><TD>FK5</TD><TD>2000</TD><TD>TAI</TD><TD>180.094830 0.794849</TD><TD></TD></TR>
<TR><TD>8.441184510333563E-42</TD><TD>http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&amp;FORMAT=votable&amp;PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380443407868100608</TD><TD>application/x-votable+xml</TD><TD>SPECTRUM-1.0</TD><TD>SPECTRUM</TD><TD>4000</TD><TD>s</TD><TD>A</TD><TD>10**(-17) erg s**(-1) cm**(-2) A**(-1)</TD><TD>SDSS J115918.12+005113.61 GALAXY</TD><TD>sdss</TD><TD>SDSS DR6</TD><TD>ivo://sdss/dr6/spec/2_5/#80443407868100608</TD><TD>2001-01-21 11:23:50Z</TD><TD>6.2.5</TD><TD>ivo://sdss/dr6/spec/2_5/#80443407868100608</TD><TD>SDSS 2.5-M SPEC2 v4_5</TD><TD>OPTICAL</TD><TD>SURVEY</TD><TD>ARCHIVAL</TD><TD>ELTE VO</TD><TD>ivo://jhu/sdss/dr6/spec/2.5#80443407868100608</TD><TD>PUBLIC</TD><TD>179.825520 0.853781</TD><TD>SDSS J115918.12+005113.61</TD><TD>GALAXY</TD><TD>0.0770442</TD><TD>0</TD><TD>FK5</TD><TD>2000</TD><TD>TAI</TD><TD>179.825520 0.853781</TD><TD></TD></TR>
<TR><TD>8.441184510333563E-42</TD><TD>http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&amp;FORMAT=votable&amp;PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380442261136998400</TD><TD>application/x-votable+xml</TD><TD>SPECTRUM-1.0</TD><TD>SPECTRUM</TD><TD>4000</TD><TD>s</TD><TD>A</TD><TD>10**(-17) erg s**(-1) cm**(-2) A**(-1)</TD><TD>SDSS J115918.12+005113.61 GALAXY</TD><TD>sdss</TD><TD>SDSS DR6</TD><TD>ivo://sdss/dr6/spec/2_5/#80442261136998400</TD><TD>2000-04-29 03:22:00Z</TD><TD>6.2.5</TD><TD>ivo://sdss/dr6/spec/2_5/#80442261136998400</TD><TD>SDSS 2.5-M SPEC2 v4_5</TD><TD>OPTICAL</TD><TD>SURVEY</TD><TD>ARCHIVAL</TD><TD>ELTE VO</TD><TD>ivo://jhu/sdss/dr6/spec/2.5#80442261136998400</TD><TD>PUBLIC</TD><TD>179.825520 0.853781</TD><TD>SDSS J115918.12+005113.61</TD><TD>GALAXY</TD><TD>0.0770941</TD><TD>0</TD><TD>FK5</TD><TD>2000</TD><TD>TAI</TD><TD>179.825520 0.853781</TD><TD></TD></TR>
<TR><TD>8.441184510333563E-42</TD><TD>http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&amp;FORMAT=votable&amp;PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380442261136998400</TD><TD>application/x-votable+xml</TD><TD>SPECTRUM-1.0</TD><TD>SPECTRUM</TD><TD>4000</TD><TD>s</TD><TD>A</TD><TD>10**(-17) erg s**(-1) cm**(-2) A**(-1)</TD><TD>SDSS J115918.12+005113.61 GALAXY</TD><TD>sdss</TD><TD>SDSS DR6</TD><TD>ivo://sdss/dr6/spec/2_5/#80442261136998400</TD><TD/><!-- Empty VOX:Image_MJDateObs field --><TD>6.2.5</TD><TD>ivo://sdss/dr6/spec/2_5/#80442261136998400</TD><TD>SDSS 2.5-M SPEC2 v4_5</TD><TD>OPTICAL</TD><TD>SURVEY</TD><TD>ARCHIVAL</TD><TD>ELTE VO</TD><TD>ivo://jhu/sdss/dr6/spec/2.5#80442261136998400</TD><TD>PUBLIC</TD><TD>179.825520 0.853781</TD><TD>SDSS J115918.12+005113.61</TD><TD>GALAXY</TD><TD>0.0770941</TD><TD>0</TD><TD>FK5</TD><TD>2000</TD><TD>TAI</TD><TD>179.825520 0.853781</TD><TD></TD></TR>
</TABLEDATA>
</DATA>
</TABLE>
Expand Down
10 changes: 7 additions & 3 deletions pyvo/dal/tests/test_sia.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ class TestSIAService:
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W42")
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W49")
def test_search(self):
service = SIAService('http://example.com/sia', capability_description="A SIA service.")
assert service.baseurl == 'http://example.com/sia'
assert service.capability_description == "A SIA service."
description = "A SIA service."
url = 'http://example.com/sia'
service = SIAService(url, capability_description=description)
assert service.baseurl == url
assert service.capability_description == description

results = service.search(pos=(288, 15))
result = results[0]

_test_result(result)

assert results[1].dateobs is None
5 changes: 3 additions & 2 deletions pyvo/dal/tests/test_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def callback(request, context):
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W42")
def test_search():
results = search('http://example.com/ssa', pos=(0.0, 0.0), diameter=1.0)
assert len(results) == 35
assert len(results) == 36


class TestSSAService:
Expand All @@ -46,4 +46,5 @@ def test_search(self):

results = service.search(pos=(0.0, 0.0), diameter=1.0)

assert len(results) == 35
assert len(results) == 36
assert results[35].dateobs is None

0 comments on commit 96b0f7a

Please sign in to comment.