示例#1
0
def test_time_range():
    rows = [{'Start Time': parse_time("2020/01/01"), 'End Time': parse_time("2020/01/02")},
            {'Start Time': parse_time("2019/01/01"), 'End Time': parse_time("2019/01/02")}]
    resp = QueryResponse(rows)

    assert resp.time_range().start == parse_time("2019/01/01")
    assert resp.time_range().end == parse_time("2020/01/02")
示例#2
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/1 23:59:59'
    obj = {
        'Start Time':
        parse_time(start),
        'End Time':
        parse_time(end),
        'Instrument':
        'EVE',
        'Physobs':
        'irradiance',
        'Source':
        'SDO',
        'Provider':
        'LASP',
        'Level':
        '0',
        'url': ('http://lasp.colorado.edu/eve/data_access/evewebdata/'
                'quicklook/L0CS/SpWx/2016/20160101_EVE_L0CS_DIODES_1m.txt')
    }
    results = QueryResponse([obj], client=LCClient)
    return results
示例#3
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/1 23:59:59'
    obj = {
        'Start Time':
        parse_time(start),
        'End Time':
        parse_time(end),
        'Instrument':
        'LYRA',
        'Physobs':
        'irradiance',
        'Source':
        'PROBA2',
        'Provider':
        'ESA',
        'Level':
        '2',
        'url': ('http://proba2.oma.be/lyra/data/bsd/2016/01/01/'
                'lyra_20160101-000000_lev2_std.fits')
    }
    results = QueryResponse([obj], client=LCClient)
    return results
示例#4
0
def mock_query_object(start_date, end_date):
    """
    Creation of a QueryResponse object, and prefill some
    downloaded data from noaa.NOAAIndicesClient().fetch(Time('20 ..)
    """
    # Create a mock Query Response object
    start = parse_time(start_date)
    end = parse_time(end_date)
    obj = {
        'Start Time':
        parse_time(start),
        'End Time':
        parse_time(end),
        'Instrument':
        'NOAA-Indices',
        'Physobs':
        'sunspot number',
        'Source':
        'SIDC',
        'Provider':
        'SWPC',
        'url':
        'https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json'
    }
    results = QueryResponse([obj], client=noaa.NOAAIndicesClient())
    return results
示例#5
0
def mock_query_object(timerange):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = timerange.start
    end = timerange.end
    wave = 17 * u.GHz
    delta = end - start
    resp = []
    for i in range(delta.datetime.days + 1):
        start_time = start.datetime + timedelta(days=i)
        end_time = start_time + timedelta(days=1) - timedelta(milliseconds=1)
        obj = {
            'Start Time': parse_time(start_time),
            'End Time': parse_time(end_time),
            'Instrument': 'NORH',
            'Source': 'NAOJ',
            'Provider': 'NRO',
            'Wavelength': wave,
            'url': create_url(start_time, wave)
        }
        resp.append(obj)
    results = QueryResponse(resp, client=norh.NoRHClient())
    return results
示例#6
0
def mock_query_object(suvi_client):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2019/05/25 00:50'
    end = '2019/05/25 00:52'
    wave = 94 * u.Angstrom
    obj = {
        'Start Time':
        parse_time(start),
        'End Time':
        parse_time(end),
        'Instrument':
        'SUVI',
        'Physobs':
        'flux',
        'Source':
        'GOES',
        'Provider':
        'NOAA',
        'Level':
        '2',
        'Wavelength':
        wave,
        'url':
        ('https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites'
         '/goes/goes16/l2/data/suvi-l2-ci094/2019/05/25/'
         'dr_suvi-l2-ci094_g16_s20190525T005200Z_e20190525T005600Z_v1-0-0.fits'
         )
    }
    results = QueryResponse([obj], client=suvi_client)
    return results
示例#7
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/1 23:59:59'
    obj = {
        'Start Time':
        parse_time(start),
        'End Time':
        parse_time(end),
        'Instrument':
        'GBM',
        'Physobs':
        'flux',
        'Source':
        'FERMI',
        'Provider':
        'NASA',
        'Resolution':
        'cspec',
        'Detector':
        'n5',
        'url': ('https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/'
                '2016/01/01/current/glg_cspec_n5_160101_v00.pha')
    }
    results = QueryResponse([obj], client=LCClient)
    return results
示例#8
0
def mock_query_object(suvi_client):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2019/05/25 00:50'
    end = '2019/05/25 00:52'
    wave = 94 * u.Angstrom
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'GOES',
        'instrument': 'SUVI',
        'physobs': 'flux',
        'provider': 'NOAA',
        'wavelength': wave
    }
    urls = [
        'https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites'
        '/goes/goes16/l2/data/suvi-l2-ci094/2019/05/25/'
        'dr_suvi-l2-ci094_g16_s20190525T005200Z_e20190525T005600Z_v1-0-0.fits'
    ]
    results = QueryResponse.create(obj, urls, client=suvi_client)
    return results
