Skip to content

Commit

Permalink
adding uri/url load_data user docs, better error message on bad path
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed May 21, 2024
1 parent d4a36a2 commit 31ea0d6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/cubeviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,11 @@ For more details on the API, please see
:py:meth:`~jdaviz.core.helpers.ImageConfigHelper.load_regions_from_file`
and :py:meth:`~jdaviz.core.helpers.ImageConfigHelper.load_regions` methods
in Cubeviz.

Loading from a URL or URI
-------------------------

.. seealso::

:ref:`Load from URL or URI <load-data-uri>`
Imviz documentation describing load from URI/URL.
28 changes: 28 additions & 0 deletions docs/imviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ data entries into the viewer until after the parsing is complete::
imviz.show()


.. _load-data-uri:

Load data from a URI or URL
---------------------------

The examples above import data from a local file path, and also support loading remote
data from a URL or URI with :meth:`~jdaviz.core.helpers.ConfigHelper.load_data`.
URL. If the input is a string with a MAST URI, the file will be retrieved via
astroquery's `~astroquery.mast.ObservationsClass.download_file`. If the
input string is a URL, it will be retrieved via astropy with
`~astropy.utils.data.download_file`. Both methods support a
``cache`` argument, which will store the file locally. Cached downloads via astropy
are placed in the `astropy cache <https://docs.astropy.org/en/stable/utils/data.html>`_,
and URIs retrieved via astroquery can be saved to a path of your choice with
``local_path``::

from jdaviz import Imviz

uri = "mast:JWST/product/jw01345-o001_t021_nircam_clear-f200w_i2d.fits"
cache = True

# store the retrieved file in the current working directory:
local_path = "jw01345-o001_t021_nircam_clear-f200w_i2d.fits"

imviz = Imviz()
imviz.load_data(uri, cache=cache, local_path=local_path)
imviz.show()

Importing catalogs via the API
==============================

Expand Down
8 changes: 8 additions & 0 deletions docs/specviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,11 @@ The :py:meth:`~jdaviz.configs.specviz.helper.Specviz.load_data` method also take
an optional keyword argument ``concat_by_file``. When set to ``True``, the spectra
loaded in the :class:`~specutils.SpectrumList` will be concatenated together into one
combined spectrum per loaded file, which may be useful for MIRI observations, for example.

Loading from a URL or URI
-------------------------

.. seealso::

:ref:`Load from URL or URI <load-data-uri>`
Imviz documentation describing load from URI/URL.
8 changes: 8 additions & 0 deletions docs/specviz2d/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ the spectrum to be horizontal:
.. code-block:: python
specviz2d.load_data(filename, ext=7, transpose=True)
Loading from a URL or URI
-------------------------

.. seealso::

:ref:`Load from URL or URI <load-data-uri>`
Imviz documentation describing load from URI/URL.
5 changes: 5 additions & 0 deletions jdaviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ def download_uri_to_path(possible_uri, cache=False, local_path=None):
elif parsed_uri.scheme.lower() in ['http', 'https', 'ftp']:
return download_file(possible_uri, cache=cache)

elif parsed_uri.scheme == '':
raise ValueError(f"The data to load '{possible_uri}' cannot be parse as a "
f"URL or URI, and no existing local file is available "
f"at this path.")

else:
raise ValueError(f"URI {possible_uri} with scheme {parsed_uri.scheme} is not "
f"currently supported.")
Expand Down

0 comments on commit 31ea0d6

Please sign in to comment.