Exemplo n.º 1
0
def test_split_series_using_lytaf():
    '''test the downloading of the LYTAF file and subsequent queries'''
    tmp_dir = tempfile.mkdtemp()
    lyra.download_lytaf_database(lytaf_dir=tmp_dir)
    assert os.path.exists(os.path.join(tmp_dir, 'annotation_ppt.db'))

    # test split_series_using_lytaf
    # construct a dummy signal for testing purposes
    basetime = parse_time('2010-06-13 02:00')
    seconds = 3600
    dummy_time = [basetime + TimeDelta(s*u.second) for s in range(seconds)]
    dummy_data = np.random.random(seconds)

    lytaf_tmp = lyra.get_lytaf_events('2010-06-13 02:00', '2010-06-13 06:00',
                                      lytaf_path=tmp_dir,
                                      combine_files=["ppt"])
    split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp)
    assert type(split) == list
    assert len(split) == 4
    assert is_time_equal(split[0]['subtimes'][0], parse_time((2010, 6, 13, 2, 0)))
    assert is_time_equal(split[0]['subtimes'][-1], parse_time((2010, 6, 13, 2, 7, 2)))
    assert is_time_equal(split[3]['subtimes'][0], parse_time((2010, 6, 13, 2, 59, 42)))
    assert is_time_equal(split[3]['subtimes'][-1], parse_time((2010, 6, 13, 2, 59, 58)))

    # Test case when no LYTAF events found in time series.
    split_no_lytaf = lyra.split_series_using_lytaf(dummy_time,
                                                   dummy_data, LYTAF_TEST)
    assert type(split_no_lytaf) == list
    assert type(split_no_lytaf[0]) == dict
    assert not set(split_no_lytaf[0].keys()).symmetric_difference({'subtimes', 'subdata'})
    assert split_no_lytaf[0]["subtimes"] == dummy_time
    assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
Exemplo n.º 2
0
def test_split(timerange_a):
    expect = [sunpy.time.TimeRange('2012/1/1T00:00:00', '2012/1/1T12:00:00'),
              sunpy.time.TimeRange('2012/1/1T12:00:00', '2012/1/2T00:00:00')]
    split = timerange_a.split(n=2)
    # Doing direct comparisons seem to not work
    assert all([is_time_equal(wi.start, ex.start) and is_time_equal(wi.end, ex.end)
                for wi, ex in zip(split, expect)])
Exemplo n.º 3
0
def test_split_series_using_lytaf():
    """
    test the downloading of the LYTAF file and subsequent queries.
    """
    # test split_series_using_lytaf
    # construct a dummy signal for testing purposes
    basetime = parse_time('2010-06-13 02:00')
    seconds = 3600
    dummy_time = [basetime + TimeDelta(s * u.second) for s in range(seconds)]
    dummy_data = np.random.random(seconds)

    lytaf_tmp = lyra.get_lytaf_events('2010-06-13 02:00',
                                      '2010-06-13 06:00',
                                      combine_files=["ppt"])
    split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp)
    assert type(split) == list
    assert len(split) == 4
    assert is_time_equal(split[0]['subtimes'][0],
                         parse_time((2010, 6, 13, 2, 0)))
    assert is_time_equal(split[0]['subtimes'][-1],
                         parse_time((2010, 6, 13, 2, 7, 2)))
    assert is_time_equal(split[3]['subtimes'][0],
                         parse_time((2010, 6, 13, 2, 59, 42)))
    assert is_time_equal(split[3]['subtimes'][-1],
                         parse_time((2010, 6, 13, 2, 59, 58)))

    # Test case when no LYTAF events found in time series.
    split_no_lytaf = lyra.split_series_using_lytaf(dummy_time, dummy_data,
                                                   LYTAF_TEST)
    assert type(split_no_lytaf) == list
    assert type(split_no_lytaf[0]) == dict
    assert not set(split_no_lytaf[0].keys()).symmetric_difference(
        {'subtimes', 'subdata'})
    assert split_no_lytaf[0]["subtimes"] == dummy_time
    assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
Exemplo n.º 4
0
def testis_time_equal_not_equal():
    t1 = Time('1995-12-31T23:59:59', format='isot')
    t2 = Time('1995-12-31T23:59:60', format='isot')

    assert not is_time_equal(t1, t2)

    t1 = Time('1995-12-31T23:59:59', format='isot')
    t2 = Time('1995-12-31T23:59:59', format='isot') + TimeDelta(2*u.nanosecond)

    assert not is_time_equal(t1, t2)
