Exemplo n.º 1
0
def test_query_error(LCClient):
    times = [a.Time("1983-05-01", "1983-05-02")]
    for time in times:
        with pytest.raises(ValueError):
            LCClient.search(time, Instrument('XRS'))
Exemplo n.º 2
0
def test_srs_start_or_end_out_of_range(srs_client):
    res = srs_client.search(a.Time('1995/12/30', '1996/01/02'))
    assert len(res) == 1
    cur_year = datetime.date.today().year
    res = srs_client.search(a.Time(f'{cur_year}/01/01', f'{cur_year+2}/01/01'))
    assert len(res) > 0
Exemplo n.º 3
0
def query_result():
    client = vso.VSOClient()
    return client.search(net_attrs.Time('2001/1/1', '2001/1/2'),
                         net_attrs.Instrument('EIT'))
Exemplo n.º 4
0
import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.visualization import ImageNormalize, SqrtStretch

import sunpy.map
from sunpy.net import Fido
from sunpy.net import attrs as a

#####################################################
# First, query a full frame AIA image.
t0 = astropy.time.Time('2012-09-24T14:56:03', scale='utc', format='isot')
q = Fido.search(
    a.Instrument.aia,
    a.Physobs.intensity,
    a.Wavelength(171 * u.angstrom),
    a.Time(t0, t0 + 13 * u.s),
)
m = sunpy.map.Map(Fido.fetch(q))

#####################################################
# Next, we will create a submap from this image. We will
# crop the field of view to active region NOAA 11575.
m_cutout = m.submap(
    SkyCoord(-500 * u.arcsec, -275 * u.arcsec, frame=m.coordinate_frame),
    top_right=SkyCoord(150 * u.arcsec,
                       375 * u.arcsec,
                       frame=m.coordinate_frame),
)
m_cutout.peek()

#####################################################
Exemplo n.º 5
0
def test_srs_unpack():
    qr = Fido.search(
        a.Instrument("soon") & a.Time("2015/01/01", "2015/01/01T23:59:29"))
    res = Fido.fetch(qr)
    assert len(res) == 1
    assert res.data[0].endswith("20150101SRS.txt")
    sunpy.data.sample.NOAAINDICES_TIMESERIES, source='NOAAIndices')
ts_noaa_pre = sunpy.timeseries.TimeSeries(
    sunpy.data.sample.NOAAPREDICT_TIMESERIES, source='NOAAPredictIndices')
ts_norh = sunpy.timeseries.TimeSeries(sunpy.data.sample.NORH_TIMESERIES,
                                      source='NoRH')
ts_rhessi = sunpy.timeseries.TimeSeries(sunpy.data.sample.RHESSI_TIMESERIES,
                                        source='RHESSI')
ts_gbm = sunpy.timeseries.TimeSeries(sunpy.data.sample.GBM_TIMESERIES,
                                     source='GBMSummary')
# Note: for some FITS files a source can be determined implicitly, however it
# is good practice to delcare it explicitly when possible.

##############################################################################
# You can create a list of TimeSeries objects by using multiple files. First
# however, we shall download these files using `Fido`.
goes = Fido.search(a.Time("2012/06/01", "2012/06/04"), a.Instrument("XRS"))
goes_files = Fido.fetch(goes)

# Using these new files you get a list:
lis_goes_ts = sunpy.timeseries.TimeSeries(goes_files[:2], source='XRS')
lis_goes_ts = sunpy.timeseries.TimeSeries(goes_files, source='XRS')
# Using concatenate=True kwarg you can merge the files into one TimeSeries:
combined_goes_ts = sunpy.timeseries.TimeSeries(goes_files,
                                               source='XRS',
                                               concatenate=True)
combined_goes_ts.peek()
# Note: ATM we only accept TimeSeries of a single class being created together
# with the factory. The issue is that several source filetypes don't contain
# metadata that enables us to reliably implicitly gather the source and ATM the
# source is given as a single keyword argument for simplicity. But you can merge
# different TimeSeries classes using concatenate.
Exemplo n.º 7
0
import astropy.units as u
import matplotlib.pyplot as plt
import sunpy.map
from sunpy.net import Fido
from sunpy.net import attrs as a