示例#9
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/1 23:59:59'
    obj = {
        'Start Time':
        parse_time(start),
        'End Time':
        parse_time(end),
        'Instrument':
        'RHESSI',
        'Physobs':
        'irradiance',
        'Source':
        'RHESSI',
        'Provider':
        'NASA',
        'url': ('https://hesperia.gsfc.nasa.gov/hessidata/metadata/'
                'catalog/hsi_obssumm_20160101_078.fits')
    }
    results = QueryResponse([obj], client=LCClient)
    return results
示例#10
0
def test_reprs():
    rowdict = {}
    rowdict['Start Time'] = parse_time("2012/1/1")
    rowdict['End Time'] = parse_time("2012/1/2")
    resp = QueryResponse([rowdict])
    assert isinstance(resp, QueryResponse)
    strs = ["2012-01-01T00:00:00.000", "2012-01-02T00:00:00.000"]
    assert all(s in str(resp) for s in strs)
    assert all(s in repr(resp) for s in strs)
示例#11
0
def test_reprs():
    map_ = {}
    map_['Time_start'] = parse_time("2012/1/1")
    map_['Time_end'] = parse_time("2012/1/2")
    resp = QueryResponse.create(map_, [''])
    assert isinstance(resp, QueryResponse)
    strs = ["2012-01-01 00:00:00", "2012-01-02 00:00:00"]
    assert all(s in str(resp) for s in strs)
    assert all(s in repr(resp) for s in strs)
示例#12
0
    def search(self, *args, **kwargs):
        baseurl, pattern, matchdict = self.pre_search_hook(*args, **kwargs)
        metalist = []
        for obs in matchdict['Observatory']:
            scraper = Scraper(baseurl.format(obs=self.observatory_map[obs.title()]), regex=True)
            tr = TimeRange(matchdict['Start Time'], matchdict['End Time'])
            filesmeta = scraper._extract_files_meta(tr, extractor=pattern,
                                                    matcher=matchdict)

            for i in filesmeta:
                rowdict = self.post_search_hook(i, matchdict)
                metalist.append(rowdict)

        return QueryResponse(metalist, client=self)
def mock_querry_object(suvi_client, start, end):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'GOES',
        'instrument': 'SUVI',
        'physobs': 'flux',
        'provider': 'NOAA'
    }
    results = QueryResponse.create(
        obj, suvi_client._get_url_for_timerange(TimeRange(start, end)))
    results.client = suvi_client
    return results
示例#14
0
def mock_query_object(start_date, end_date):
    """
    Creation of a QueryResponse object, and prefill some
    downloaded data from noaa.NOAAIndicesClient().fetch(Time('20 ..)
    """
    # Create a mock QueryResponse object
    map_ = {
        'TimeRange': TimeRange(parse_time(start_date), parse_time(end_date)),
        'Time_start': parse_time(start_date),
        'Time_end':  parse_time(end_date),
        'source': 'sdic',
        'instrument': 'noaa-indices',
        'physobs': 'sunspot number',
        'provider': 'swpc'
    }

    resp = QueryResponse.create(map_, LCClient._get_url_for_timerange(None), client=LCClient)
    return resp
示例#15
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/1 23:59:59'
    obj = {
        'Start Time': parse_time(start),
        'End Time': parse_time(end),
        'Instrument': 'GOES',
        'Physobs': 'irradiance',
        'Source': 'GOES',
        'Provider': 'NOAA',
        'SatelliteNumber': '15',
        'url': 'https://umbra.nascom.nasa.gov/goes/fits/2016/go1520160101.fits'
    }
    results = QueryResponse([obj], client=LCClient)
    return results
示例#16
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/1 23:59:59'
    wave = 17 * u.GHz
    obj = {
        'Start Time': parse_time(start),
        'End Time': parse_time(end),
        'Instrument': 'NORH',
        'Source': 'NAOJ',
        'Provider': 'NRO',
        'Wavelength': wave,
        'url':
        'ftp://solar-pub.nao.ac.jp/pub/nsro/norh/data/tcx/2016/01/tca160101'
    }
    results = QueryResponse([obj], client=LCClient)
    return results
示例#17
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/2'
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'nasa',
        'instrument': 'goes',
        'physobs': 'irradiance',
        'provider': 'sdac'
    }
    urls = ['https://umbra.nascom.nasa.gov/goes/fits/2016/go1520160101.fits',
            'https://umbra.nascom.nasa.gov/goes/fits/2016/go1520160102.fits']
    results = QueryResponse.create(obj, urls, client=LCClient)
    return results