Exemplo n.º 5
0
def testis_time_equal():
    t1 = Time('1995-12-31T23:59:60', format='isot')
    t2 = Time('1995-12-31T23:59:60', format='isot')

    assert is_time_equal(t1, t2)

    t1 = Time('1995-12-31T23:59:59', format='isot')
    t2 = Time(datetime(1995, 12, 31, 23, 59, 59), format='datetime')

    assert is_time_equal(t1, t2)

    t1 = Time('1995-12-31T23:59:60', format='isot')
    t2 = Time('1995-12-31T23:59:60', format='isot') + TimeDelta(0*u.day)

    assert is_time_equal(t1, t2)
Exemplo n.º 6
0
def test_parse_time_ISO():
    dt1 = Time('1966-02-03T20:17:40')
    assert parse_time('1966-02-03').jd == LANDING.jd
    assert (parse_time('1966-02-03T20:17:40') == dt1)
    assert (parse_time('19660203T201740') == dt1)

    dt2 = Time('2007-05-04T21:08:12.999999')
    dt3 = Time('2007-05-04T21:08:12')
    dt4 = Time('2007-05-04T21:08:00')
    dt5 = Time('2007-05-04')

    lst = [
        ('2007-05-04T21:08:12.999999', dt2),
        ('20070504T210812.999999', dt2),
        ('2007/05/04 21:08:12.999999', dt2),
        ('2007-05-04 21:08:12.999999', dt2),
        ('2007/05/04 21:08:12', dt3),
        ('2007-05-04 21:08:12', dt3),
        ('2007-05-04 21:08', dt4),
        ('2007-05-04T21:08:12', dt3),
        ('20070504T210812', dt3),
        ('2007-May-04 21:08:12', dt3),
        ('2007-May-04 21:08', dt4),
        ('2007-May-04', dt5),
        ('2007-05-04', dt5),
        ('2007/05/04', dt5),
        ('04-May-2007', dt5),
        ('04-May-2007 21:08:12.999999', dt2),
        ('20070504_210812', dt3),
    ]

    for k, v in lst:
        dt = parse_time(k)
        assert is_time_equal(dt, v)
        assert dt.format == 'isot'
Exemplo n.º 7
0
def test_roi_times_list_two_elements():
    region = roi(times=['2012-06-20 05:00', '2012-06-20 07:00'])
    expected_start_time = parse_time((2012, 6, 20, 5, 0))
    expected_end_time = parse_time((2012, 6, 20, 7, 0))
    assert (region.start_time == expected_start_time)
    assert (is_time_equal(region.end_time,
                          expected_end_time))  # A float comparison error
Exemplo n.º 8
0
def test_backprojection():
    """
    Test that backprojection returns a map with the expected time.
    """
    test_filename = 'hsi_calib_ev_20020220_1106_20020220_1106_25_40.fits'
    amap = rhessi.backprojection(get_test_filepath(test_filename))
    assert isinstance(amap, sunpy.map.GenericMap)
    assert is_time_equal(amap.date, parse_time((2002, 2, 20, 11, 6, 21)))
Exemplo n.º 9
0
def test_backprojection():
    """
    Test that backprojection returns a map with the expected time.
    """
    test_filename = 'hsi_calib_ev_20020220_1106_20020220_1106_25_40.fits'
    amap = rhessi.backprojection(get_test_filepath(test_filename))
    assert isinstance(amap, sunpy.map.GenericMap)
    assert is_time_equal(amap.date, parse_time((2002, 2, 20, 11, 6, 21)))
Exemplo n.º 10
0
    def __ne__(self, other):
        """
        Check two TimeRange objects have different start or end datetimes.

        Parameters
        ----------
        other : `~sunpy.time.timerange.TimeRange`
            The second TimeRange object to compare to.

        Returns
        -------
        result : `bool`
        """
        if isinstance(other, TimeRange):
            return not (is_time_equal(self.start, other.start)
                        and is_time_equal(self.end, other.end))

        return NotImplemented
Exemplo n.º 11
0
    def __ne__(self, other):
        """
        Check two `sunpy.time.TimeRange` have different start or end datetimes.

        Parameters
        ----------
        other : `~sunpy.time.timerange.TimeRange`
            The second `sunpy.time.TimeRange` to compare to.

        Returns
        -------
        `bool`
            `True` if non-equal, `False` otherwise.
        """
        if isinstance(other, TimeRange):
            return not (is_time_equal(self.start, other.start) and is_time_equal(self.end, other.end))

        return NotImplemented
Exemplo n.º 12
0
    def __ne__(self, other):
        """
        Check two `sunpy.time.TimeRange` have different start or end datetimes.

        Parameters
        ----------
        other : `~sunpy.time.timerange.TimeRange`
            The second `sunpy.time.TimeRange` to compare to.

        Returns
        -------
        `bool`
            `True` if non-equal, `False` otherwise.
        """
        if isinstance(other, TimeRange):
            return not (is_time_equal(
                self.start, other.start) and is_time_equal(self.end, other.end))

        return NotImplemented