import pfsspy
import pfsspy.utils

###############################################################################
# Set up the search.
#
# Note that for SunPy versions earlier than 2.0, a time attribute is needed to
# do the search, even if (in this case) it isn't used, as the synoptic maps are
# labelled by Carrington rotation number instead of time
time = a.Time('2010/01/01', '2010/01/01')
series = a.jsoc.Series('hmi.synoptic_mr_polfil_720s')
crot = a.jsoc.PrimeKey('CAR_ROT', 2210)

###############################################################################
# Do the search.
#
# If you use this code, please replace this email address
# with your own one, registered here:
# http://jsoc.stanford.edu/ajax/register_email.html
result = Fido.search(time, series, crot,
                     a.jsoc.Notify(os.environ["JSOC_EMAIL"]))
files = Fido.fetch(result)

###############################################################################
# Read in a file. This will read in the first file downloaded to a sunpy Map
Exemplo n.º 8
0

@pytest.mark.remote_data
@pytest.mark.parametrize("time,instrument", [
    (Time('2012/11/27', '2012/11/27'), Instrument('eve')),
])
def test_get(LCClient, time, instrument):
    qr1 = LCClient.search(time, instrument)
    res = LCClient.fetch(qr1)
    assert len(res) == len(qr1)


@pytest.mark.remote_data
@pytest.mark.parametrize(
    'query',
    [(a.Time('2012/10/4', '2012/10/5') & a.Instrument.eve & a.Level.zero)])
def test_fido(LCClient, query):
    qr = Fido.search(query)
    client = qr.get_response(0).client
    assert isinstance(qr, UnifiedResponse)
    assert isinstance(client, eve.EVEClient)
    response = Fido.fetch(qr)
    assert len(response) == qr._numfile


@pytest.mark.remote_data
@pytest.mark.parametrize('time', [(a.Time('2012/10/4', '2012/10/6'))])
def test_levels(time):
    """
    Test the correct handling of level
    Level 0 comes from EVEClient, other levels from EVE.
Exemplo n.º 9
0
available from each satellite. Similarly there are times when GOES 16 and 17 overlap.
"""
import matplotlib.pyplot as plt
import numpy as np

from sunpy import timeseries as ts
from sunpy.net import Fido
from sunpy.net import attrs as a

#############################################################
# Lets first define our start and end times and query using the
# `~sunpy.net.Fido`.

tstart = "2015-06-21 01:00"
tend = "2015-06-21 23:00"
result = Fido.search(a.Time(tstart, tend), a.Instrument("XRS"))
print(result)

#############################################################
# As we can see this now returns three results, one file for GOES
# 13, one for GOES 14 and one for GOES 15, which can be identified
# by the ``SatelliteNumber`` column. However, we probably will only want
# one of these files for our analysis, so we can query by the `sunpy.net.attrs`:
# `sunpy.net.dataretriever.attrs.goes.SatelliteNumber` to specify what GOES satellite number we want
# to use.

result_goes15 = Fido.search(a.Time(tstart, tend), a.Instrument("XRS"),
                            a.goes.SatelliteNumber(15))
print(result_goes15)

#############################################################
Exemplo n.º 10
0
def test_can_handle_query_no_series(client):
    assert not client._can_handle_query(a.Time("2020/01/02", "2020/01/03"))
    assert not client._can_handle_query(a.Wavelength(17.1 * u.nm))
    assert client._can_handle_query(a.jsoc.Series("hmi.M_45s"))
Exemplo n.º 11
0
def test_query(client):
    Jresp = client.search(a.Time('2020/1/1T00:00:00', '2020/1/1T00:01:30'),
                          a.jsoc.Series('hmi.M_45s'), a.Sample(90 * u.second))
    assert isinstance(Jresp, JSOCResponse)
    assert len(Jresp) == 2
Exemplo n.º 12
0
def test_invalid_query(client):
    with pytest.raises(ValueError):
        client.search(a.Time('2020/1/1T01:00:00', '2020/1/1T01:00:45'))
