Skip to content

Commit

Permalink
Download methods to FileManager for quality and movie
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Apr 27, 2023
1 parent 17721d3 commit be7e206
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dkist/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def from_directory(cls, directory):
elif len(asdf_files) > 1:
raise NotImplementedError("Multiple asdf files found in this "
"directory. Use from_asdf to specify which "
"one to use.") # pragma: no cover
"one to use.") # pragma: no cover

asdf_file = asdf_files[0]

Expand Down
68 changes: 66 additions & 2 deletions dkist/io/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import dask.array
import numpy as np
from parfive import Downloader

try:
from numpy.typing import DTypeLike, NDArray # NOQA
Expand Down Expand Up @@ -314,6 +315,69 @@ def __init__(self, fits_loader: StripedExternalArray):
# be populated with a reference to that Dataset instance.
self._ndcube = None

@property
def _metadata_streamer_url(self):
# Import here to avoid circular import
from dkist.net import conf

return conf.download_endpoint

def quality_report(self, path=None, overwrite=None):
"""
Download the quality report PDF.
Parameters
----------
path: `str` or `pathlib.Path`
The destination path to save the file to. See
`parfive.Downloader.simple_download` for details.
The default path is ``.basepath``, if ``.basepath`` is None it will
default to `~/`.
overwrite: `bool`
Set to `True` to overwrite file if it already exists. See
`parfive.Downloader.simple_download` for details.
Returns
-------
results: `parfive.Results`
A `~parfive.Results` obejct containing the filepath of the
downloaded file if the download was successful, and any errors if it
was not.
"""
dataset_id = self._ndcube.meta['inventory']['datasetId']
url = f"{self._metadata_streamer_url}/quality?datasetId={dataset_id}"
if path is None and self.basepath:
path = self.basepath
return Downloader.simple_download([url], path=path, overwrite=overwrite)

def preview_movie(self, path=None, overwrite=None):
"""
Download the preview movie.
Parameters
----------
path: `str` or `pathlib.Path`
The destination path to save the file to. See
`parfive.Downloader.simple_download` for details.
The default path is ``.basepath``, if ``.basepath`` is None it will
default to `~/`.
overwrite: `bool`
Set to `True` to overwrite file if it already exists. See
`parfive.Downloader.simple_download` for details.
Returns
-------
results: `parfive.Results`
A `~parfive.Results` obejct containing the filepath of the
downloaded file if the download was successful, and any errors if it
was not.
"""
dataset_id = self._ndcube.meta['inventory']['datasetId']
url = f"{self._metadata_streamer_url}/movie?datasetId={dataset_id}"
if path is None and self.basepath:
path = self.basepath
return Downloader.simple_download([url], path=path, overwrite=overwrite)

def download(self, path=None, destination_endpoint=None, progress=True, wait=True, label=None):
"""
Start a Globus file transfer for all files in this Dataset.
Expand All @@ -323,8 +387,8 @@ def download(self, path=None, destination_endpoint=None, progress=True, wait=Tru
path : `pathlib.Path` or `str`, optional
The path to save the data in, must be accessible by the Globus
endpoint.
The default value is ``.basepath``, if this is None it will default
to ``/~/``.
The default value is ``.basepath``, if ``.basepath`` is None it will
default to ``/~/``.
It is possible to put placeholder strings in the path with any key
from the dataset inventory dictionary which can be accessed as
``ds.meta['inventory']``. An example of this would be
Expand Down

0 comments on commit be7e206

Please sign in to comment.