Example #1
0
 def get(self,
         query_response,
         path=None,
         methods=('URL-FILE', ),
         downloader=None):
     """
     Download data specified in the query_response.
     
     Parameters
     ----------
     query_response : sunpy.net.vso.QueryResponse
         QueryResponse containing the items to be downloaded.
     path : str
         Specify where the data is to be downloaded. Can refer to arbitrary
         fields of the QueryResponseItem (instrument, source, time, ...) via
         string formatting, moreover the file-name of the file downloaded can
         be refered to as file, e.g.
         "{source}/{instrument}/{time.start}/{file}".
     methods : {list of str}
         Methods acceptable to user.
     downloader : sunpy.net.downloader.Downloader
         Downloader used to download the data.
     
     Returns
     -------
     out : :py:class:`Results` object that supplies a list of filenames with meta attributes containing the respective QueryResponse.
     
     Examples
     --------
     >>> res = get(qr).wait()
     """
     if downloader is None:
         downloader = download.Downloader()
         thread = threading.Thread(target=downloader.reactor.run)
         thread.daemon = True
         thread.start()
         res = Results(lambda _: downloader.reactor.stop(), 1,
                       lambda mp: self.link(query_response, mp))
     else:
         res = Results(lambda _: None, 1,
                       lambda mp: self.link(query_response, mp))
     if path is None:
         path = os.path.join(tempfile.mkdtemp(), '{file}')
     fileids = VSOClient.by_fileid(query_response)
     if not fileids:
         res.poke()
         return res
     self.download_all(
         self.api.service.GetData(
             self.make_getdatarequest(query_response, methods)), methods,
         downloader, path, fileids, res)
     res.poke()
     return res
Example #2
0
    def fetch(self,
              query_response,
              path=None,
              methods=('URL-FILE_Rice', 'URL-FILE'),
              downloader=None,
              site=None):
        """
        Download data specified in the query_response.

        Parameters
        ----------
        query_response : sunpy.net.vso.QueryResponse
            QueryResponse containing the items to be downloaded.

        path : str
            Specify where the data is to be downloaded. Can refer to arbitrary
            fields of the QueryResponseItem (instrument, source, time, ...) via
            string formatting, moreover the file-name of the file downloaded can
            be referred to as file, e.g.
            "{source}/{instrument}/{time.start}/{file}".

        methods : {list of str}
            Download methods, defaults to URL-FILE_Rice then URL-FILE.
            Methods are a concatenation of one PREFIX followed by any number of
            SUFFIXES i.e. `PREFIX-SUFFIX_SUFFIX2_SUFFIX3`.
            The full list of
            `PREFIXES <http://sdac.virtualsolar.org/cgi/show_details?keyword=METHOD_PREFIX>`_
            and `SUFFIXES <http://sdac.virtualsolar.org/cgi/show_details?keyword=METHOD_SUFFIX>`_
            are listed on the VSO site.

        downloader : sunpy.net.downloader.Downloader
            Downloader used to download the data.

        site : str
            There are a number of caching mirrors for SDO and other
            instruments, some available ones are listed below.

            =============== ========================================================
            NSO             National Solar Observatory, Tucson (US)
            SAO  (aka CFA)  Smithonian Astronomical Observatory, Harvard U. (US)
            SDAC (aka GSFC) Solar Data Analysis Center, NASA/GSFC (US)
            ROB             Royal Observatory of Belgium (Belgium)
            MPS             Max Planck Institute for Solar System Research (Germany)
            UCLan           University of Central Lancashire (UK)
            IAS             Institut Aeronautique et Spatial (France)
            KIS             Kiepenheuer-Institut fur Sonnenphysik Germany)
            NMSU            New Mexico State University (US)
            =============== ========================================================

        Returns
        -------
        out : :py:class:`Results`
            Object that supplies a list of filenames with meta attributes
            containing the respective QueryResponse.

        Examples
        --------
        >>> res = fetch(qr).wait() # doctest:+SKIP
        """
        if downloader is None:
            downloader = download.Downloader()
            downloader.init()
            res = download.Results(lambda _: downloader.stop(), 1,
                                   lambda mp: self.link(query_response, mp))
        else:
            res = download.Results(lambda _: None, 1,
                                   lambda mp: self.link(query_response, mp))
        if path is None:
            path = os.path.join(config.get('downloads', 'download_dir'),
                                '{file}')
        elif isinstance(path, str) and '{file}' not in path:
            path = os.path.join(path, '{file}')
        path = os.path.expanduser(path)

        fileids = VSOClient.by_fileid(query_response)
        if not fileids:
            res.poke()
            return res
        # Adding the site parameter to the info
        info = {}
        if site is not None:
            info['site'] = site

        self.download_all(
            self.api.service.GetData(
                self.make_getdatarequest(query_response, methods, info)),
            methods, downloader, path, fileids, res)
        res.poke()
        return res
Example #3
0
File: vso.py Project: tdunn19/sunpy
 def get(self, query_response, path=None, methods=('URL-FILE',), downloader=None, site=None):
     """
     Download data specified in the query_response.
     
     Parameters
     ----------
     query_response : sunpy.net.vso.QueryResponse
         QueryResponse containing the items to be downloaded.
     path : str
         Specify where the data is to be downloaded. Can refer to arbitrary
         fields of the QueryResponseItem (instrument, source, time, ...) via
         string formatting, moreover the file-name of the file downloaded can
         be refered to as file, e.g.
         "{source}/{instrument}/{time.start}/{file}".
     methods : {list of str}
         Methods acceptable to user.
     downloader : sunpy.net.downloader.Downloader
         Downloader used to download the data.
     site: str
         There are a number of caching mirrors for SDO and other
         instruments, some available ones are listed below.
             NSO   : National Solar Observatory, Tucson (US)
             SAO  (aka CFA)  : Smithonian Astronomical Observatory, Harvard U. (US)
             SDAC (aka GSFC) : Solar Data Analysis Center, NASA/GSFC (US)
             ROB   : Royal Observatory of Belgium (Belgium)
             MPS   : Max Planck Institute for Solar System Research (Germany)
             UCLan : University of Central Lancashire (UK)
             IAS   : Institut Aeronautique et Spatial (France)
             KIS   : Kiepenheuer-Institut fur Sonnenphysik Germany)
             NMSU  : New Mexico State University (US)
     
     Returns
     -------
     out : :py:class:`Results` object that supplies a list of filenames with meta attributes containing the respective QueryResponse.
     
     Examples
     --------
     >>> res = get(qr).wait()
     """
     if downloader is None:
         downloader = download.Downloader()
         thread = threading.Thread(target=downloader.reactor.run)
         thread.daemon = True
         thread.start()
         res = Results(
             lambda _: downloader.reactor.stop(), 1,
             lambda mp: self.link(query_response, mp)
         )
     else:
         res = Results(
             lambda _: None, 1, lambda mp: self.link(query_response, mp)
         )
     if path is None:
         path = os.path.join(config.get('downloads','download_dir'),
                             '{file}')
     fileids = VSOClient.by_fileid(query_response)
     if not fileids:
         res.poke()
         return res
     # Adding the site parameter to the info
     info = {}
     if site is not None:
         info['site']=site
     
     self.download_all(
         self.api.service.GetData(
             self.make_getdatarequest(query_response, methods, info)
             ),
         methods, downloader, path,
         fileids, res
     )
     res.poke()
     return res