Exemplo n.º 13
0
def test_post_wave_series(client):
    with pytest.raises(TypeError):
        client.search(
            a.Time('2020/1/1T00:00:00', '2020/1/1T00:00:45'),
            a.jsoc.Series('hmi.M_45s') | a.jsoc.Series('aia.lev1_euv_12s'),
            a.jsoc.Wavelength(193 * u.AA) | a.jsoc.Wavelength(335 * u.AA))
Exemplo n.º 14
0
def test_post_notify_fail(client):
    responses = client.search(a.Time('2020/1/1T00:00:00', '2020/1/1T00:00:45'),
                              a.jsoc.Series('hmi.M_45s'))
    with pytest.raises(ValueError):
        client.request_data(responses)
Exemplo n.º 15
0
def test_wavelength_range():
    with pytest.raises(ValueError):
        norh.NoRHClient().search(
            a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'),
            a.Wavelength(17 * u.GHz, 34 * u.GHz))
Exemplo n.º 16
0
import astropy.units as u

import sunpy.map
from sunpy.net import Fido
from sunpy.net import attrs as a

###########################################################################
# First we'll download a couple images and store them in a
# `sunpy.map.MapSequence`. This could be from any channel of any imager.
# Here, we use SDO/AIA 304 Å.

instrument = a.Instrument.aia
wave = a.Wavelength(30 * u.nm, 31 * u.nm)
result = Fido.search(
    a.Time('2015-06-18T00:00:00', '2015-06-18T00:00:10')
    | a.Time('2015-06-18T01:03:30', '2015-06-18T01:03:35'), instrument, wave)
downloaded_files = Fido.fetch(result)
maps = sunpy.map.Map(downloaded_files, sequence=True)

###########################################################################
# Now we'll do a standard plot of the second image just to see it.

plt.figure()
ax = plt.subplot(projection=maps[1])
maps[1].plot(clip_interval=(0.5, 99.9) * u.percent)

###########################################################################
# And now we can do take the actual difference.

diff = maps[1].data - maps[0].data
Exemplo n.º 17
0
def test_query_wrong_wave():
    c = norh.NoRHClient()
    with pytest.raises(ValueError):
        c.search(a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'),
                a.Wavelength(50*u.GHz))
Exemplo n.º 18
0
How to accurately plot the position of Venus as it transitted in front
of the Sun as observed by SDO/AIA.
"""
import matplotlib.pyplot as plt

import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.coordinates import solar_system_ephemeris

from sunpy.net import Fido, attrs as a
import sunpy.map
from sunpy.coordinates import get_body_heliographic_stonyhurst

###############################################################################
# Let's download an image of the Venus transit.
result = Fido.search(a.Time('2012/06/06 04:07:25', '2012/06/06 04:07:35'),
                     a.Instrument('aia'), a.Wavelength(1600 * u.angstrom))
files = Fido.fetch(result)
aiamap = sunpy.map.Map(files[0])

###############################################################################
# For this example, we require high-precision ephemeris information. The built-in
# ephemeris provided by astropy is not accurate enough. This call requires ``jplephem``
# to be installed. This will also trigger a download of about ~10 MB.
solar_system_ephemeris.set('de432s')

###############################################################################
# Now we get the position of Venus and convert it into the SDO/AIA coordinates.
# The apparent position of Venus accounts for the time it takes for light to
# travel from Venus to SDO.
venus = get_body_heliographic_stonyhurst('venus',
Exemplo n.º 19
0
import matplotlib.pyplot as plt

import sunpy.map
from sunpy.net import Fido, attrs as a

###############################################################################
# To download the required data, we use
# `Fido <sunpy.net.fido_factory.UnifiedDownloaderFactory>`, a downloader client,
# to query the Joint Science Operations Center, or JSOC, where HMI data are stored.
# First define the search variables, a timerange,
# a `data series <http://jsoc.stanford.edu/JsocSeries_DataProducts_map.html>`_,
# keywords, and your e-mail address (to notify you when the download is complete).
# See the JSOC e-mail address registration page
# `here <http://jsoc.stanford.edu/ajax/register_email.html>`_.

result = Fido.search(a.Time('2014/11/20 00:00:00', '2014/11/20 00:04:00'),
                     a.jsoc.Series("hmi.M_720s"),
                     a.jsoc.Keys(["T_REC, CROTA2"]),
                     a.jsoc.Notify("*****@*****.**"))

###############################################################################
# Now we can see what results we obtained from our search.
# Notice we have two files.
print(result)

###############################################################################
# The following shows how to download the results. If we
# don't provide a path it will download the file into the sunpy data directory.
# The output provides the path of the downloaded files.
# The result can be from several data clients, so we have to index the client first
# and then index the file.
Exemplo n.º 20
0
How to retrieve the GOES flare event list through use of
SunPy's Heliophysics Event Knowledgebase (HEK) client.
"""
from sunpy.net import Fido
from sunpy.net import attrs as a

