Пример #1
0
def test_client_fetch_wrong_type(mock_fetch):
    query = a.Time("2011/01/01", "2011/01/02") & a.Instrument("goes")

    qr = Fido.search(query)

    with pytest.raises(TypeError):
        Fido.fetch(qr)
Пример #2
0
def test_fido(mock_wait, mock_search, mock_enqueue):
    qr1 = Fido.search(Time('2012/10/4', '2012/10/6'),
                      Instrument('noaa-indices'))
    Fido.fetch(qr1, path="/some/path/{file}")

    # Here we assert that the `fetch` function has called the parfive
    # Downloader.enqueue_file method with the correct arguments. Everything
    # that happens after this point should either be tested in the
    # GenericClient tests or in parfive itself.
    assert mock_enqueue.called_once_with(("ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt",
                                          "/some/path/RecentIndices.txt"))
Пример #3
0
def test_srs_save_path(tmpdir):
    qr = Fido.search(a.Instrument.srs_table, a.Time("2016/10/01",
                                                    "2016/10/02"))
    files = Fido.fetch(qr, path=str(tmpdir))
    assert len(files) == 2
    assert files[0].endswith("20161001SRS.txt")
    assert files[1].endswith("20161002SRS.txt")
Пример #4
0
def test_fido(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
Пример #5
0
def download(dtime, dt, dir_path, *args):
    """
    Description:
              download fits files for specified time window and wavelength channels
              from the VSO


    dtime:    should be a datetime object. EX: datetime(2010, 6, 13, 5, 25, 0)
    dt:       should be a time delta object in correct units. EX: timedelta(seconds=6)
    dir_path: path to directory for storing fits files
    *argv:    wavelength channels you want fits files for. EX: 193, 211, etc... 
    """


    sform = '%Y/%m/%d %H:%M:%S'  # format datetime objects correctly

    start = datetime.strftime(dtime-dt, sform)
    end = datetime.strftime(dtime+dt, sform)

    time = attrs.Time(start, end)
    ins = attrs.Instrument('aia') 


    for thing in args:
        print("Downloading {} angstrom data\n".format(thing)) 
        wave = attrs.Wavelength(int(thing)*u.AA)
        searchResults = Fido.search(time, ins, wave)

        for file_ in searchResults:
            print("{}".format(file_))

        dl_fil = Fido.fetch(searchResults, path=dir_path, wait=True) 
Пример #6
0
def loadData(s_map: Map):
    query = Fido.search(attrs.Time(s_map.tstart.isoformat(), s_map.tstart.isoformat()),
                        attrs.Instrument(s_map.instrument), attrs.Wavelength(s_map.wavelength * u.AA))
    query = query[0, 0]
    if not s_map.id.startswith(list(query.responses)[0][0].fileid):
        raise Exception("ERROR: invalid search result encountered!")
    return Fido.fetch(query, progress=True)
Пример #7
0
def test_no_wait_fetch():
        qr = Fido.search(a.Instrument('EVE'),
                         a.Time("2016/10/01", "2016/10/02"),
                         a.Level(0))
        res = Fido.fetch(qr, wait=False)
        assert isinstance(res, DownloadResponse)
        assert isinstance(res.wait(), list)
Пример #8
0
def test_fido(LCClient, query):
    qr = Fido.search(query)
    client = qr[0].client
    assert isinstance(qr, UnifiedResponse)
    assert type(client) == type(LCClient)
    response = Fido.fetch(qr)
    assert len(response) == qr._numfile
Пример #9
0
def get_image(t, x, y):
    """
    This function gets an AIA EUV image from the SDO (AIA = Atmospheric Imaging Assembly, EUV = Extreme UltraViolent, SDO = SOlar Dynamics Observatory)
    at a given time t, and crops the image to given location x, y.
    
    Param:
          t datetime, the datetime of the flare
          x integer, the longitude position of the flare in arcsec
          y integer, the latitude position of the flare in arcsec
    
    Return:
           aia_sub sunpy Map, the cropped image
    """

    # request the data for the given time
    result = Fido.search(a.Time(t - dt.timedelta(seconds=10), t),
                         a.Instrument("aia"), a.Wavelength(94 * u.angstrom),
                         a.vso.Sample(12 * u.second))
    print('found result')
    #print(result)

    # download the data
    file_download = Fido.fetch(result[0, -1], site='ROB')
    print('downloaded data')
    #print(file_download)

    # load the data to a sun map
    aia1 = sunpy.map.Map(file_download)
    print('loaded to sun map')
    #print(aia1)

    # calibrate it
    aia = aiaprep(aia1)
    print('calibrated')

    # plot it
    aia.plot()
    plt.colorbar()
    #plt.show()

    # get the co-ordinates of the top right and bottom left of the crop box
    co_ords = get_box_coord(x, y, 100)
    tr = co_ords[1]
    bl = co_ords[2]

    # sub-map
    top_right = SkyCoord(tr[0] * u.arcsec,
                         tr[1] * u.arcsec,
                         frame=aia.coordinate_frame)
    bottom_left = SkyCoord(bl[0] * u.arcsec,
                           bl[1] * u.arcsec,
                           frame=aia.coordinate_frame)
    aia_sub = aia.submap(top_right, bottom_left)
    aia_sub.plot_settings['cmap'] = plt.get_cmap('Greys_r')
    ax = plt.subplot(projection=aia_sub)
    aia_sub.plot()
    #plt.show()
    print('made sub map')

    return aia_sub
Пример #10
0
def eis_file():
    ###########################################################################
    # Download an EIS level 0 file
    res = Fido.search(attrs.Instrument('EIS'),
                      attrs.Time('2006-11-03 20:02:00', '2006-11-03 20:03:00'))
    downloaded_files = Fido.fetch(res)
    return downloaded_files[0]
Пример #11
0
def test_fido(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
Пример #12
0
def AIATimeSeries():
    startDate = request.args.get('a', 0, type=str)
    endDate = request.args.get('b', 0, type=str)
    result = Fido.search(a.Time(startDate, endDate), a.Instrument('XRS'))
    try:
        downloaded_files = Fido.fetch(result)
        combined_goes_ts = ts.TimeSeries(downloaded_files,
                                         source='XRS',
                                         concatenate=True)
        combined_goes_ts.peek()
        filename = (os.path.basename(downloaded_files[0]))
        zipf = zipfile.ZipFile('app/static/TSFits/' + filename + '.zip', 'w',
                               zipfile.ZIP_DEFLATED)
        for files in downloaded_files:
            zipf.write(files, os.path.basename(files))
        zipf.close()
        plt.savefig('app/static/images/' + filename + '_timeseries.png')
        return jsonify(
            result='<img id="img" src="static/images/' + filename +
            '_timeseries.png" style="width: inherit; padding-bottom: 6px;">',
            download='<a href="static/images/' + filename +
            '_timeseries.png" download="" id="btn-down" '
            'class="glyphicon glyphicon-floppy-save" style="font-size: 20px; color: black; text-decoration: none; '
            'data-toggle="tooltip" data-placement="top" title="Download PNG file""></a>'
            '<a href="static/TSFits/' + filename +
            '.zip" download="" id="btn-down" class="glyphicon '
            'glyphicon glyphicon-save-file" style="font-size: 20px; color: black; text-decoration: none;'
            'data-toggle="tooltip" data-placement="top" title="Download FITS file""></a>'
        )
    except HTTPError:
        import pdb
        pdb.set_trace()
        result = "error"
        return jsonify(result=result)
Пример #13
0
def test_read_cdf_empty_variable():
    # This tests that:
    # - A CDF file with an empty column can be read
    # - Unknown unit handling works as expected
    result = sunpy.net.Fido.search(a.Time('2020-01-01', '2020-01-02'),
                                   a.cdaweb.Dataset('AC_H6_SWI'))
    filename = Fido.fetch(result[0, 0])

    # Temporarily reset sunpy.io.cdf registry of known unit conversions
    import sunpy.io.cdf as sunpy_cdf
    known_units = sunpy_cdf._known_units
    sunpy_cdf._known_units = {}

    with pytest.warns(SunpyUserWarning, match='Assigning dimensionless units'):
        ts = sunpy.timeseries.TimeSeries(filename)

    assert ts.quantity('nH').unit == u.dimensionless_unscaled

    # Put back known unit registry, and check that units are recognised
    sunpy_cdf._known_units = known_units
    ts = sunpy.timeseries.TimeSeries(filename)
    assert ts.quantity('nH').unit == u.cm**-3

    # Reset again to check that registring units via. astropy works too
    sunpy_cdf._known_units = {}
    u.add_enabled_units([u.def_unit('#/cm^3', represents=u.cm**-3)])
    ts = sunpy.timeseries.TimeSeries(filename)
    assert ts.quantity('nH').unit == u.cm**-3

    sunpy_cdf._known_units = known_units
Пример #14
0
def test_retry(mock_retry):
    """
    Test that you can use Fido.fetch to retry failed downloads.
    """
    res = Results()
    res.data.append("/this/worked.fits")

    err1 = FailedDownload("This is not a filename", "http://not.url/test",
                          None)
    err2 = FailedDownload("This is not a filename2", "http://not.url/test2",
                          None)
    res.errors.append(err1)
    res.errors.append(err2)

    mock_retry.return_value._errors += [err2]

    res2 = Fido.fetch(res, Results(["/this/also/worked.fits"]))

    assert res2 is not res

    # Assert that the result of retry ends up in the returned Results() object
    assert res2.data == [
        "/this/worked.fits", "/tmp/test", "/this/also/worked.fits", "/tmp/test"
    ]
    assert res2.errors == [err2, err2]
Пример #15
0
def test_save_path():
    with tempfile.TemporaryDirectory() as target_dir:
        qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0))
        files = Fido.fetch(qr, path=os.path.join(target_dir, "{instrument}"+os.path.sep+"{level}"))
        for f in files:
            assert target_dir in f
            assert "eve{}0".format(os.path.sep) in f
