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
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
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
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) 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)
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
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 = { 'Time': TimeRange(parse_time(start), 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
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
def hurst_analysis2(ts, duration = None, advance = None,**kwargs): hurst2_results = [] # Pick the duration of the sub-time series #duration = timedelta(seconds=10) # Pick how far to jump forward in time for the next sub time-series # Can use this to overlap with the previous time-series #advance = duration/2 # Start the loop extent = TimeRange(ts.data.index[0], ts.data.index[0] + duration) while extent.end() <= ts.data.index[-1]: hurst2 = hurst_fArma([extent.start(),extent.end()],kwargs) # Store the analyzed time-series and its Hurst analysis hurst2_results.append( {"extent":extent,"hurst2":hurst2} ) extent.extend(advance,advance)
def plot(self, extract=None, show_frm=None, show_spike=False, show_before_after=False): if extract is None: self.lyra.plot() else: lc = self.lyra.extract(extract) lc.plot() if show_frm is not None: times = self.onoff(frm_name=show_frm).times() for tr in times: plt.axvspan(tr.start(), tr.end(), facecolor='green', alpha=0.5) if show_spike: for tr in self.all_spike_times: plt.axvspan(tr.start(), tr.end(), facecolor='black', alpha=0.75) if show_before_after: for event in self.event_times: current_minimum = datetime.timedelta(days=3) for spike_time in self.all_spike_times: event_end_to_spike_start = spike_time.start() - event.end() print current_minimum if event_end_to_spike_start > datetime.timedelta(): if event_end_to_spike_start < current_minimum: current_minimum = event_end_to_spike_start after_flare = TimeRange(event.end(), spike_time.start()) lc.truncate(after_flare.start(), after_flare.end()).plot(style ='c-') for event in self.event_times: current_minimum = datetime.timedelta(days=3) for spike_time in self.all_spike_times: spike_end_to_event_start = event.start() - spike_time.end() if spike_end_to_event_start > datetime.timedelta(): if spike_end_to_event_start < current_minimum: current_minimum = event.start() - spike_time.end() before_flare = TimeRange(spike_time.end(),event.start()) lc.truncate(before_flare.start(), before_flare.end()).plot(style ='r-')
from sunpy.net import Fido from sunpy.net import attrs as a from sunpy.net._attrs import Instrument, Level, Time from sunpy.net.vso.attrs import Source from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse from sunpy.net.vso import VSOClient from sunpy.time import parse_time from sunpy.time.timerange import TimeRange LCClient = eve.EVEClient() @pytest.mark.remote_data @pytest.mark.parametrize("timerange,url_start,url_end", [ (TimeRange('2012/4/21', '2012/4/21'), 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120421_EVE_L0CS_DIODES_1m.txt', 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120421_EVE_L0CS_DIODES_1m.txt' ), (TimeRange('2012/5/5', '2012/5/6'), 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120505_EVE_L0CS_DIODES_1m.txt', 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120506_EVE_L0CS_DIODES_1m.txt', ), (TimeRange('2012/7/7', '2012/7/14'), 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120707_EVE_L0CS_DIODES_1m.txt', 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120714_EVE_L0CS_DIODES_1m.txt', ) ]) def test_get_url_for_time_range(timerange, url_start, url_end): urls = LCClient._get_url_for_timerange(timerange) assert isinstance(urls, list)
from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse from sunpy.net.tests.strategies import goes_time from sunpy.time import is_time_equal, parse_time from sunpy.time.timerange import TimeRange @pytest.fixture def LCClient(): return goes.XRSClient() @pytest.mark.remote_data @pytest.mark.parametrize( "timerange,url_start,url_end", [(TimeRange('1995/06/03', '1995/06/05'), 'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950603.fits', 'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950605.fits'), (TimeRange('2008/06/02', '2008/06/04'), 'https://umbra.nascom.nasa.gov/goes/fits/2008/go1020080602.fits', 'https://umbra.nascom.nasa.gov/goes/fits/2008/go1020080604.fits')]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end): urls = LCClient._get_url_for_timerange(timerange) assert isinstance(urls, list) assert urls[0] == url_start assert urls[-1] == url_end @pytest.mark.remote_data @pytest.mark.parametrize("timerange, url_start, url_end", [(TimeRange('1999/01/10', '1999/01/20'),
import sunpy.net.dataretriever.sources.goes as goes from sunpy.net.fido_factory import UnifiedResponse from sunpy.net import Fido from sunpy.net import attrs as a from sunpy.net.tests.strategies import goes_time from sunpy.time import parse_time, is_time_equal @pytest.fixture def LCClient(): return goes.XRSClient() @pytest.mark.parametrize( "timerange,url_start,url_end", [(TimeRange('1995/06/03', '1995/06/05'), 'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950603.fits', 'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950605.fits'), (TimeRange('2008/06/02', '2008/06/04'), 'https://umbra.nascom.nasa.gov/goes/fits/2008/go1020080602.fits', 'https://umbra.nascom.nasa.gov/goes/fits/2008/go1020080604.fits')]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end): urls = LCClient._get_url_for_timerange(timerange) assert isinstance(urls, list) assert urls[0] == url_start assert urls[-1] == url_end @given(goes_time()) def test_can_handle_query(time): ans1 = goes.XRSClient._can_handle_query(time, Instrument('XRS'))
from sunpy.time import parse_time from sunpy.time.timerange import TimeRange from sunpy.net.dataretriever.client import QueryResponse import sunpy.net.dataretriever.sources.fermi_gbm as fermi_gbm from sunpy.net.fido_factory import UnifiedResponse from sunpy.net import Fido from sunpy.net import attrs as a from sunpy.net.tests.strategies import time_attr from hypothesis import given LCClient = fermi_gbm.GBMClient() @pytest.mark.remote_data @pytest.mark.parametrize("timerange,url_start,url_end", [(TimeRange('2011/06/07', '2011/06/09'), 'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/2011/06/07/' 'current/glg_cspec_n5_110607_v00.pha', 'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/2011/06/09/' 'current/glg_cspec_n5_110609_v00.pha'), (TimeRange('2016/09/09', '2016/09/11'), 'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/2016/09/09/' 'current/glg_cspec_n5_160909_v00.pha', 'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/' '2016/09/11/current/glg_cspec_n5_160911_v00.pha')]) def test_get_url_for_time_range(timerange, url_start, url_end): urls = LCClient._get_url_for_timerange(timerange, detector='n5', resolution='cspec') assert isinstance(urls, list) assert urls[0] == url_start assert urls[-1] == url_end
import astropy.units as u from sunpy.time.timerange import TimeRange from sunpy.net.dataretriever.client import QueryResponse import sunpy.net.dataretriever.sources.norh as norh from sunpy.net.fido_factory import UnifiedResponse from sunpy.net import Fido from sunpy.net import attrs as a from hypothesis import given from sunpy.net.tests.strategies import time_attr @pytest.mark.parametrize("timerange,url_start,url_end", [ (TimeRange('2012/4/21', '2012/4/21'), 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2012/04/tca120421', 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2012/04/tca120421' ), (TimeRange('2012/12/1', '2012/12/2'), 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2012/12/tca121201', 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2012/12/tca121202' ), (TimeRange('2012/3/7', '2012/3/14'), 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2012/03/tca120307', 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2012/03/tca120314' ) ]) def test_get_url_for_time_range(timerange, url_start, url_end): urls = norh.NoRHClient()._get_url_for_timerange(timerange, wavelength=17 * u.GHz)
def to_timerange(self): return TimeRange(self.start.to_time(), self.end.to_time())
from sunpy.time import parse_time from sunpy.net.vso.attrs import Time, Instrument, Source from sunpy.net.dataretriever.client import QueryResponse import sunpy.net.dataretriever.sources.lyra as lyra from sunpy.net.fido_factory import UnifiedResponse from sunpy.net import Fido from sunpy.net import attrs as a from hypothesis import given from sunpy.net.tests.strategies import time_attr LCClient = lyra.LYRAClient() @pytest.mark.parametrize("timerange,url_start,url_end", [ (TimeRange('2012/1/7', '2012/1/7'), 'http://proba2.oma.be/lyra/data/bsd/2012/01/07/lyra_20120107-000000_lev2_std.fits', 'http://proba2.oma.be/lyra/data/bsd/2012/01/07/lyra_20120107-000000_lev2_std.fits' ), (TimeRange('2012/12/1', '2012/12/2'), 'http://proba2.oma.be/lyra/data/bsd/2012/12/01/lyra_20121201-000000_lev2_std.fits', 'http://proba2.oma.be/lyra/data/bsd/2012/12/02/lyra_20121202-000000_lev2_std.fits' ), (TimeRange('2012/4/7', '2012/4/14'), 'http://proba2.oma.be/lyra/data/bsd/2012/04/07/lyra_20120407-000000_lev2_std.fits', 'http://proba2.oma.be/lyra/data/bsd/2012/04/14/lyra_20120414-000000_lev2_std.fits' ) ]) def test_get_url_for_time_range(timerange, url_start, url_end): urls = LCClient._get_url_for_timerange(timerange) assert isinstance(urls, list)
import sunpy.net.dataretriever.sources.rhessi as rhessi from sunpy.net import Fido from sunpy.net import attrs as a from sunpy.time import parse_time from sunpy.time.timerange import TimeRange from sunpy.net.vso.attrs import Time, Instrument from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse LCClient = rhessi.RHESSIClient() @pytest.mark.online @pytest.mark.parametrize( "timerange,url_start", [(TimeRange('2012/7/1', '2012/7/2'), 'hessidata/metadata/catalog/hsi_obssumm_20120701_050.fits'), (TimeRange('2013/6/3', '2013/6/4'), 'hessidata/metadata/catalog/hsi_obssumm_20130603_042.fits'), (TimeRange('2012/7/1', '2012/7/14'), 'hessidata/metadata/catalog/hsi_obssumm_20120701_050.fits')]) def test_get_url_for_time_range(timerange, url_start): urls = LCClient._get_url_for_timerange(timerange) assert isinstance(urls, list) assert url_start in urls[0] def test_can_handle_query(): ans1 = rhessi.RHESSIClient._can_handle_query(Time('2012/8/9', '2012/8/9'), Instrument('rhessi')) assert ans1 is True
from sunpy.net import attrs as a from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse from sunpy.net.tests.strategies import time_attr from sunpy.time import parse_time from sunpy.time.timerange import TimeRange @pytest.fixture def LCClient(): return fermi_gbm.GBMClient() @pytest.mark.remote_data @pytest.mark.parametrize("timerange,url_start,url_end", [(TimeRange('2011/06/07', '2011/06/09'), 'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/2011/06/07/' 'current/glg_cspec_n5_110607_v00.pha', 'https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/2011/06/09/' 'current/glg_cspec_n5_110609_v00.pha')]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end): urls = LCClient._get_url_for_timerange(timerange, detector='n5', resolution='cspec') assert isinstance(urls, list) assert urls[0] == url_start assert urls[-1] == url_end @given(time_attr()) def test_can_handle_query(LCClient, time): ans1 = LCClient._can_handle_query(time, a.Instrument.gbm) assert ans1 is True