###################################################################
# We use Fido to to query the HEK catalogue. We define our event type
# as a flare ("FL"). We also set up the start and end times over which
# we will search for flare events. We want the list of events
# that were detected by the GOES X-ray Sensor (XRS) instrument between
# ``tstart`` and ``tend``.
event_type = "FL"
tstart = "2013/10/28"
tend = "2013/10/29"
result = Fido.search(a.Time(tstart, tend),
                     a.hek.EventType(event_type),
                     a.hek.OBS.Observatory == "GOES")

###################################################################
# The result is returned as a `~sunpy.net.fido_factory.UnifiedResponse`,
# from which we can see a table from one provider is found and returned.
print(result)

# We can now inspect the results in `result` by indexing to return get the data
# from the `~sunpy.net.hek.hek.HEKTable`. Lets print the number of flares and
# inspect the result information.
print(len(result[0]))

###################################################################
# It"s also possible to access the HEK results from the
Exemplo n.º 21
0
"""

from __future__ import print_function, division

import astropy.units as u

import sunpy.data.sample
import sunpy.timeseries
from sunpy.net import Fido, attrs as a
from sunpy.time import TimeRange, parse_time


##############################################################################
# Search for Data

goes_res = Fido.search(a.Time("2010-11-02", "2010-11-07"), a.Instrument('goes'))
goes_res

norh_res = Fido.search(a.Time("2010-11-02", "2010-11-07"), a.Instrument('norh'),
                       a.Wavelength(17 * u.GHz))
norh_res


##############################################################################
# Download Data

goes_files = Fido.fetch(goes_res)
norh_files = Fido.fetch(norh_res)

##############################################################################
# Make Timeseries
Exemplo n.º 22
0
from sunpy.net import attrs as a
from sunpy.net import Fido

tstart = '2013/04/12 19:00:56'

tend = '2013/04/12 20:30:29'

event_type = 'FL'

result = Fido.search(a.Time(tstart, tend), a.hek.EventType(event_type))

[print(r) for r in result]
print(result.keys())

print(result['hek']['event_coord1'])
print(result['hek']['event_coord2'])
print(result['hek']['event_coord3'])
print(result['hek']['event_title'])
print(result['hek'].keys())
Exemplo n.º 23
0
def Flarefinder(start_datetime, end_datetime):
    instrument = a.Instrument('AIA')
    wave = a.Wavelength(13 * u.nm, 14 * u.nm)

    start_datetime_d = start_datetime + timedelta(seconds=15)
    end_datetime_d = end_datetime + timedelta(seconds=15)
    result = Fido.search(
        a.Time(start_datetime, start_datetime_d)
        | a.Time(end_datetime, end_datetime_d), instrument, wave)
    downloaded_files = Fido.fetch(
        result, path="C:/Users/Nils/Documents/MaTa/flaskandst/sunpymaps")
    maps = smap.Map(downloaded_files, sequence=True)
    maps = mapsequence_solar_derotate(maps)
    amount = len(maps)

    #%%######################################################################-Superpixel-######################################################################
    pixamt = 128
    newdim1 = u.Quantity(maps[0].dimensions) / pixamt
    newdim2 = u.Quantity(maps[amount - 1].dimensions) / pixamt
    spmap1 = maps[0].superpixel(newdim1)
    spmap2 = maps[amount - 1].superpixel(newdim2)

    #%%######################################################################-Difference Map-######################################################################

    diff = spmap1.data - spmap2.data
    metadiff = spmap2.meta
    diffmap = smap.Map(diff, metadiff)
    #vdef = diffmap.max()*0.6
    #fig = plt.figure()
    #ax_diffmap= plt.subplot(projection = diffmap)
    #dplot = diffmap.plot(cmap='Greys_r', norm=colors.Normalize(vmin=-vdef, vmax=vdef))
    #st.write(fig)

    #%%#####################################################################-Flare Detection Procedure-########################################################################

    bar = diffmap.max() * 0.99

    pixelpos = np.argwhere(abs(diffmap.data) >= bar) * u.pixel
    if len(pixelpos) == 0:
        print('no flares found')

    else:
        print('Possible flare locations:')
        print(pixelpos)
        print('Keep in mind here in pixel format it is y,x and not x,y')

    pixelcord = diffmap.pixel_to_world(pixelpos[:, 1], pixelpos[:, 0])
    print(pixelcord)

    #%%#####################################################################-Submap-########################################################################

    pixoperator = (540, 960) * u.pixel
    pixelpos4k = pixelpos * (4096 / pixamt)
    PPLEN = len(pixelpos)

    x = 0
    while x < PPLEN:
        now = datetime.utcnow()
        nowstr = now.strftime("%Y%b%athe%d%H%M%S")
        startstr = start_datetime.strftime("%Y%b%athe%d%H%M%S")
        endstr = end_datetime.strftime("%Y%b%athe%d%H%M%S")
        pixbot = pixelpos4k[x] - pixoperator
        cordbot = maps[amount - 1].pixel_to_world(pixbot[1], pixbot[0])
        submap = maps[amount - 1].submap(cordbot,
                                         width=1153.43016 * u.arcsec,
                                         height=648.75384 * u.arcsec)
        fig = plt.figure()
        ax_submap = plt.subplot(projection=submap)
        submap.plot(cmap='sdoaia131')
        urlstr = "static/Submaps/" + nowstr + "_" + startstr + "_" + endstr + ".jpeg"
        plt.savefig(urlstr)

        newflare = [startstr, endstr, urlstr]
        conn.execute(
            '''insert into flares(stime, etime, urlfor) values (?,?,?) ''',
            newflare)
        conn.commit()
        st.write(fig)
        x += 1
Exemplo n.º 24
0
Fido supports searching metadata from services like `~sunpy.net.hek.HEKClient`,
`~sunpy.net.helio.HECClient`, and `~sunpy.net.jsoc.JSOCClient`.

In this example we will make one search for records from the JSOC and the HEK,
and then download the corresponding file from the JSOC.
"""
import os