Пример #16
0
    def get_mdi_fulldisk_fits_file(self,
                                   obsdate: str,
                                   filepath: str = str(path) + "/fulldisk/"):
        """
        Downloads the MDI Fulldisk FITS file corresponding to a particular observation.

        Parameters
        ----------
        obsdate : str
            The observation time and date.
        filepath : mdi_mapsequence : sunpy.map.MapSequence,
            By default downloaded files are stored in `~pythia/data/fulldisk`

        Returns
        -------
        filepath : str
            Filepath to the downloaded FITS file.

        Examples
        --------
        >>> from pythia.seo import Sunspotter
        >>> sunspotter = Sunspotter()
        >>> obsdate = '2000-01-01 12:47:02'
        >>> sunspotter.get_mdi_fulldisk_fits_file(obsdate)
        '~pythia/data/all_clear/fulldisk/fd_m_96m_01d_2556_0008.fits'
        """
        # TODO: Figure out a way to test the downloaded file.
        obsdate = self.get_nearest_observation(obsdate)
        search_results = Fido.search(a.Time(obsdate, obsdate),
                                     a.Instrument.mdi)
        downloaded_file = Fido.fetch(search_results, path=filepath)
        return downloaded_file[0]
Пример #17
0
def get_goes(tr,t0,t1):
    results = Fido.search(a.Time(tr), a.Instrument('XRS'))
    files = Fido.fetch(results)
    goes = TimeSeries(files, source='XRS')

    year = []
    month = []
    day = []
    hour = []
    minute = []
    for items in goes.index:
        year.append(int(str(items)[0:4])) 
        month.append(int(str(items)[5:7])) 
        day.append(int(str(items)[8:10])) 
        hour.append(int(str(items)[11:13])) 
        minute.append(int(str(items)[14:16])) 

    times = []
    for i in range(0,len(year)):
        times.append(datetime(year[i],month[i],day[i],hour[i],minute[i])) 

    times = np.array(times)

    # t0 = datetime(2019, 4, 9, 10, 0)
    # t1 = datetime(2019, 4, 9, 15, 0)

    indices = np.where((times>=t0) & (times<=t1))[0]


    xrsa_data = goes.data['xrsa'][indices]
    xrsb_data = goes.data['xrsb'][indices]

    return xrsa_data, xrsb_data
