Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAST: Moving target TESScut #2121

Merged
merged 12 commits into from
Jan 31, 2022
Merged

MAST: Moving target TESScut #2121

merged 12 commits into from
Jan 31, 2022

Conversation

ceb8
Copy link
Member

@ceb8 ceb8 commented Jul 19, 2021

Adding functionality to access the new MAST Moving Target TESScut functionality from the astroquery.mast Tesscut class.

Includes:

  • New moving_target argument to Tesscut class functions, that allows users to make cutouts for named moving targets (asteroids/comets etc).
  • Associated documentation
  • Associated tests (remote and local)
  • Update to mast cloud access documentation to reflect prior code changes (unrelated, just apparently forgot to do the docs when I updated the code)
  • General test tweaks to explicitly catch warnings and make sure all the remote tests pass

@pep8speaks
Copy link

pep8speaks commented Jul 19, 2021

Hello @ceb8! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-01-31 20:24:21 UTC

@ceb8 ceb8 added the mast label Jul 19, 2021
@codecov
Copy link

codecov bot commented Jul 19, 2021

Codecov Report

Merging #2121 (2a127ae) into main (31a4164) will increase coverage by 0.02%.
The diff coverage is 86.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2121      +/-   ##
==========================================
+ Coverage   62.70%   62.72%   +0.02%     
==========================================
  Files         131      131              
  Lines       16828    16855      +27     
==========================================
+ Hits        10552    10573      +21     
- Misses       6276     6282       +6     
Impacted Files Coverage Δ
astroquery/mast/cutouts.py 79.42% <86.04%> (-0.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31a4164...2a127ae. Read the comment docs.

@bsipocz bsipocz added this to the v0.4.4 milestone Aug 10, 2021
Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly needs a changelog entry.

Most of my comments are nit picks, but while I see why it's easier for the backend to use a new kwargs, for UX I don't think we need a new kwarg to specify the name.

Some of the test/cloud changes are unrelated to this PR, now it's fine to leave them, but next time I think they worth to put them in separate, smaller PRs.

I also have one remote failure:

astroquery/mast/tests/test_mast.py .........................................                                                                  [ 51%]
astroquery/mast/tests/test_mast_remote.py .........................F...........                                                               [ 98%]
docs/mast/mast.rst s                                                                                                                          [100%]

===================================================================== FAILURES ======================================================================
_______________________________________________________ TestMast.test_catalogs_query_criteria _______________________________________________________

self = <astroquery.mast.tests.test_mast_remote.TestMast object at 0x14daf9d00>

    def test_catalogs_query_criteria(self):
    
        # clear columns config
        mast.Catalogs._column_configs = dict()
    
        # without position
        result = mast.Catalogs.query_criteria(catalog="Tic", Bmag=[30, 50], objType="STAR")
        assert isinstance(result, Table)
        assert len(result) >= 10
        assert result[np.where(result['ID'] == '81609218')]
    
        result = mast.Catalogs.query_criteria(catalog="ctl", Tmag=[10.5, 11], POSflag="2mass")
        assert isinstance(result, Table)
>       assert len(result) >= 400
E       assert 316 >= 400
E        +  where 316 = len(<Table masked=True length=316>\n    ID    version   HIP      TYC      ... e_Dec_orig raddflag wdflag   objID  \n   str9 ......       70.0        1      0 137129648\n394245807 20190415    -- 9490-00757-1 ...      130.0        1      0 516829248)

astroquery/mast/tests/test_mast_remote.py:463: AssertionError

self._service_api_connection.set_service_params(services, "tesscut")

def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None):
def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_target=None, mt_type=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe now is a good time to make the kwargs mandatory kwargs given that only one of them can be provided?

Suggested change
def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_target=None, mt_type=None):
def get_sectors(self, *, coordinates=None, radius=0*u.deg, objectname=None, moving_target=None, mt_type=None):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever gets included in * also needs to be added to params = {"obj_id": moving_target} in L157 before the service call right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* means that the rest of the parameters are keyword only, nothing additional is included in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see - learned something new today. This might be something worth starting a new PR over, since its a syntax change, we'd want to add the * to all the Zcut methods as well, etc. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please do add it to all places where it makes sense, as separate PR sounds perfect, as it would allow us flexibility for the future as well as a safety-net against user bugs.