from sunpy.net import Fido
from sunpy.net import attrs as a

###################################################################
# We will query the HEK for all flares with a peak flux greater than 1000.
# We will also search JSOC for a 'hmi.m_45s' series.

timerange = a.Time('2010/8/1 03:40', '2010/8/1 3:40:10')

# Note that JSOC needs an email address to export the files, if you want to run
# this, you must supply your own email here.
jsoc_email = os.environ["JSOC_EMAIL"]

results = Fido.search(
    timerange, a.hek.FL & (a.hek.FL.PeakFlux > 1000)
    | a.jsoc.Series('hmi.m_45s') & a.jsoc.Notify(jsoc_email))

###################################################################
# ``results`` is a `~sunpy.net.fido_factory.UnifiedResponse` object that
# contains records returned from querying various clients by "Fido.search".

print(results)
Exemplo n.º 25
0
def test_srs_out_of_range(srs_client):
    res = srs_client.search(a.Time('1995/01/01', '1995/02/01'))
    assert len(res) == 0
    res = srs_client.search(a.Time('2995/01/01', '2995/02/01'))
    assert len(res) == 0
Exemplo n.º 26
0
    with pytest.raises(ValueError):
        norh.NoRHClient().search(
            a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'),
            a.Wavelength(17 * u.GHz, 34 * u.GHz))