Пример #18
0
def download_and_gen_carrmap(dt, resample_size=None):
    # Saves fits files to ~/sunpy/data
    stereoA = (a.vso.Source('STEREO_A') & a.Instrument('EUVI') & a.Time(
        time_string(dt), time_string(dt + timedelta(minutes=60))))
    stereoB = (a.vso.Source('STEREO_B') & a.Instrument('EUVI') & a.Time(
        time_string(dt), time_string(dt + timedelta(minutes=60))))
    aia = (a.Instrument('AIA')
           & a.Time(time_string(dt), time_string(dt + timedelta(minutes=60))))
    wave = a.Wavelength(19 * u.nm, 20 * u.nm)
    res = Fido.search(wave, aia | stereoA | stereoB)
    files = []
    for jj in range(len(res)):
        try:
            files.append(Fido.fetch(res[jj, 0]))
        except:
            ""

    maps = [m for m in sunpy.map.Map(files)]
    carrmaps = [
        get_carr_map(map_, resample_size=resample_size) for map_ in maps
    ]

    lons, lats = carrmaps[0][0:2]

    # Quick process maps to have same floor value (0) and same median
    quick_procs_list = []
    for arr in carrmaps[:]:
        arr = arr[2]
        quick_proc = arr - np.nanmin(arr)
        quick_procs_list.append(quick_proc / np.nanmedian(quick_proc))

    combined = np.nanmean(np.array(quick_procs_list), axis=0)

    return lons, lats, combined, maps