Exemplo n.º 13
0
def test_query(LCClient, time):
    qr1 = LCClient.search(time, Instrument('XRS'))
    assert isinstance(qr1, QueryResponse)
    # We only compare dates here as the start time of the qr will always be the
    # start of the day.
    assert qr1.time_range().start.strftime('%Y-%m-%d') == time.start.strftime('%Y-%m-%d')

    almost_day = TimeDelta(1*u.day - 1*u.millisecond)
    end = parse_time(time.end.strftime('%Y-%m-%d')) + almost_day
    assert is_time_equal(qr1.time_range().end, end)
Exemplo n.º 14
0
    def __eq__(self, other):
        """
        Check that two `sunpy.time.TimeRange` have the same start and end
        datetime.

        Parameters
        ----------
        other : `~sunpy.time.timerange.TimeRange`
            The second `sunpy.time.TimeRange` to compare to.

        Returns
        -------
        `bool`
            `True` if equal, `False` otherwise.
        """
        if isinstance(other, TimeRange):
            return is_time_equal(self.start, other.start) and is_time_equal(self.end, other.end)

        return NotImplemented
Exemplo n.º 15
0
def test_query(LCClient, time):
    qr1 = LCClient.search(time, Instrument('XRS'))
    assert isinstance(qr1, QueryResponse)
    # We only compare dates here as the start time of the qr will always be the
    # start of the day.
    assert qr1.time_range().start.strftime('%Y-%m-%d') == time.start.strftime('%Y-%m-%d')

    almost_day = TimeDelta(1*u.day - 1*u.millisecond)
    end = parse_time(time.end.strftime('%Y-%m-%d')) + almost_day
    assert is_time_equal(qr1.time_range().end, end)
Exemplo n.º 16
0
    def __eq__(self, other):
        """
        Check that two `sunpy.time.TimeRange` have the same start and end
        datetime.

        Parameters
        ----------
        other : `~sunpy.time.timerange.TimeRange`
            The second `sunpy.time.TimeRange` to compare to.

        Returns
        -------
        `bool`
            `True` if equal, `False` otherwise.
        """
        if isinstance(other, TimeRange):
            return is_time_equal(
                self.start, other.start) and is_time_equal(self.end, other.end)

        return NotImplemented
Exemplo n.º 17
0
def test_parse_time_scale(scale):
    dt = parse_time('2007-05-04T21:08:12', scale=scale)
    dt2 = Time('2007-05-04T21:08:12', scale=scale)
    assert is_time_equal(dt, dt2)
    assert dt.scale == scale

    dt = parse_time(np.datetime64('2007-05-04T21:08:12'), scale=scale)
    dt2 = Time('2007-05-04T21:08:12', scale=scale)
    assert dt == dt2
    assert dt.scale == scale

    dt = datetime(2014, 2, 7, 16, 47, 51)
    dt = parse_time(dt, scale=scale)
    dt2 = Time('2014-02-07T16:47:51', scale=scale)
    assert dt == dt2
    assert dt.scale == scale

    dt = date(2014, 2, 7)
    dt = parse_time(dt, scale=scale)
    dt2 = Time('2014-02-07', scale=scale)
    assert dt == dt2
    assert dt.scale == scale
Exemplo n.º 18
0
def test_parse_time_scale(scale):
    dt = parse_time('2007-05-04T21:08:12', scale=scale)
    dt2 = Time('2007-05-04T21:08:12', scale=scale)
    assert is_time_equal(dt, dt2)
    assert dt.scale == scale

    dt = parse_time(np.datetime64('2007-05-04T21:08:12'), scale=scale)
    dt2 = Time('2007-05-04T21:08:12', scale=scale)
    assert dt == dt2
    assert dt.scale == scale

    dt = datetime(2014, 2, 7, 16, 47, 51)
    dt = parse_time(dt, scale=scale)
    dt2 = Time('2014-02-07T16:47:51', scale=scale)
    assert dt == dt2
    assert dt.scale == scale

    dt = date(2014, 2, 7)
    dt = parse_time(dt, scale=scale)
    dt2 = Time('2014-02-07', scale=scale)
    assert dt == dt2
    assert dt.scale == scale
