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_attror_and(): attr = va.Instrument('foo') | va.Instrument('bar') one = attr & va.Source('bar') other = ( (va.Instrument('foo') & va.Source('bar')) | (va.Instrument('bar') & va.Source('bar')) ) assert one == other
def test_QueryResponse_build_table_defaults(): records = (MockQRRecord(), ) qr = vso.QueryResponse(records) table = qr.build_table() start_time_ = table['Start Time'] assert len(start_time_) == 1 assert start_time_[0] == 'None' end_time_ = table['End Time'] assert len(end_time_) == 1 assert end_time_[0] == 'None' type_ = table['Type'].data assert len(type_) == 1 assert type_[0] == 'N/A' # Check values we did set by default in 'MockQRRecord' source_ = table['Source'].data assert len(source_) == 1 assert source_[0] == str(va.Source('SOHO')) instrument_ = table['Instrument'].data assert len(instrument_) == 1 assert instrument_[0] == str(va.Instrument('aia'))
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 __init__(self, start_time=None, end_time=None, size=0, source='SOHO', instrument='aia', extent_type=None): self.size = size self.time = MockObject(start=start_time, end=end_time) self.source = va.Source(source) self.instrument = va.Instrument(instrument) self.extent = MockObject(type=None if extent_type is None else extent_type.type)
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_simpleattr_and_duplicate(): attr = va.Instrument('foo') pytest.raises(TypeError, lambda: attr & va.Instrument('bar')) attr |= va.Source('foo') pytest.raises(TypeError, lambda: attr & va.Instrument('bar')) otherattr = va.Instrument('foo') | va.Source('foo') pytest.raises(TypeError, lambda: attr & otherattr) pytest.raises(TypeError, lambda: (attr | otherattr) & va.Instrument('bar')) tst = va.Instrument('foo') & va.Source('foo') pytest.raises(TypeError, lambda: tst & tst)
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_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_or_nesting(): a = attr.or_(attrs.Instrument('a'), attr.AttrOr((attrs.Instrument('b'), attrs.Instrument('c')))) # Test that the nesting has been removed. assert len(a.attrs) == 3
def test_simpleattr_or_eq(): attr = va.Instrument('eit') assert attr | attr == attr assert attr | va.Instrument('eit') == attr
def pytest_funcarg__eit(request): return va.Instrument('eit')
def eit(request): return va.Instrument('eit')
def vso_instrument(self): if self['obs_instrument'] == 'HEK': raise ValueError("No instrument contained.") return v_attrs.Instrument(self['obs_instrument'])
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_non_str_instrument(): # Sanity Check assert isinstance(va.Instrument("lyra"), va.Instrument) with pytest.raises(ValueError): va.Instrument(1234)