Пример #19
0
def get_jsoc_map(start_time, end_time, series_name, email_notify):
    """Submits data request on jsoc server and downloads fits files.
    Processes the files and give sunPy map

    Inputs:
    -------
    start_time - str
        Starting time of data in format "yyyy/mm/dd hh:mm:ss"
    end_time - str
        Ending time of data in format "yyyy/mm/dd hh:mm:ss"
    series_name - str
        Name of jsoc series e.g "hmi.M_720_s"
    email_notify - str
        Email address registered in JSOC which will be used to notify

    Returns:
    --------
    jsoc_map - sunPy map
        SunPy map of the given data


    Notes:
    ------
    result = Fido.search(a.Time('2020/05/01 00:00:00', '2020/05/01 00:00:15'),
                         a.jsoc.Series("hmi.M_720s"),
                         a.jsoc.Notify("*****@*****.**"))
    """
    result = Fido.search(a.Time(start_time, end_time),
                         a.jsoc.Series(series_name),
                         a.jsoc.Notify(email_notify))
    print(result)
    downloaded_file = Fido.fetch(result[0])
    print(downloaded_file)
    jsoc_map = sunpy.map.Map(downloaded_file[0])
    return jsoc_map
Пример #20
0
def test_fido(mock_fetch):
    qr = Fido.search(a.Time("2012/10/4", "2012/10/6"),
                     a.Instrument('noaa-indices'))
    assert isinstance(qr, UnifiedResponse)

    response = Fido.fetch(qr)
    assert len(response) == qr._numfile
Пример #21
0
def test_fido(mock_fetch):
    qr = Fido.search(a.Time("2012/10/4", "2012/10/6"),
                     a.Instrument('noaa-indices'))
    assert isinstance(qr, UnifiedResponse)

    response = Fido.fetch(qr)
    assert len(response) == qr._numfile
Пример #22
0
def test_srs_tar_unpack_midyear():
    qr = Fido.search(
        a.Instrument("soon") & a.Time("2011/06/07", "2011/06/08T23:59:29"))
    res = Fido.fetch(qr)
    assert len(res) == 2
    assert res.data[0].endswith("20110607SRS.txt")
    assert res.data[-1].endswith("20110608SRS.txt")
Пример #23
0
def test_srs_current_year():
    # Current year is nothing but text files, all older years should be tar files.
    year = datetime.date.today().year
    qr = Fido.search(a.Instrument("soon") & a.Time(f"{year}/01/01", f"{year}/01/01T23:59:29"))
    res = Fido.fetch(qr)
    assert len(res) == 1
    assert res.data[0].endswith(f"{year}0101SRS.txt")
Пример #24
0
def test_save_path(tmpdir):
    qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0))

    # Test when path is str
    files = Fido.fetch(qr, path=str(tmpdir / "{instrument}" / "{level}"))
    for f in files:
        assert str(tmpdir) in f
        assert "eve{}0".format(os.path.sep) in f
Пример #25
0
def test_save_path(tmpdir):
    qr = Fido.search(a.Instrument.eve, a.Time("2016/10/01", "2016/10/02"), a.Level.zero)

    # Test when path is str
    files = Fido.fetch(qr, path=str(tmpdir / "{instrument}" / "{level}"))
    for f in files:
        assert str(tmpdir) in f
        assert f"EVE{os.path.sep}0" in f
