Skip to content

Commit 336e657

Browse files
committed
updating moving target functionality and test coverage for get_sectors, download_cutouts, and get_cutouts. also fixing import statements and other typos.
1 parent 4aec2b3 commit 336e657

File tree

3 files changed

+157
-38
lines changed

3 files changed

+157
-38
lines changed

astroquery/mast/cutouts.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_
155155

156156
if moving_target:
157157

158-
# Check that objectname has been passed in
158+
# Check that objectname has been passed in and coordinates
159+
# is not
159160
if coordinates:
160-
raise InvalidQueryError("Only one of moving_target and coordinates may be specified.")
161+
raise InvalidQueryError("Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname.")
161162

162163
if not objectname:
163164
raise InvalidQueryError("Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet.")
@@ -259,14 +260,21 @@ def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", infl
259260
"""
260261

261262
if moving_target:
262-
# Check only ony object designator has been passed in
263-
if objectname or coordinates:
264-
raise InvalidQueryError("Only one of objectname, coordinates, and moving_target may be specified.")
265263

266-
astrocut_request = f"moving_target/astrocut?obj_id={moving_target}"
264+
# Check that objectname has been passed in and coordinates
265+
# is not
266+
if coordinates:
267+
raise InvalidQueryError("Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname.")
268+
269+
if not objectname:
270+
raise InvalidQueryError("Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet.")
271+
272+
astrocut_request = f"moving_target/astrocut?obj_id={objectname}"
267273
if mt_type:
268274
astrocut_request += f"&obj_type={mt_type}"
275+
269276
else:
277+
270278
# Get Skycoord object for coordinates/object
271279
coordinates = parse_input_location(coordinates, objectname)
272280

@@ -364,11 +372,15 @@ def get_cutouts(self, coordinates=None, size=5, sector=None,
364372

365373
if moving_target:
366374

367-
# Check only on object designator has been passed in
368-
if objectname or coordinates:
369-
raise InvalidQueryError("Only one of objectname, coordinates, and moving_target may be specified.")
375+
# Check that objectname has been passed in and coordinates
376+
# is not
377+
if coordinates:
378+
raise InvalidQueryError("Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname.")
379+
380+
if not objectname:
381+
raise InvalidQueryError("Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet.")
370382

371-
param_dict["obj_id"] = moving_target
383+
param_dict["obj_id"] = objectname
372384

373385
# Add optional parameter if present
374386
if mt_type:

astroquery/mast/tests/test_mast.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ def test_tesscut_get_sector(patch_post):
590590
assert sector_table['ccd'][0] == 3
591591

592592
# Exercising the search by moving target
593-
sector_table = mast.Tesscut.get_sectors(moving_target="Ceres")
593+
sector_table = mast.Tesscut.get_sectors(objectname="Ceres",
594+
moving_target=True)
594595
assert isinstance(sector_table, Table)
595596
assert len(sector_table) == 1
596597
assert sector_table['sectorName'][0] == "tess-s0001-1-3"
@@ -599,14 +600,10 @@ def test_tesscut_get_sector(patch_post):
599600
assert sector_table['ccd'][0] == 3
600601

601602
# Testing catch for multiple designators'
602-
error_str = "Only one of objectname, coordinates, and moving_target may be specified."
603+
error_str = "Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname."
603604

604605
with pytest.raises(InvalidQueryError) as invalid_query:
605-
mast.Tesscut.get_sectors(moving_target="Ceres", coordinates=coord)
606-
assert error_str in str(invalid_query.value)
607-
608-
with pytest.raises(InvalidQueryError) as invalid_query:
609-
mast.Tesscut.get_sectors(moving_target="Ceres", objectname="M103")
606+
mast.Tesscut.get_sectors(objectname='Ceres', moving_target=True, coordinates=coord)
610607
assert error_str in str(invalid_query.value)
611608

612609

@@ -637,21 +634,24 @@ def test_tesscut_download_cutouts(patch_post, tmpdir):
637634
assert os.path.isfile(manifest[0]['Local Path'])
638635

639636
# Exercising the search by moving target
640-
manifest = mast.Tesscut.download_cutouts(moving_target="Eleonora", size=5, path=str(tmpdir))
637+
manifest = mast.Tesscut.download_cutouts(objectname="Eleonora",
638+
moving_target=True,
639+
size=5,
640+
path=str(tmpdir))
641641
assert isinstance(manifest, Table)
642642
assert len(manifest) == 1
643643
assert manifest["Local Path"][0][-4:] == "fits"
644644
assert os.path.isfile(manifest[0]['Local Path'])
645645

646646
# Testing catch for multiple designators'
647-
error_str = "Only one of objectname, coordinates, and moving_target may be specified."
647+
error_str = "Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname."
648648

649649
with pytest.raises(InvalidQueryError) as invalid_query:
650-
mast.Tesscut.download_cutouts(moving_target="Eleonora", coordinates=coord, size=5, path=str(tmpdir))
651-
assert error_str in str(invalid_query.value)
652-
653-
with pytest.raises(InvalidQueryError) as invalid_query:
654-
mast.Tesscut.download_cutouts(moving_target="Eleonora", objectname="M103", size=5, path=str(tmpdir))
650+
mast.Tesscut.download_cutouts(objectname="Eleonora",
651+
moving_target=True,
652+
coordinates=coord,
653+
size=5,
654+
path=str(tmpdir))
655655
assert error_str in str(invalid_query.value)
656656

657657

@@ -670,20 +670,21 @@ def test_tesscut_get_cutouts(patch_post, tmpdir):
670670
assert isinstance(cutout_hdus_list[0], fits.HDUList)
671671

672672
# Exercising the search by object name
673-
cutout_hdus_list = mast.Tesscut.get_cutouts(moving_target="Eleonora", size=5)
673+
cutout_hdus_list = mast.Tesscut.get_cutouts(objectname='Eleonora',
674+
moving_target=True,
675+
size=5)
674676
assert isinstance(cutout_hdus_list, list)
675677
assert len(cutout_hdus_list) == 1
676678
assert isinstance(cutout_hdus_list[0], fits.HDUList)
677679

678680
# Testing catch for multiple designators'
679-
error_str = "Only one of objectname, coordinates, and moving_target may be specified."
680-
681-
with pytest.raises(InvalidQueryError) as invalid_query:
682-
mast.Tesscut.get_cutouts(moving_target="Eleonora", coordinates=coord, size=5)
683-
assert error_str in str(invalid_query.value)
681+
error_str = "Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname."
684682

685683
with pytest.raises(InvalidQueryError) as invalid_query:
686-
mast.Tesscut.get_cutouts(moving_target="Eleonora", objectname="M103", size=5)
684+
mast.Tesscut.get_cutouts(objectname="Eleonora",
685+
moving_target=True,
686+
coordinates=coord,
687+
size=5)
687688
assert error_str in str(invalid_query.value)
688689

689690

astroquery/mast/tests/test_mast_remote.py

Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from astropy.io import fits
1212
import astropy.units as u
1313

14-
from astroquery.exceptions import NoResultsWarning
1514
from astroquery import mast
1615

17-
from ...exceptions import RemoteServiceError, MaxResultsWarning
16+
from ..utils import ResolverError
17+
from ...exceptions import InvalidQueryError, MaxResultsWarning, NoResultsWarning, RemoteServiceError
1818

1919

2020
OBSID = '1647157'
@@ -702,14 +702,49 @@ def test_tesscut_get_sectors(self):
702702
assert sector_table['camera'][0] > 0
703703
assert sector_table['ccd'][0] > 0
704704

705-
sector_table = mast.Tesscut.get_sectors(moving_target="Stichius")
705+
# Moving target functionality testing
706+
707+
moving_target_name = 'Eleonora'
708+
709+
sector_table = mast.Tesscut.get_sectors(objectname=moving_target_name,
710+
moving_target=True)
706711
assert isinstance(sector_table, Table)
707712
assert len(sector_table) >= 1
708-
assert sector_table['sectorName'][0] == "tess-s0001-1-1"
709-
assert sector_table['sector'][0] == 1
713+
assert sector_table['sectorName'][0] == "tess-s0006-1-1"
714+
assert sector_table['sector'][0] == 6
710715
assert sector_table['camera'][0] == 1
711716
assert sector_table['ccd'][0] == 1
712717

718+
error_noname = "Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet."
719+
error_nameresolve = f"Could not resolve {moving_target_name} to a sky position."
720+
error_mt_coord = "Only one of moving_target and coordinates may be specified."
721+
error_name_coord = "Only one of objectname and coordinates may be specified."
722+
723+
with pytest.raises(InvalidQueryError) as error_msg:
724+
mast.Tesscut.get_sectors(moving_target=True)
725+
assert error_noname in str(error_msg.value)
726+
727+
with pytest.raises(ResolverError) as error_msg:
728+
mast.Tesscut.get_sectors(objectname=moving_target_name)
729+
assert error_nameresolve in str(error_msg.value)
730+
731+
with pytest.raises(InvalidQueryError) as error_msg:
732+
mast.Tesscut.get_sectors(coordinates=coord, moving_target=True)
733+
assert error_mt_coord in str(error_msg.value)
734+
735+
with pytest.raises(InvalidQueryError) as error_msg:
736+
mast.Tesscut.get_sectors(objectname=moving_target_name,
737+
coordinates=coord)
738+
assert error_name_coord in str(error_msg.value)
739+
740+
with pytest.raises(InvalidQueryError) as error_msg:
741+
mast.Tesscut.get_sectors(objectname=moving_target_name,
742+
coordinates=coord,
743+
moving_target=True)
744+
assert error_mt_coord in str(error_msg.value)
745+
746+
747+
713748
def test_tesscut_download_cutouts(self, tmpdir):
714749

715750
coord = SkyCoord(349.62609, -47.12424, unit="deg")
@@ -749,13 +784,49 @@ def test_tesscut_download_cutouts(self, tmpdir):
749784
for row in manifest:
750785
assert os.path.isfile(row['Local Path'])
751786

752-
manifest = mast.Tesscut.download_cutouts(moving_target="Eleonora", sector=6, size=5, path=str(tmpdir))
787+
# Moving target functionality testing
788+
789+
moving_target_name = 'Eleonora'
790+
791+
manifest = mast.Tesscut.download_cutouts(objectname=moving_target_name,
792+
moving_target=True,
793+
sector=6,
794+
size=5,
795+
path=str(tmpdir))
753796
assert isinstance(manifest, Table)
754797
assert len(manifest) == 1
755798
assert manifest["Local Path"][0][-4:] == "fits"
756799
for row in manifest:
757800
assert os.path.isfile(row['Local Path'])
758801

802+
error_noname = "Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet."
803+
error_nameresolve = f"Could not resolve {moving_target_name} to a sky position."
804+
error_mt_coord = "Only one of moving_target and coordinates may be specified."
805+
error_name_coord = "Only one of objectname and coordinates may be specified."
806+
807+
with pytest.raises(InvalidQueryError) as error_msg:
808+
mast.Tesscut.download_cutouts(moving_target=True)
809+
assert error_noname in str(error_msg.value)
810+
811+
with pytest.raises(ResolverError) as error_msg:
812+
mast.Tesscut.download_cutouts(objectname=moving_target_name)
813+
assert error_nameresolve in str(error_msg.value)
814+
815+
with pytest.raises(InvalidQueryError) as error_msg:
816+
mast.Tesscut.download_cutouts(coordinates=coord, moving_target=True)
817+
assert error_mt_coord in str(error_msg.value)
818+
819+
with pytest.raises(InvalidQueryError) as error_msg:
820+
mast.Tesscut.download_cutouts(objectname=moving_target_name,
821+
coordinates=coord)
822+
assert error_name_coord in str(error_msg.value)
823+
824+
with pytest.raises(InvalidQueryError) as error_msg:
825+
mast.Tesscut.download_cutouts(objectname=moving_target_name,
826+
coordinates=coord,
827+
moving_target=True)
828+
assert error_mt_coord in str(error_msg.value)
829+
759830
def test_tesscut_get_cutouts(self, tmpdir):
760831

761832
coord = SkyCoord(107.18696, -70.50919, unit="deg")
@@ -782,11 +853,46 @@ def test_tesscut_get_cutouts(self, tmpdir):
782853
assert len(cutout_hdus_list) >= 1
783854
assert isinstance(cutout_hdus_list[0], fits.HDUList)
784855

785-
cutout_hdus_list = mast.Tesscut.get_cutouts(moving_target="Eleonora", sector=6, size=5)
856+
# Moving target functionality testing
857+
858+
moving_target_name = 'Eleonora'
859+
860+
cutout_hdus_list = mast.Tesscut.get_cutouts(objectname=moving_target_name,
861+
moving_target=True,
862+
sector=6,
863+
size=5)
786864
assert isinstance(cutout_hdus_list, list)
787865
assert len(cutout_hdus_list) == 1
788866
assert isinstance(cutout_hdus_list[0], fits.HDUList)
789867

868+
error_noname = "Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet."
869+
error_nameresolve = f"Could not resolve {moving_target_name} to a sky position."
870+
error_mt_coord = "Only one of moving_target and coordinates may be specified."
871+
error_name_coord = "Only one of objectname and coordinates may be specified."
872+
873+
with pytest.raises(InvalidQueryError) as error_msg:
874+
mast.Tesscut.download_cutouts(moving_target=True)
875+
assert error_noname in str(error_msg.value)
876+
877+
with pytest.raises(ResolverError) as error_msg:
878+
mast.Tesscut.download_cutouts(objectname=moving_target_name)
879+
assert error_nameresolve in str(error_msg.value)
880+
881+
with pytest.raises(InvalidQueryError) as error_msg:
882+
mast.Tesscut.download_cutouts(coordinates=coord, moving_target=True)
883+
assert error_mt_coord in str(error_msg.value)
884+
885+
with pytest.raises(InvalidQueryError) as error_msg:
886+
mast.Tesscut.download_cutouts(objectname=moving_target_name,
887+
coordinates=coord)
888+
assert error_name_coord in str(error_msg.value)
889+
890+
with pytest.raises(InvalidQueryError) as error_msg:
891+
mast.Tesscut.download_cutouts(objectname=moving_target_name,
892+
coordinates=coord,
893+
moving_target=True)
894+
assert error_mt_coord in str(error_msg.value)
895+
790896
###################
791897
# ZcutClass tests #
792898
###################

0 commit comments

Comments
 (0)