@@ -164,7 +195,8 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None):
warnings.warn("Coordinates are not in any TESS sector.", NoResultsWarning)
return Table(sector_dict)

def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", inflate=True, objectname=None):
def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", inflate=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, make them kwargs only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a separate issue for this: #2267

else:

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates, objectname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this has been the same before, but maybe it's worth using a different name here and below in the other methods, too that coordinates that is also a non-parsed, and maybe None input kwarg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rec would be to file and issue and have this be a seperate PR, bc this is the convention throughout the MAST module, so I think it would be clearer if they all got changed at once.

objectname : str, optional
The target around which to search, by name (objectname="M104")
or TIC ID (objectname="TIC 141914082").
One and only one of coordinates and objectname must be supplied.
One and only one of coordinates, objectname, moving_target must be supplied.
moving_target : str, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new kwarg for moving targets? At the end of the day they are the name of the object to query, and from the user's pow I don't see a difference whether querying for M1 or Ceres.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bsipocz , I've been tasked with addressing threads for this PR so it can get merged: From what I can tell it looks like there are two separate databases, and setting moving_target will make the request call for the moving target database in MAST.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, so my reason for doing this was twofold:

  • The resolving method for moving vs regular targets is completely different, and naming in astronomy is not always unique so I was worried about the user putting in a valid moving target and getting a stationary result.
  • The output for moving targets is not quite the same as for regular targets, since it's a different type of cutout, so I thought it was clearer to keep the two queries more separate.

Both of these concerns could be addressed by having a moving target flag that defaults to false instead of a whole new argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming mess affects not just moving targets, I'm sure there is overlap within non-moving ones if we look closely, too, and also, the users don't need to know what's under the hood, that depending on the type of the object the query goes to a different database.
So, I find the logic of having a bool moving_target clearer than basically having two separate APIs for the name depending on the service.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a new commit that turns moving_target into an optional bool argument. With your approvals, I'll make another commit to update the docstrings, tests, documentation, and collapse the commits into one.

self._cloud_connection.download_file(data_product, local_path, cache)
except Exception as ex:
log.exception("Error pulling from S3 bucket: {}".format(ex))
if self._cloud_connection is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this related to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an unrelated commit that was part of something else. I can make another commit to reverse these changes on my local branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this was something else I was working on that accidentally got in. @jaymedina you might want to check what is on the main branch, and if this bit needs to be added in another PR or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to revert these changes to what's in the main branch because it's following the same logic just written slightly differently, without the fall_back trigger and a few other things.


.. code-block:: python

>>> from astroquery.mast import Observations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks overindented

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked the rest of mast.rst and the indentation is consistent with the rest of the document. I worry pulling it back will mess up the formatting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then this is an issue for a separate quick cleanup PR.

>>> single_obs = Observations.query_criteria(obs_collection="IUE",obs_id="lwp13058")
>>> data_products = Observations.get_product_list(single_obs)

>>> Observations.download_products(data_products,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

download_products returns a table, maybe it's worth assigning it into a variable. However, it stays as is (I really don't have a strong preference), then include the table in the output below.


.. code-block:: python

>>> from astroquery.mast import Tesscut
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run into a timeout with this example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaymedina Try this example now, if I remember correctly the JPL horizons service was having timeout problems last August, so that might have been the problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

In [3]: hdulist = Tesscut.get_cutouts(moving_target="Eleonora", size=5, sector=6
   ...: )

In [4]: hdulist[0].info()
Filename: <class '_io.BytesIO'>
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU      54   ()      
  1  PIXELS        1 BinTableHDU    150   355R x 16C   [D, E, J, 25J, 25E, 25E, 25E, 25E, J, E, E, 38A, D, D, D, D]   
  2  APERTURE      1 ImageHDU        97   (2136, 2078)   int32   

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have 355 rows now instead of 356. Must be a numpy thing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ceb8 would you mind giving me writing access to your forked astroquery repo? I have some updates I need to commit to this branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaymedina you should have an invite now

@bsipocz bsipocz modified the milestones: v0.4.4, v4 Nov 13, 2021
@jaymedina
Copy link
Contributor