Пример #26
0
def test_save_path(tmpdir):
    qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0))

    # Test when path is str
    files = Fido.fetch(qr, path=str(tmpdir / "{instrument}" / "{level}"))
    for f in files:
        assert str(tmpdir) in f
        assert "eve{}0".format(os.path.sep) in f
Пример #27
0
def test_srs_current_year():
    year = datetime.date.today().year
    qr = Fido.search(
        a.Instrument("soon")
        & a.Time(f"{year}/01/01", f"{year}/01/01T23:59:29"))
    res = Fido.fetch(qr)
    assert len(res) == 1
    assert res.data[0].endswith(f"{year}0101SRS.txt")
Пример #28
0
def test_save_path_cwd(tmpdir):
    qr = Fido.search(a.Instrument.eve, a.Time("2016/10/01", "2016/10/02"), a.Level.zero)

    # Test when path is ./ for current working directory
    os.chdir(tmpdir)  # move into temp directory
    files = Fido.fetch(qr, path="./")
    for f in files:
        assert pathlib.Path.cwd().joinpath(f).exists()
Пример #29
0
    def download(self, q_id, f_id):
        req = copy.copy(self.queries[q_id])
        req._list = [copy.copy(r) for r in req]
        for resp in req:
            resp[:] = [item for item in resp if item.fileid == f_id]

        self._addLoading([f_id])
        executeTask(lambda x: Fido.fetch(x, progress=False), [req], self._onDownloadResult, [f_id, req])
Пример #30
0
def test_vso_fetch_hmi(tmpdir):
    start_time = "2017-01-25"
    end_time = "2017-01-25T23:59:59"
    results = Fido.search(a.Time(start_time, end_time),
                          a.Instrument.hmi & a.Physobs.los_magnetic_field,
                          a.Sample(1 * u.minute))
    files = Fido.fetch(results[0, 0], path=tmpdir)
    assert len(files) == 1
Пример #31
0
def test_download():
    # Check that clipping the max splits at 3 reliably works for CDAWeb
    # This query has 4 small files
    trange = a.Time('2021/07/01', '2021/07/05')
    dataset = a.cdaweb.Dataset('SOLO_L2_MAG-RTN-NORMAL-1-MINUTE')
    result = Fido.search(trange, dataset)
    assert len(result[0]) == 4
    files = Fido.fetch(result)
    assert len(files.errors) == 0
Пример #32
0
def test_query():
    res = Fido.search(a.Time('2018-11-01', '2018-11-01 01:00:00'),
                      Dataset('WI_H1_SWE') | Dataset('WI_H5_SWE'))
    assert len(res) == 2
    assert len(res[0]) == 1
    assert len(res[1]) == 2

    files = Fido.fetch(res)
    assert len(files) == 3
Пример #33
0
def hmi_fido(
    output_path='/Users/admin/Documents/solarmonitor_2_0/sol_mon/fits_tests/HMI/'
):
    res = Fido.search(
        a.jsoc.Time('2019-01-15T01:00:00', '2019-01-15T02:00:00'),
        a.jsoc.Series('hmi.Ic_noLimbDark_720s_nrt'),
        a.jsoc.Notify('*****@*****.**'))

    dow = Fido.fetch(res, output_path)
Пример #34
0
    def downloadData(self):
        results = Fido.search(self.attrsTime, self.instrument)

        closest = results["gong"][0]
        print(closest)
        self.file = Fido.fetch(closest, path=self.path)  # Fetching only one
        gongmap = Map(self.file)
        self.map = Map(gongmap.data - np.mean(gongmap.data), gongmap.meta)
        return self.map
Пример #35
0
def test_save_path_pathlib(tmpdir):
    qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0))

    # Test when path is pathlib.Path
    target_dir = tmpdir.mkdir("down")
    path = pathlib.Path(target_dir, "{instrument}", "{level}")
    files = Fido.fetch(qr, path=path)
    for f in files:
        assert target_dir.strpath in f
        assert "eve{}0".format(os.path.sep) in f
Пример #36
0
def test_fido(tmp_path, time, instrument, wave):
    with mock.patch('sunpy.net.Fido.search',
                    return_value=UnifiedResponse(mock_query_object(time))):
        path = tmp_path / "sub"
        qr = Fido.search(time, instrument, wave)
        assert isinstance(qr, UnifiedResponse)
        with mock.patch('sunpy.net.Fido.fetch',
                        return_value=UnifiedResponse(mock_query_object(time))):
            response = Fido.fetch(qr, path=path)
            assert len(response) == len(qr)