def test_query_wrong_wave():
    c = norh.NoRHClient()
    with pytest.raises(ValueError):
        c.search(a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'),
                a.Wavelength(50*u.GHz))


@pytest.mark.remote_data
@pytest.mark.parametrize("time,instrument,wave", [
    (a.Time('2012/10/4', '2012/10/6'), a.Instrument('norh'), a.Wavelength(17*u.GHz)),
    (a.Time('2013/10/5', '2013/10/7'), a.Instrument('norh'), a.Wavelength(34*u.GHz))])
def test_get(time, instrument, wave):
    LCClient = norh.NoRHClient()
    qr1 = LCClient.search(time, instrument, wave)
    res = LCClient.fetch(qr1)
    download_list = res.wait(progress=False)
    assert len(download_list) == len(qr1)


@pytest.mark.remote_data
@pytest.mark.parametrize(
    "time, instrument, wave",
    [(a.Time('2012/10/4', '2012/10/6'), a.Instrument('norh'), a.Wavelength(17*u.GHz)),
     (a.Time('2013/10/5', '2013/10/7'), a.Instrument('norh'), a.Wavelength(34*u.GHz))])
def test_fido(time, instrument, wave):
Exemplo n.º 27
0
def test_tar_file_broken():
    # 2010 extracts out to 2010_SRS while other years do SRS only.
    results = Fido.search(a.Time("2010/5/1", "2010/5/2"), a.Instrument.soon)
    results = Fido.fetch(results)
    assert len(results) == 2
Exemplo n.º 28
0
def test_query_no_wave():
    c = norh.NoRHClient()
    with pytest.raises(ValueError):
        c.search(a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'))
Exemplo n.º 29
0
How to download data from the VSO with Fido.
"""
import astropy.units as u

from sunpy.net import Fido
from sunpy.net import attrs as a

###############################################################################
# `sunpy.net.Fido` is the primary
# interface to search for and download data and
# will search the VSO when appropriate. The following example searches for all
# SOHO/EIT images between the times defined below by defining
# a timerange (`~sunpy.net.attrs.Time`) and
# the instrument (`~sunpy.net.attrs.Instrument`).
attrs_time = a.Time('2005/01/01 00:10', '2005/01/01 00:15')
result = Fido.search(attrs_time, a.Instrument.eit)

###############################################################################
# Let's inspect the results.
print(result)

###############################################################################
# The following shows how to download the results. If we
# don't provide a path it will download the file into the sunpy data directory.
# The output provides the path of the downloaded files.
downloaded_files = Fido.fetch(result)
print(downloaded_files)

###############################################################################
# More complicated queries can be constructed by using relational operators.
Exemplo n.º 30
0
    qr1 = LCClient.search(time, instrument)
    download_list = LCClient.fetch(qr1)
    assert len(download_list) == len(qr1)


@pytest.mark.remote_data
def test_new_logic(LCClient):
    qr = LCClient.search(Time('2012/10/4', '2012/10/6'), Instrument('XRS'))
    download_list = LCClient.fetch(qr)
    assert len(download_list) == len(qr)


@pytest.mark.remote_data
@pytest.mark.parametrize(
    "time, instrument",
    [(a.Time("2012/10/4", "2012/10/5"), a.Instrument.goes)])
def test_fido(time, instrument):
    qr = Fido.search(time, Instrument('XRS'))
    assert isinstance(qr, UnifiedResponse)
    response = Fido.fetch(qr)
    assert len(response) == qr._numfile


@settings(deadline=10000, max_examples=5)
@pytest.mark.remote_data
@given(goes_time())
def test_time_for_url(time):
    # Create a fresh client, as fixtures don't work with @given
    LCClient = goes.XRSClient()
    time = time.start.strftime("%Y/%m/%d")
    almost_day = TimeDelta(1 * u.day - 1 * u.millisecond)