Exemple #1
0
def test_tconvert():
    """Test :func:`gwpy.time.tconvert`
    """
    # from GPS
    assert time.tconvert(1126259462.391) == (
        datetime(2015, 9, 14, 9, 50, 45, 391000))

    # from GPS using LAL LIGOTimeGPS
    assert time.tconvert(time.LIGOTimeGPS(1126259462.391)) == (
        datetime(2015, 9, 14, 9, 50, 45, 391000))
    assert time.tconvert(GlueGPS(1126259462.391)) == (
        datetime(2015, 9, 14, 9, 50, 45, 391000))

    # to GPS
    assert time.tconvert(datetime(2015, 9, 14, 9, 50, 45, 391000)) == (
        time.LIGOTimeGPS(1126259462, 391000000))

    # special cases
    now = time.tconvert()
    now2 = time.tconvert('now')
    assert now == now2
    today = float(time.tconvert('today'))
    yesterday = float(time.tconvert('yesterday'))
    assert today - yesterday == pytest.approx(86400)
    assert now >= today
    tomorrow = float(time.tconvert('tomorrow'))
    assert tomorrow - today == pytest.approx(86400)
Exemple #2
0
@pytest.mark.parametrize(
    'in_, out',
    [
        (1126259462, int(GW150914)),
        (LIGOTimeGPS(1126259462, 391000000), GW150914),
        ('0', 0),
        ('Jan 1 2017', 1167264018),
        ('Sep 14 2015 09:50:45.391', GW150914),
        ((2017, 1, 1), 1167264018),
        (datetime(2017, 1, 1), 1167264018),
        (Time(57754, format='mjd'), 1167264018),
        (Time(57754.0001, format='mjd'), LIGOTimeGPS(1167264026, 640000000)),
        (Quantity(1167264018, 's'), 1167264018),
        (Decimal('1126259462.391000000'), GW150914),
        pytest.param(GlueGPS(GW150914.gpsSeconds, GW150914.gpsNanoSeconds),
                     GW150914,
                     marks=skipglue),
        (numpy.int32(NOW), NOW),  # fails with lal-6.18.0
        ('now', NOW),
        ('today', TODAY),
        ('tomorrow', TOMORROW),
        ('yesterday', YESTERDAY),
        (Quantity(1, 'm'), UnitConversionError),
        ('random string', (ValueError, TypeError)),
    ])
def test_to_gps(in_, out):
    """Test :func:`gwpy.time.to_gps`
    """
    _test_with_errors(time.to_gps, in_, out)
Exemple #3
0
@pytest.mark.parametrize(
    'in_, out',
    [
        (1126259462, int(GW150914)),
        (1235635623.7500002, LIGOTimeGPS(1235635623, 750000200)),
        (LIGOTimeGPS(1126259462, 391000000), GW150914),
        ('0', 0),
        ('Jan 1 2017', 1167264018),
        ('Sep 14 2015 09:50:45.391', GW150914),
        ((2017, 1, 1), 1167264018),
        (datetime(2017, 1, 1), 1167264018),
        (Time(57754, format='mjd'), 1167264018),
        (Time(57754.0001, format='mjd'), LIGOTimeGPS(1167264026, 640000000)),
        (Quantity(1167264018, 's'), 1167264018),
        (Decimal('1126259462.391000000'), GW150914),
        pytest.param(GlueGPS(GW150914.gpsSeconds, GW150914.gpsNanoSeconds),
                     GW150914,
                     marks=skip_missing_dependency('glue')),
        (numpy.int32(NOW), NOW),  # fails with lal-6.18.0
        ('now', NOW),
        ('today', TODAY),
        ('tomorrow', TOMORROW),
        ('yesterday', YESTERDAY),
        (Quantity(1, 'm'), UnitConversionError),
        ('random string', (ValueError, TypeError)),
        pytest.param('Oct 30 2016 12:34 CST',
                     1161887657,
                     marks=skip_missing_dependency('maya')),
    ])
def test_to_gps(in_, out):
    """Test :func:`gwpy.time.to_gps`