Пример #37
0
def test_vso_errors_with_second_client(mock_download_all):
    query = a.Time("2011/01/01", "2011/01/02") & (a.Instrument.goes | a.Instrument.eit)
    qr = Fido.search(query)
    res = Fido.fetch(qr)
    assert len(res.errors) == 1
    assert len(res) != qr.file_num
    # Assert that all the XRSClient records are in the output.
    for resp in qr:
        if isinstance(resp, XRSClient):
            assert len(resp) == len(res)
Пример #38
0
def test_save_path_pathlib(tmpdir):
    qr = Fido.search(a.Instrument.eve, a.Time("2016/10/01", "2016/10/02"), a.Level.zero)

    # Test when path is pathlib.Path
    target_dir = tmpdir.mkdir("down")
    path = pathlib.Path(target_dir, "{instrument}", "{level}")
    files = Fido.fetch(qr, path=path)
    for f in files:
        assert target_dir.strpath in f
        assert f"EVE{os.path.sep}0" in f
Пример #39
0
def test_save_path_pathlib():
    pathlib = pytest.importorskip('pathlib')
    qr = Fido.search(a.Instrument('EVE'), a.Time("2016/10/01", "2016/10/02"), a.Level(0))

    # Test when path is pathlib.Path
    with tempfile.TemporaryDirectory() as target_dir:
        path = pathlib.Path(target_dir, "{instrument}", "{level}")
        files = Fido.fetch(qr, path=path)
        for f in files:
            assert target_dir in f
            assert "eve{}0".format(os.path.sep) in f
Пример #40
0
def test_vso_errors_with_second_client(mock_download_all):
    query = a.Time("2011/01/01", "2011/01/02") & (a.Instrument("goes") | a.Instrument("EIT"))

    qr = Fido.search(query)

    res = Fido.fetch(qr)
    assert len(res.errors) == 1
    assert len(res) != qr.file_num

    # Assert that all the XRSClient records are in the output.
    for resp in qr.responses:
        if isinstance(resp, XRSClient):
            assert len(resp) == len(res)
Пример #41
0
def test_retry(mock_retry):
    """
    Test that you can use Fido.fetch to retry failed downloads.
    """
    res = Results()
    res.data.append("/this/worked.fits")

    err1 = FailedDownload("This is not a filename", "http://not.url/test", None)
    err2 = FailedDownload("This is not a filename2", "http://not.url/test2", None)
    res.errors.append(err1)
    res.errors.append(err2)

    mock_retry.return_value._errors += [err2]

    res2 = Fido.fetch(res, Results(["/this/also/worked.fits"]))

    assert res2 is not res

    # Assert that the result of retry ends up in the returned Results() object
    assert res2.data == ["/this/worked.fits", "/tmp/test", "/this/also/worked.fits", "/tmp/test"]
    assert res2.errors == [err2, err2]
Пример #42
0
from sunpy.timeseries import TimeSeries
from sunpy.time import TimeRange, parse_time
from sunpy.net import hek, Fido, attrs as a

###############################################################################
# Let's first grab GOES XRS data for a particular time of interest

tr = TimeRange(['2011-06-07 04:00', '2011-06-07 12:00'])
results = Fido.search(a.Time(tr), a.Instrument('XRS'))
results

###############################################################################
# Then download the data and load it into a TimeSeries

files = Fido.fetch(results)
goes = TimeSeries(files)

###############################################################################
# Next lets grab the HEK data for this time from the NOAA Space Weather
# Prediction Center (SWPC)

client = hek.HEKClient()
flares_hek = client.search(hek.attrs.Time(tr.start, tr.end),
                           hek.attrs.FL, hek.attrs.FRM.Name == 'SWPC')

###############################################################################
# Finally lets plot everything together

goes.peek()
plt.axvline(parse_time(flares_hek[0].get('event_peaktime')))
Пример #43
0
def test_srs_tar_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")
Пример #44
0
###############################################################################
# Now we can see what results we obtained from our search.
# Notice we have two files. One is the full disk image we plan to display
# and the other is a synoptic version of said image.

print(result)