示例#18
0
def mock_query_object(start_date, end_date):
    """
    Creation of a QueryResponse object, and prefill some
    downloaded data from noaa.NOAAIndicesClient().fetch(Time('20 ..)
    """
    # Create a mock QueryResponse object
    map_ = {
        'TimeRange': TimeRange(parse_time(start_date), parse_time(end_date)),
        'Time_start': parse_time(start_date),
        'Time_end':  parse_time(end_date),
        'source': 'sdic',
        'instrument': 'noaa-indices',
        'physobs': 'sunspot number',
        'provider': 'swpc'
    }

    resp = QueryResponse.create(map_, LCClient._get_default_uri())
    # Attach the client with the QueryResponse
    resp.client = LCClient
    return resp
示例#19
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/2'
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'FERMI',
        'instrument': 'GBM',
        'physobs': 'flux',
        'provider': 'NASA'
    }
    urls = ['https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/'
            '2016/01/01/current/glg_cspec_n5_160101_v00.pha',
            'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/'
            '2016/01/02/current/glg_cspec_n5_160102_v00.pha']
    results = QueryResponse.create(obj, urls, client=LCClient)
    return results
示例#20
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/2'
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'rhessi',
        'instrument': 'rhessi',
        'physobs': 'irradiance',
        'provider': 'nasa'
    }
    urls = [
        'https://hesperia.gsfc.nasa.gov/hessidata/metadata/catalog/hsi_obssumm_20160101_078.fits',
        'https://hesperia.gsfc.nasa.gov/hessidata/metadata/catalog/hsi_obssumm_20160102_084.fits'
    ]
    results = QueryResponse.create(obj, urls, client=LCClient)
    return results
示例#21
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/2'
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'Proba2',
        'instrument': 'lyra',
        'physobs': 'irradiance',
        'provider': 'esa'
    }
    urls = [
        'http://proba2.oma.be/lyra/data/bsd/2016/01/01/lyra_20160101-000000_lev2_std.fits',
        'http://proba2.oma.be/lyra/data/bsd/2016/01/02/lyra_20160102-000000_lev2_std.fits'
    ]
    results = QueryResponse.create(obj, urls, client=LCClient)
    return results
示例#22
0
    def search(self, *args, **kwargs):
        """
        Query this client for a list of results.

        Parameters
        ----------
        *args: `tuple`
            `sunpy.net.attrs` objects representing the query.
        **kwargs: `dict`
            Any extra keywords to refine the search.

        Returns
        -------
        A `QueryResponse` instance containing the query result.
        """
        matchdict = self._get_match_dict(*args, **kwargs)
        req_wave = matchdict.get('Wavelength', None)
        receivers = RECEIVER_FREQUENCIES.keys()
        if req_wave is not None:
            receivers = self._check_wavelengths(req_wave)

        metalist = []
        start_year = matchdict['Start Time'].datetime.year
        end_year = matchdict['End Time'].datetime.year
        tr = TimeRange(matchdict['Start Time'], matchdict['End Time'])
        for receiver in receivers:
            for year in range(start_year, end_year + 1):
                urlpattern = self.baseurl.format(Wavelength=receiver,
                                                 year=year,
                                                 ext=RECEIVER_EXT[receiver])
                scraper = Scraper(urlpattern, regex=True)
                filesmeta = scraper._extract_files_meta(tr,
                                                        extractor=self.pattern)
                for i in filesmeta:
                    rowdict = self.post_search_hook(i, matchdict)
                    metalist.append(rowdict)

        return QueryResponse(metalist, client=self)
示例#23
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/2'
    wave = 17000000 * u.kHz
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'NAOJ',
        'instrument': 'NORH',
        'physobs': '',
        'provider': 'NRO',
        'wavelength': wave
    }
    urls = [
        'ftp://solar-pub.nao.ac.jp/pub/nsro/norh/data/tcx/2016/01/tca160101',
        'ftp://solar-pub.nao.ac.jp/pub/nsro/norh/data/tcx/2016/01/tca160102'
    ]
    results = QueryResponse.create(obj, urls, client=LCClient)
    return results
示例#24
0
def mock_query_object(LCClient):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = '2016/1/1'
    end = '2016/1/2'
    obj = {
        'TimeRange': TimeRange(parse_time(start), parse_time(end)),
        'Time_start': parse_time(start),
        'Time_end': parse_time(end),
        'source': 'SDO',
        'instrument': 'eve',
        'physobs': 'irradiance',
        'provider': 'LASP'
    }
    urls = [
        'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/'
        '2016/20160101_EVE_L0CS_DIODES_1m.txt',
        'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/'
        '2016/20160102_EVE_L0CS_DIODES_1m.txt'
    ]
    results = QueryResponse.create(obj, urls, client=LCClient)
    return results
示例#25
0
def test_missing_time_range():
    rows = [{'wibble': 1}]
    resp = QueryResponse(rows)

    assert resp.time_range() is None