Exemplo n.º 19
0
def test_parse_time_ISO():
    dt1 = Time('1966-02-03T20:17:40')
    assert parse_time('1966-02-03').jd == LANDING.jd
    assert (
        parse_time('1966-02-03T20:17:40') == dt1
    )
    assert (
        parse_time('19660203T201740') == dt1
    )

    dt2 = Time('2007-05-04T21:08:12.999999')
    dt3 = Time('2007-05-04T21:08:12')
    dt4 = Time('2007-05-04T21:08:00')
    dt5 = Time('2007-05-04')

    lst = [
        ('2007-05-04T21:08:12.999999', dt2),
        ('20070504T210812.999999', dt2),
        ('2007/05/04 21:08:12.999999', dt2),
        ('2007-05-04 21:08:12.999999', dt2),
        ('2007/05/04 21:08:12', dt3),
        ('2007-05-04 21:08:12', dt3),
        ('2007-05-04 21:08', dt4),
        ('2007-05-04T21:08:12', dt3),
        ('20070504T210812', dt3),
        ('2007-May-04 21:08:12', dt3),
        ('2007-May-04 21:08', dt4),
        ('2007-May-04', dt5),
        ('2007-05-04', dt5),
        ('2007/05/04', dt5),
        ('04-May-2007', dt5),
        ('04-May-2007 21:08:12.999999', dt2),
        ('20070504_210812', dt3),
    ]

    for k, v in lst:
        dt = parse_time(k)
        assert is_time_equal(dt, v)
        assert dt.format == 'isot'
Exemplo n.º 20
0
def test_goes_event_list():
    # Set a time range to search
    trange = TimeRange('2011-06-07 00:00', '2011-06-08 00:00')
    # Test case where GOES class filter is applied
    result = goes.get_goes_event_list(trange, goes_class_filter='M1')
    assert type(result) == list
    assert type(result[0]) == dict
    assert type(result[0]['event_date']) == str
    assert type(result[0]['goes_location']) == tuple
    assert isinstance(result[0]['peak_time'], Time)
    assert isinstance(result[0]['start_time'], Time)
    assert isinstance(result[0]['end_time'], Time)
    assert type(result[0]['goes_class']) == str
    assert type(result[0]['noaa_active_region']) == np.int64
    assert result[0]['event_date'] == '2011-06-07'
    assert result[0]['goes_location'] == (54, -21)
    # float errror
    assert is_time_equal(result[0]['start_time'],
                         parse_time((2011, 6, 7, 6, 16)))
    assert is_time_equal(result[0]['peak_time'], parse_time(
        (2011, 6, 7, 6, 41)))
    assert is_time_equal(result[0]['end_time'], parse_time(
        (2011, 6, 7, 6, 59)))
    assert result[0]['goes_class'] == 'M2.5'
    assert result[0]['noaa_active_region'] == 11226
    # Test case where GOES class filter not applied
    result = goes.get_goes_event_list(trange)
    assert type(result) == list
    assert type(result[0]) == dict
    assert type(result[0]['event_date']) == str
    assert type(result[0]['goes_location']) == tuple
    assert isinstance(result[0]['peak_time'], Time)
    assert isinstance(result[0]['start_time'], Time)
    assert isinstance(result[0]['end_time'], Time)
    assert type(result[0]['goes_class']) == str
    assert type(result[0]['noaa_active_region']) == np.int64
    assert result[0]['event_date'] == '2011-06-07'
    assert result[0]['goes_location'] == (54, -21)
    assert is_time_equal(result[0]['start_time'],
                         parse_time((2011, 6, 7, 6, 16)))
    assert is_time_equal(result[0]['peak_time'], parse_time(
        (2011, 6, 7, 6, 41)))
    assert is_time_equal(result[0]['end_time'], parse_time(
        (2011, 6, 7, 6, 59)))
    assert result[0]['goes_class'] == 'M2.5'
    assert result[0]['noaa_active_region'] == 11226
Exemplo n.º 21
0
def test_center(timerange_a):
    assert is_time_equal(timerange_a.center, Time('2012-1-1T12:00:00'))
Exemplo n.º 22
0
def test_roi_times_list_two_elements():
    region = roi(times=['2012-06-20 05:00', '2012-06-20 07:00'])
    expected_start_time = parse_time((2012, 6, 20, 5, 0))
    expected_end_time = parse_time((2012, 6, 20, 7, 0))
    assert (region.start_time == expected_start_time)
    assert (is_time_equal(region.end_time, expected_end_time))  # A float comparison error
Exemplo n.º 23
0
def test_split(timerange_a):
    expect = [sunpy.time.TimeRange('2012/1/1T00:00:00', '2012/1/1T12:00:00'),
              sunpy.time.TimeRange('2012/1/1T12:00:00', '2012/1/2T00:00:00')]
    split = timerange_a.split(n=2)
    # Doing direct comparisons seem to not work
    assert all([is_time_equal(wi.start, ex.start) and is_time_equal(wi.end, ex.end) for wi, ex in zip(split, expect)])
Exemplo n.º 24
0
def test_center(timerange_a):
    assert is_time_equal(timerange_a.center, Time('2012-1-1T12:00:00'))