###############################################################################
# Once we are happy with the results obtained from the search.
# We can download the data with `Fido.fetch` .
# In this case we only want one file so we can index the result.
# A `Fido` result can be from several clients, so we have to index the first
# client and then index the first result.

# Slice the first record returned by the first client.
downloaded_file = Fido.fetch(result[0, 0])

###############################################################################
# The ``downloaded_files`` variables returns a list with the path for the file
# that was downloaded.

print(downloaded_file)

###############################################################################
# Now we are going to create a `sunpy.map.Map` object out of the first result.

hmi_map = sunpy.map.Map(downloaded_file)

###############################################################################
# Once we have created our Map, we can plot it quite simply doing:
Пример #45
0
###############################################################################
# We could ask for all SOHO/EIT data between January 1st and 2nd, 2001.

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 result

print(result)

###############################################################################
# Now lets download this query. If we don't provide a path it will download the
# file into the sunpy data directory.

downloaded_files = Fido.fetch(result)

###############################################################################
# You can check where the file was downloaded to.

print(downloaded_files)

###############################################################################
# More complicated queries can be constructed by using relational operators.
# For example, say we are interested in both eit and mdi data.

result = Fido.search(a.Time('2012/3/4', '2012/3/6'),
                     a.Instrument('aia'),
                     a.Wavelength(171*u.angstrom) | a.Wavelength(94*u.angstrom))
print(result)
Пример #46
0
def test_fido(time, instrument):
    qr = Fido.search(time, instrument)
    assert isinstance(qr, UnifiedResponse)
    response = Fido.fetch(qr)
    assert len(response) == qr._numfile
Пример #47
0
def test_fetch():
        qr = Fido.search(a.Instrument('EVE'),
                         a.Time("2016/10/01", "2016/10/02"),
                         a.Level(0))
        res = Fido.fetch(qr)
        assert isinstance(res, Results)
Пример #48
0
def test_downloader_type_error():
    with pytest.raises(TypeError):
        Fido.fetch([], downloader=Results())
Пример #49
0
##############################################################################
# Search for Data

goes_res = Fido.search(a.Time("2010-11-02", "2010-11-07"), a.Instrument('XRS'))
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

goes_ts = sunpy.timeseries.TimeSeries(goes_files, source='XRS', concatenate=True)
norh_ts = sunpy.timeseries.TimeSeries(norh_files, source='NoRH', concatenate=True)


# Combining
large_ts = goes_ts.concatenate(norh_ts)

# ToDo: Fix: plot doesn't work, it's of type goes TS and so it doesn't plot
# non-goes data. Should concanate default to GenericTimeSeries???
Пример #50
0
def test_fido(time, instrument):
    qr = Fido.search(a.Time('2012/10/4', '2012/10/6'), Instrument('goes'))
    assert isinstance(qr, UnifiedResponse)
    response = Fido.fetch(qr)
    assert len(response) == qr._numfile
