askap-vast / vast-tools

A collection of tools that are useful for the VAST project and for exploration of results from the VAST Pipeline.
https://vast-survey.org/vast-tools/
MIT License
8 stars 0 forks source link

Exit nicely when invalid survey is requested for Source.skyview_contour_plot #482

Closed ddobie closed 1 year ago

ddobie commented 1 year ago

The current behaviour is okay for someone familiar with tracebacks, but for people less proficient in python the error handling is quite confusing:

/home/ddobie/vast-tools/vasttools/source.py:1685: UserWarning: SkyView fetch failed!
  warnings.warn("SkyView fetch failed!")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/vast-tools/vasttools/source.py:1676, in Source.skyview_contour_plot(self, index, survey, contour_levels, percentile, zscale, contrast, outfile, no_colorbar, title, save, size, force, plot_dpi)
   1675 try:
-> 1676     paths = SkyView.get_images(
   1677         position=self.measurements.iloc[index]['skycoord'],
   1678         survey=[survey], radius=size
   1679     )
   1680     path_fits = paths[0][0]

File ~/user-conda-envs/vast-tools-dev/lib/python3.9/site-packages/astroquery/skyview/core.py:200, in SkyViewClass.get_images(self, position, survey, coordinates, projection, pixels, scaling, sampler, resolver, deedger, lut, grid, gridlabels, radius, height, width, cache, show_progress)
     93 """
     94 Query the SkyView service, download the FITS file that will be
     95 found and return a generator over the local paths to the
   (...)
    198 
    199 """
--> 200 readable_objects = self.get_images_async(position, survey, coordinates,
    201                                          projection, pixels, scaling,
    202                                          sampler, resolver, deedger,
    203                                          lut, grid, gridlabels,
    204                                          radius=radius, height=height,
    205                                          width=width,
    206                                          cache=cache,
    207                                          show_progress=show_progress)
    208 return [obj.get_fits() for obj in readable_objects]

File ~/user-conda-envs/vast-tools-dev/lib/python3.9/site-packages/astroquery/skyview/core.py:221, in SkyViewClass.get_images_async(self, position, survey, coordinates, projection, pixels, scaling, sampler, resolver, deedger, lut, grid, gridlabels, radius, height, width, cache, show_progress)
    216 """
    217 Returns
    218 -------
    219 A list of context-managers that yield readable file-like objects
    220 """
--> 221 image_urls = self.get_image_list(position, survey, coordinates,
    222                                  projection, pixels, scaling, sampler,
    223                                  resolver, deedger, lut, grid,
    224                                  gridlabels, radius=radius,
    225                                  height=height, width=width,
    226                                  cache=cache)
    227 return [commons.FileContainer(url, encoding='binary',
    228                               show_progress=show_progress)
    229         for url in image_urls]

File ~/user-conda-envs/vast-tools-dev/lib/python3.9/site-packages/astroquery/skyview/core.py:251, in SkyViewClass.get_image_list(self, position, survey, coordinates, projection, pixels, scaling, sampler, resolver, deedger, lut, grid, gridlabels, radius, width, height, cache)
    237 """
    238 Returns
    239 -------
   (...)
    248  u'http://skyview.gsfc.nasa.gov/tempspace/fits/skv6183161285798_3.fits']
    249 """
--> 251 self._validate_surveys(survey)
    253 if radius is not None:

File ~/user-conda-envs/vast-tools-dev/lib/python3.9/site-packages/astroquery/skyview/core.py:320, in SkyViewClass._validate_surveys(self, surveys)
    319 if sv not in self._valid_surveys:
--> 320     raise ValueError("Survey is not among the surveys hosted "
    321                      "at skyview.  See list_surveys or "
    322                      "survey_dict for valid surveys.")

ValueError: Survey is not among the surveys hosted at skyview.  See list_surveys or survey_dict for valid surveys.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[32], line 1
----> 1 contour_plot = source.skyview_contour_plot(13, 'DSS-2')

File ~/vast-tools/vasttools/source.py:1686, in Source.skyview_contour_plot(self, index, survey, contour_levels, percentile, zscale, contrast, outfile, no_colorbar, title, save, size, force, plot_dpi)
   1684 except Exception as e:
   1685     warnings.warn("SkyView fetch failed!")
-> 1686     warnings.warn(e)
   1687     return
   1689 fig = plt.figure(figsize=(8, 8))

TypeError: expected string or bytes-like object