Add cutouts for casda#2366
Conversation
bsipocz
left a comment
There was a problem hiding this comment.
I mostly have nitpick comments.
The bigger point is that I feel the module would benefit if the baseclass would be updated to be QueryWithLogin to help with admining the authentication, following the API of the other modules that deal with the need of authentication.
| right = fk5_coords.ra.degree + (width/2) | ||
| pos = 'RANGE {} {} {} {}'.format(left, right, bottom, top) | ||
| else: | ||
| pos = 'CIRCLE {} {} {}'.format(fk5_coords.ra.degree, fk5_coords.dec.degree, 1*u.arcmin.to(u.deg)) |
There was a problem hiding this comment.
would it be possible to bring this 1 arcmin default out somewhere to be as a default?
I see that it would change the current API behaviour (there is already a minor change to default from ValueError to this default) to change that height+width takes the first case in the conditional then radius could be defaulted to the 1archmin in the signature?
There was a problem hiding this comment.
I've moved this to the signature of the query_region_async , _args_to_payload and cutout functions.
| if (band[0] is not None and not isinstance(band[0], u.Quantity)) or (band[1] is not None and not isinstance(band[1], u.Quantity)): | ||
| raise ValueError("The 'band' value must be a list of 2 wavelength or frequency values.") | ||
| if band[0] is not None and band[1] is not None and band[0].unit.physical_type != band[1].unit.physical_type: | ||
| raise ValueError("The 'band' values must have the same kind of units.") | ||
| if band[0] is not None or band[1] is not None: |
There was a problem hiding this comment.
nitpick: I feel these could be simplified a bit to not check the same things repeativly? (Though nested conditionals may not be that nice an alternative either).
There was a problem hiding this comment.
I tried out a few approaches to simplifying these but none made it much better. I've pull out the band[0] is not None code into variables to hopefully make it more readable though.
| request_payload['BAND'] = '{} {}'.format(min_band, max_band) | ||
|
|
||
| if kwargs.get('channel') is not None: | ||
| channel = kwargs.get('channel') |
There was a problem hiding this comment.
nitpick: you could bring this out from the conditional, avoiding calling get() twice. Same for band above.
| if not isinstance(channel, (list, tuple)) or len(channel) != 2: | ||
| raise ValueError("The 'channel' value must be a list of 2 integer values.") | ||
| if (not isinstance(channel[0], int)) or (not isinstance(channel[1], int)): | ||
| raise ValueError("The 'channel' value must be a list of 2 integer values.") |
There was a problem hiding this comment.
nitpick: Maybe have just one long check to avoid duplicates?
| bottom = fk5_coords.dec.degree + (height/2) | ||
| left = fk5_coords.ra.degree - (width/2) | ||
| right = fk5_coords.ra.degree + (width/2) | ||
| pos = 'RANGE {} {} {} {}'.format(left, right, top, bottom) |
There was a problem hiding this comment.
nitpick: using f-strings maybe easier/nicer to read here and elsewhere?
There was a problem hiding this comment.
Change made - that's the first time I have encountered f-strings so thank-you for the suggestion.
There was a problem hiding this comment.
yes, we couldn't really use them for a long time, but fortunately, we now dropped the old python versions that don't have it.
| log.info("Adding parameters: " + str(cutout_spec)) | ||
| resp = self._request('POST', job_location + '/parameters', data=cutout_spec, cache=False) | ||
| resp.raise_for_status() | ||
| return |
| width : str or `astropy.units.Quantity`, optional | ||
| the width for a box cutout | ||
| band : list of `astropy.units.Quantity` with two elements, optional | ||
| the spectral range to be included, may be low and high wavelengths in metres or low and high frequencies in Hertz. Use None for an open bound. |
There was a problem hiding this comment.
nitpick: this is a bit long, please break the line at 120 or shorter
There was a problem hiding this comment.
I've updated all code in this file to be 120 characters or less
| The cutout support in AstroQuery allows both spatial and spectral cutouts. | ||
| To produce a spatial cutout, pass in a coordinate and either a radius or a height and a width to the :meth:`~astroquery.casda.CasdaClass.cutout` method. | ||
| To produce a spectral cutout, pass in either a band or a channel value. | ||
| For band, the value must be a list or tuple of two `astropy.units.Quantity` objects specifying a low and high frequency or wavelength. For an open ended range use `None` as the open value. |
There was a problem hiding this comment.
I've updated the newly added content to be 120 characters or less
| >>> import getpass | ||
| >>> centre = coordinates.SkyCoord.from_name('2MASX J08161181-7039447') | ||
| >>> username = 'email@somewhere.edu.au' | ||
| >>> password = getpass.getpass(str("Enter your OPAL password: ")) |
There was a problem hiding this comment.
Overall it would be beneficial to switch to use the authenticated baseclass: QueryWithLogin, it would help you deal with the password promts to follow the usual way we do it in other modules.
|
|
||
| @pytest.mark.skipif(('CASDA_USER' not in os.environ or | ||
| 'CASDA_PASSWD' not in os.environ), | ||
| reason='Requires real CASDA user/password (CASDA_USER ' |
There was a problem hiding this comment.
Long term it would be nice to figure out some test user that we could use for testing purposes. E.g password stored as a token, or it would have access only some limited test data, etc.
It might be best to do that as a separate PR, however I will start on it immediately so that both changes are in the same release |
Yes, I agree that it's beyond the scope here and would better be in a separate PR. |
Codecov Report
@@ Coverage Diff @@
## main #2366 +/- ##
==========================================
+ Coverage 63.17% 63.29% +0.12%
==========================================
Files 132 132
Lines 17187 17241 +54
==========================================
+ Hits 10858 10913 +55
+ Misses 6329 6328 -1
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
bsipocz
left a comment
There was a problem hiding this comment.
Thank you! I'll commit the one misunderstanding in the previous review and merge once tests pass.
| bottom = fk5_coords.dec.degree + (height/2) | ||
| left = fk5_coords.ra.degree - (width/2) | ||
| right = fk5_coords.ra.degree + (width/2) | ||
| pos = 'RANGE {} {} {} {}'.format(left, right, top, bottom) |
There was a problem hiding this comment.
yes, we couldn't really use them for a long time, but fortunately, we now dropped the old python versions that don't have it.
944f149 to
c69651f
Compare
Thanks for the review! If you have an example of the approach you want with kwarg I can make the change |
Also include support for numpy arrays for band and channel, and autocorrect the band and channel values to be in ascending order
|
Thanks @jd-au! |
Added the ability to produce spatial and spectral cutouts from ASKAP images and cubes using CASDA's SODA implementation.