I'll have to dig myself out of this again. In the meantime, tests look good. There's one test that was intentionally skipped because it retrieves too much data, which I'll revisit later - it's lower priority because I have some back-end tests running and this test executes, I'll take a look at it in the next sprint and see if I can recreate it for the GitHub tests:

test_mast_remote.py ..................s....................                                                                                                                                    [100%]

====================================================================================== short test summary info =======================================================================================
SKIPPED [1] test_mast_remote.py:260: Tests should not download this much data. Skipping until revised.
============================================================================= 38 passed, 1 skipped in 1521.35s (0:25:21) =============================================================================

@jaymedina
Copy link
Contributor

I'm assuming a rebase will collapse all the commits that got merged from recent changes to main @bsipocz @ceb8

@ceb8
Copy link
Member Author

ceb8 commented Jan 20, 2022

@jaymedina Yes, a rebase is definitely in order, if you do that and are still having issued with stray commits, let me know. We might have to back out your changes, then rebase, then add them back in.

@ceb8 ceb8 force-pushed the moving_target_tesscut branch 2 times, most recently from 6b04633 to 0b9c924 Compare January 20, 2022 22:00
@jaymedina
Copy link
Contributor

Heads up @ceb8 & @bsipocz : I'm going to move forward with those changes I made in commit 6e91621 unless there are any objections.

@jaymedina jaymedina force-pushed the moving_target_tesscut branch 3 times, most recently from 9110923 to 32c5844 Compare January 28, 2022 20:43
@jaymedina
Copy link
Contributor

jaymedina commented Jan 28, 2022

Since moving_target will now be a bool value, moving_target and objectname will now be required to go together as specified in the dosctrings. Tests will account for the possible user input combinations below:

  1. moving_target only
  2. coordinates only (correct)
  3. objectname only
  4. moving_target + coordinates
  5. moving_target + objectname (correct)
  6. coordinates + objectname
  7. moving_target + coordinates + objectname

Update: Written tests results

test_mast.py .........................................                                                              [100%]

=================================================== 41 passed in 1.08s ====================================================
test_mast_remote.py ..................s....................                                                         [100%]

======================================== 38 passed, 1 skipped in 377.37s (0:06:17) ========================================

@jaymedina
Copy link
Contributor

The old dependencies and readthedocs checks are failing from not having the recent merge. Is it alright if I rebase really quick @bsipocz ? I have a backup branch ready.

@jaymedina jaymedina force-pushed the moving_target_tesscut branch 2 times, most recently from ca87911 to ee0766d Compare January 29, 2022 01:05
@bsipocz
Copy link
Member

bsipocz commented Jan 29, 2022

The old dependencies and readthedocs checks are failing from not having the recent merge. Is it alright if I rebase really quick @bsipocz ? I have a backup branch ready.

No need to ask, do feel free to rebase, squash commits, etc as often as you need :)

@ceb8
Copy link
Member Author

ceb8 commented Jan 30, 2022

@jaymedina This is looking good. Is it ready to be merged, or are you planning to do anything else?

@jaymedina
Copy link
Contributor

@jaymedina This is looking good. Is it ready to be merged, or are you planning to do anything else?

Nope I’m done with the PR. Now just trying to figure out why the readthedocs check is failing, but the error messages aren’t giving me any hints.

@ceb8
Copy link
Member Author

ceb8 commented Jan 30, 2022

@jaymedina OK, I'll give it a last look over, and see whats up with the docs check in the next day or so.

docs/mast/mast.rst Outdated Show resolved Hide resolved
@ceb8 ceb8 merged commit b3b54e9 into astropy:main Jan 31, 2022
@ceb8
Copy link
Member Author

ceb8 commented Jan 31, 2022

Thanks @jaymedina !

@jaymedina
Copy link
Contributor

Thank you :) @ceb8

@jaymedina jaymedina deleted the moving_target_tesscut branch January 31, 2022 20:42
@bsipocz
Copy link
Member

bsipocz commented Jan 31, 2022

This needs a changelog entry, please open a separate PR for adding one, with using the number of this PR.

@bsipocz bsipocz modified the milestones: v4, v0.4.6 Jan 31, 2022
bsipocz added a commit that referenced this pull request Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants