def test_complexattr_and_duplicate(): attr = va.Time((2011, 1, 1), (2011, 1, 1, 1)) pytest.raises(TypeError, lambda: attr & va.Time((2011, 2, 1), (2011, 2, 1, 1))) attr |= va.Source('foo') pytest.raises(TypeError, lambda: attr & va.Time((2011, 2, 1), (2011, 2, 1, 1)))
def product_search(base, time_range, date_time_start): if 'EIT' in base: wavelen = int(base[3:6]) product_results = Fido.search( avso.Time(time_range, date_time_start), avso.Source('SOHO'), avso.Instrument('EIT'), avso.Provider('SDAC'), avso.Wavelength(wavelen * avso.u.Angstrom, wavelen * avso.u.Angstrom)) elif 'MDI' in base: product_results = Fido.search(avso.Time(time_range, date_time_start), avso.Source('SOHO'), avso.Instrument('MDI'), avso.Provider('SDAC'), avso.Physobs('LOS_MAGNETIC_FIELD')) elif 'LASCO' in base: detector = base.split('_')[1] product_results = Fido.search(avso.Time(time_range, date_time_start), avso.Provider('SDAC'), avso.Source('SOHO'), avso.Instrument('LASCO'), avso.Detector(detector)) return product_results
def test_request_data_protocol(): responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**')) req = client.request_data(responses) req.wait() assert req._d['method'] == 'url' assert req._d['protocol'] == 'fits' responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'), attrs.Protocol('fits')) req = client.request_data(responses) req.wait() assert req._d['method'] == 'url' assert req._d['protocol'] == 'fits' responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'), attrs.Protocol('as-is')) req = client.request_data(responses) req.wait() assert req._d['method'] == 'url_quick' assert req._d['protocol'] == 'as-is'
def test_complexquery(): a1 = attrs.Series('foo1') a2 = attrs.Series('foo2') t1 = vso_attrs.Time('2012/01/01', '2013/1/2') t2 = vso_attrs.Time('2012/01/01', '2013/1/3') ans1 = jsoc.jsoc.and_(a1 | a2, t1 | t2) assert isinstance(ans1.attrs[0], AttrOr) assert isinstance(ans1.attrs[0].attrs[0], AttrAnd) assert isinstance(ans1.attrs[0].attrs[1], AttrAnd)
def test_check_request(): responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**')) req = client.request_data(responses) req.wait() assert req.status == 0
def test_request_data_error(): responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'), attrs.Protocol('foo')) with pytest.raises(TypeError): req = client.request_data(responses)
def test_and_nesting(): a = attr.and_( attrs.Level(0), attr.AttrAnd( (attrs.Instrument('EVE'), attrs.Time("2012/1/1", "2012/01/02")))) # Test that the nesting has been removed. assert len(a.attrs) == 3
def test_post_pass(): responses = client.search( vso_attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**')) aa = client.request_data(responses) tmpresp = aa._d assert tmpresp['protocol'] == 'fits' assert tmpresp['method'] == 'url'
def test_search_metadata(): metadata = client.search_metadata( vso_attrs.Time('2014-01-01T00:00:00', '2014-01-01T00:02:00'), attrs.Series('aia.lev1_euv_12s'), attrs.Wavelength(304 * u.AA)) assert isinstance(metadata, pd.DataFrame) assert metadata.shape == (11, 176) for i in metadata.index.values: assert (i.startswith('aia.lev1_euv_12s') and i.endswith('[304]'))
def test_wait_get(): responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**')) path = tempfile.mkdtemp() res = client.fetch(responses, path=path) assert isinstance(res, Results) assert res.total == 1
def test_get_request(): responses = client.search( vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**')) bb = client.request_data(responses) path = tempfile.mkdtemp() aa = client.get_request(bb, path=path) assert isinstance(aa, Results)
def test_results_filenames(): responses = client.search( vso_attrs.Time('2014/1/1T1:00:36', '2014/1/1T01:01:38'), attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**')) path = tempfile.mkdtemp() files = client.fetch(responses, path=path) assert isinstance(files, Results) assert len(files) == len(responses) for hmiurl in files: assert os.path.isfile(hmiurl)
def test_time_xor(): one = va.Time((2010, 1, 1), (2010, 1, 2)) a = one ^ va.Time((2010, 1, 1, 1), (2010, 1, 1, 2)) assert a == attr.AttrOr( [va.Time((2010, 1, 1), (2010, 1, 1, 1)), va.Time((2010, 1, 1, 2), (2010, 1, 2))]) a ^= va.Time((2010, 1, 1, 4), (2010, 1, 1, 5)) assert a == attr.AttrOr([ va.Time((2010, 1, 1), (2010, 1, 1, 1)), va.Time((2010, 1, 1, 2), (2010, 1, 1, 4)), va.Time((2010, 1, 1, 5), (2010, 1, 2)) ])
def test_path(client, tmpdir): """ Test that '{file}' is automatically appended to the end of a custom path if it is not specified. """ qr = client.search(va.Time('2011-06-07 06:33', '2011-06-07 06:33:08'), va.Instrument('aia'), va.Wavelength(171 * u.AA)) tmp_dir = tmpdir / "{file}" files = client.fetch(qr, path=tmp_dir) assert len(files) == 1 # The construction of a VSO filename is bonkers complex, so there is no # practical way to determine what it should be in this test, so we just # put it here. assert "aia_lev1_171a_2011_06_07t06_33_02_77z_image_lev1.fits" in files[0]
def test_post_wavelength(): responses = client.search( vso_attrs.Time('2010/07/30T13:30:00', '2010/07/30T14:00:00'), attrs.Series('aia.lev1_euv_12s'), attrs.Wavelength(193 * u.AA) | attrs.Wavelength(335 * u.AA), attrs.Notify('*****@*****.**')) aa = client.request_data(responses) [r.wait() for r in aa] tmpresp = aa[0]._d assert tmpresp['protocol'] == 'fits' assert tmpresp['method'] == 'url' assert tmpresp['count'] == '302' tmpresp = aa[1]._d assert tmpresp['protocol'] == 'fits' assert tmpresp['method'] == 'url' assert tmpresp['count'] == '302'
def test_vso_hmi(client, tmpdir): """ This is a regression test for https://github.com/sunpy/sunpy/issues/2284 """ res = client.search(va.Time('2017-09-02 23:52:00', '2017-09-02 23:54:00'), va.Instrument('HMI') | va.Instrument('AIA')) dr = client.make_getdatarequest(res) # Extract the DRIs from the request dris = dr.request.datacontainer.datarequestitem # 3 HMI series and one AIA assert len(dris) == 4 # For each DataRequestItem assert that there is only one series in it. for dri in dris: fileids = dri.fileiditem.fileid series = list(map(lambda x: x.split(':')[0], fileids)) assert all([s == series[0] for s in series])
def test_no_download(client): """ Test for https://github.com/sunpy/sunpy/issues/3292 """ class MockDownloader: download_called = False def __init__(self): pass def download(self, *args, **kwargs): download_called = True # this should fail stereo = (va.Detector('STEREO_B') & va.Instrument('EUVI') & va.Time('1900-01-01', '1900-01-01T00:10:00')) qr = client.search(stereo) downloader = MockDownloader() res = client.fetch(qr, wait=False, downloader=downloader) assert downloader.download_called is False assert res == Results()
def test_tables_all_types(): # Data retriver response objects drclient = Fido.search(a.Time('2012/3/4', '2012/3/6'), a.Instrument('lyra') | a.Instrument('rhessi')) drtables = drclient.tables assert isinstance(drtables, list) assert isinstance(drtables[0], Table) # VSO response objects vsoclient = Fido.search(va.Time('2011-06-07 06:33', '2011-06-07 06:33:08'), va.Instrument('aia'), va.Wavelength(171 * u.AA)) vsotables = vsoclient.tables assert isinstance(vsotables, list) assert isinstance(vsotables[0], Table) # JSOC response objects jsocclient = Fido.search( a.Time('2014-01-01T00:00:00', '2014-01-01T01:00:00'), a.jsoc.Series('hmi.v_45s'), a.jsoc.Notify('*****@*****.**')) jsoctables = jsocclient.tables assert isinstance(jsoctables, list) assert isinstance(jsoctables[0], Table)
def test_invalid_query(): with pytest.raises(ValueError): client.search(vso_attrs.Time('2012/1/1T01:00:00', '2012/1/1T01:00:45'))
def test_query(): Jresp = client.search( vso_attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:01:30'), attrs.Series('hmi.M_45s'), vso_attrs.Sample(90 * u.second)) assert isinstance(Jresp, JSOCResponse) assert len(Jresp) == 2
def test_vso_error(client): with pytest.warns(SunpyUserWarning, match="VSO-C500 :soap:Server.Transport : 404 Not Found"): client.search( va.Time('2019/12/30', '2019/12/31'), va.Instrument('ovsa'))
def test_Time_timerange(): t = va.Time(TimeRange('2012/1/1', '2012/1/2')) assert isinstance(t, va.Time) assert t.min == datetime.datetime(2012, 1, 1) assert t.max == datetime.datetime(2012, 1, 2)
def test_basicquery(): a1 = attrs.Series('foo') t1 = vso_attrs.Time('2012/01/01', '2013/1/2') ans1 = jsoc.jsoc.and_(a1, t1) assert isinstance(ans1, AttrAnd) assert len(ans1.attrs) == 2
def vso_time(self): return v_attrs.Time( datetime.strptime(self['event_starttime'], "%Y-%m-%dT%H:%M:%S"), datetime.strptime(self['event_endtime'], "%Y-%m-%dT%H:%M:%S") )
def test_input_error(): with pytest.raises(ValueError): va.Time('2012/1/1')
def test_post_notify_fail(): responses = client.search( vso_attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'), attrs.Series('hmi.M_45s')) with pytest.raises(ValueError): client.request_data(responses)
def test_complexattr_or_eq(): attr = va.Time((2011, 1, 1), (2011, 1, 1, 1)) assert attr | attr == attr assert attr | va.Time((2011, 1, 1), (2011, 1, 1, 1)) == attr
def test_post_wave_series(): with pytest.raises(TypeError): client.search( vso_attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'), attrs.Series('hmi.M_45s') | attrs.Series('aia.lev1_euv_12s'), attrs.Wavelength(193 * u.AA) | attrs.Wavelength(335 * u.AA))