Пример #51
0
def match_wcs(fiss_file,smooth=False,**kwargs):
    """
    Match the wcs information of FISS files with the SDO/HMI file.
    
    Parameters
    ----------
    fiss_file : str or list
        A single of fiss file or the list of fts file.
    sdo_file : (optional) str
        A SDO/HMI data to use for matching the wcs.
        If False, then download the HMI data on the VSO site.
    dirname : (optional) str
        The directory name for saving the npz data.

        If False, the dirname is the present working directory.
    filename : (optional) str
        The file name for saving the npz data.
        There are no need to add the extension.
        If False, the filename is the date of FISS data.
    sil : (optional) bool
        If False, it print the ongoing time index.
        Default is True.
    sdo_path : (optional) str
        The directory name for saving the HMI data.
    method : (optioinal) bool
        If True, then manually match the wcs.
        If False, you have a no choice to this yet. kkk.
    wvref : (optional) float
        The referenced wavelength for making raster image.
    reflect : (optional) bool
        Correct the reflection of FISS data.
        Default is True.
    alpha : (optional) float
        The transparency of the image to 
    missing : (optional) float
        The extrapolated value of interpolation.
        Default is -1.
        
    Returns
    -------
    match_angle : float
        The angle to rotate the FISS data to match the wcs information.
    wcsx : float
        The x-axis value of image center in WCS arcesec unit.
    wcsy : float
        The y-axis value of image center in WCS arcesec unit.
    
    
    Example
    -------
    >>> from glob import glob
    >>> from fisspy.image import coalignment
    >>> file=glob('*_A1_c.fts')
    >>> dirname='D:\\im\\so\\hot'
    >>> sdo_path='D:\\im\\sdo\\path'
    >>> coalignment.match_wcs(file,dirname=dirname,sil=False,
                              sdo_path=sdo_path)
    
    """
    ref_frame=kwargs.get('ref_frame',len(fiss_file)//2)
    kwargs['ref_frame']=ref_frame
    fiss_file0=fiss_file[ref_frame]
    sdo_file=kwargs.pop('sdo_file',False)
    sil=kwargs.get('sil',False)
    sdo_path=kwargs.pop('sdo_path',os.getcwd())
    
    if not sdo_file:
        h=getheader(fiss_file0)
        tlist=h['date']
        t=Time(tlist,format='isot',scale='ut1')
        tjd=t.jd
        t1=tjd-22/24/3600
        t2=tjd+22/24/3600
        t1=Time(t1,format='jd')
        t2=Time(t2,format='jd')
        t1.format='isot'
        t2.format='isot'
        hmi=(a.Time(t1.value,t2.value),
             a.Instrument('HMI'),
             a.vso.Physobs('intensity'))
        res=Fido.search(hmi)
        if not sil:
            print('Download the SDO/HMI file')
        sdo_file=Fido.fetch(res,path=os.path.join(sdo_path, '{file}'))
        sdo_file=sdo_file[0]
        
        if not sil:
            print('SDO/HMI file name is %s'%sdo_file)
    manual(fiss_file,sdo_file,**kwargs)
    return
Пример #52
0
results = Fido.search(a.Time(start_time, end_time),
                      a.Instrument('HMI') & a.vso.Physobs("LOS_magnetic_field"),
                      a.vso.Sample(60 * u.second))

##############################################################################
# We will only download the first file for the day. For that we use fido
# indexing on the search results which will return the first file for the day.

result = results[0, 0]

##############################################################################
# Download the file. The `fetch` method returns a list of filenames. As we
# used indexing to get the first file of the day, the list contains one
# filename.

file_name = Fido.fetch(result)

##############################################################################
# Download the SRS file.

srs_results = Fido.search(a.Time(start_time, end_time), a.Instrument('SRS_TABLE'))
srs_downloaded_files = Fido.fetch(srs_results)

##############################################################################
# We get one SRS file per day. To read this file, we pass the filename into
# the SRS reader. So now `srs_table` contains an astropy table.

srs_table = srs.read_srs(srs_downloaded_files[0])
print(srs_table)

##############################################################################
       a.Time('2011-01-01', '2011-01-02'))

wave = a.Wavelength(30 * u.nm, 31 * u.nm)


res = Fido.search(wave, aia | stereo)

###############################################################################
# The results from VSO query:
print(res)


###############################################################################
# Download the files:

files = Fido.fetch(res)
print(files)

###############################################################################
# Create a dictionary with the two maps, cropped down to full disk.
maps = {m.detector: m.submap(SkyCoord([-1100, 1100]*u.arcsec,
                                      [-1100, 1100]*u.arcsec,
                                      frame=m.coordinate_frame))
        for m in sunpy.map.Map(files)}

###############################################################################
# Plot both maps
fig = plt.figure(figsize=(10, 4))
for i, m in enumerate(maps.values()):
    ax = fig.add_subplot(1, 2, i+1, projection=m.wcs)
    m.plot(axes=ax)
Пример #54
0
ts_lyra = sunpy.timeseries.TimeSeries(sunpy.data.sample.LYRA_LEVEL3_TIMESERIES, source='LYRA')
ts_noaa_ind = sunpy.timeseries.TimeSeries(
    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.
# Debate: are we OK for one source at a time?

##############################################################################
Пример #55
0
def test_srs_current_year():
    year = datetime.date.today().year
    qr = Fido.search(a.Instrument("soon") & a.Time(f"{year}/01/01", f"{year}/01/01T23:59:29"))
    res = Fido.fetch(qr)
    assert len(res) == 1
    assert res.data[0].endswith(f"{year}0101SRS.txt")
Пример #56
0
def test_mixed_retry_error():
    with pytest.raises(TypeError):
        Fido.fetch([], Results())