def test_get_sun_rise_set_transit():
    south = Location(-35.0, 0.0, tz='UTC')
    times = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 0),
                              datetime.datetime(2004, 12, 4, 0)]
                             ).tz_localize('UTC')
    sunrise = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 7, 8, 15, 471676),
                                datetime.datetime(2004, 12, 4, 4, 38, 57, 27416)]
                               ).tz_localize('UTC').tolist()
    sunset = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 17, 1, 4, 479889),
                               datetime.datetime(2004, 12, 4, 19, 2, 2, 499704)]
                              ).tz_localize('UTC').tolist()
    result = solarposition.get_sun_rise_set_transit(times, south, 
                                                    delta_t=64.0)
    frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times)
    del result['transit']
    assert_frame_equal(frame, result)


    # tests from USNO
    # Golden
    golden = Location(39.0, -105.0, tz='MST')
    times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2),
                              datetime.datetime(2015, 8, 2),]
                             ).tz_localize('MST')
    sunrise = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 7, 19, 2, 225169),
                                datetime.datetime(2015, 8, 2, 5, 1, 26, 963145)
                                ]).tz_localize('MST').tolist()
    sunset = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 16, 49, 10, 13145),
                               datetime.datetime(2015, 8, 2, 19, 11, 31, 816401)
                               ]).tz_localize('MST').tolist()
    result = solarposition.get_sun_rise_set_transit(times, golden, delta_t=64.0)
    frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times)
    del result['transit']
    assert_frame_equal(frame, result)
Example #2
0
def test_get_sun_rise_set_transit():
    south = Location(-35.0, 0.0, tz='UTC')
    times = pd.DatetimeIndex(
        [datetime.datetime(1996, 7, 5, 0),
         datetime.datetime(2004, 12, 4, 0)]).tz_localize('UTC')
    sunrise = pd.DatetimeIndex([
        datetime.datetime(1996, 7, 5, 7, 8, 15),
        datetime.datetime(2004, 12, 4, 4, 38, 57)
    ]).tz_localize('UTC').tolist()
    sunset = pd.DatetimeIndex([
        datetime.datetime(1996, 7, 5, 17, 1, 4),
        datetime.datetime(2004, 12, 4, 19, 2, 2)
    ]).tz_localize('UTC').tolist()
    result = solarposition.get_sun_rise_set_transit(times,
                                                    south.latitude,
                                                    south.longitude,
                                                    delta_t=64.0)
    frame = pd.DataFrame({'sunrise': sunrise, 'sunset': sunset}, index=times)
    result_rounded = pd.DataFrame(index=result.index)
    # need to iterate because to_datetime does not accept 2D data
    # the rounding fails on pandas < 0.17
    for col, data in result.iteritems():
        result_rounded[col] = pd.to_datetime(
            np.floor(data.values.astype(np.int64) / 1e9) * 1e9, utc=True)

    del result_rounded['transit']
    assert_frame_equal(frame, result_rounded)

    # tests from USNO
    # Golden
    golden = Location(39.0, -105.0, tz='MST')
    times = pd.DatetimeIndex([
        datetime.datetime(2015, 1, 2),
        datetime.datetime(2015, 8, 2),
    ]).tz_localize('MST')
    sunrise = pd.DatetimeIndex([
        datetime.datetime(2015, 1, 2, 7, 19, 2),
        datetime.datetime(2015, 8, 2, 5, 1, 26)
    ]).tz_localize('MST').tolist()
    sunset = pd.DatetimeIndex([
        datetime.datetime(2015, 1, 2, 16, 49, 10),
        datetime.datetime(2015, 8, 2, 19, 11, 31)
    ]).tz_localize('MST').tolist()
    result = solarposition.get_sun_rise_set_transit(times,
                                                    golden.latitude,
                                                    golden.longitude,
                                                    delta_t=64.0)
    frame = pd.DataFrame({'sunrise': sunrise, 'sunset': sunset}, index=times)
    result_rounded = pd.DataFrame(index=result.index)
    # need to iterate because to_datetime does not accept 2D data
    # the rounding fails on pandas < 0.17
    for col, data in result.iteritems():
        result_rounded[col] = (pd.to_datetime(
            np.floor(data.values.astype(np.int64) / 1e9) * 1e9,
            utc=True).tz_convert('MST'))

    del result_rounded['transit']
    assert_frame_equal(frame, result_rounded)
def test_get_sun_rise_set_transit():
    south = Location(-35.0, 0.0, tz='UTC')
    times = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 0),
                              datetime.datetime(2004, 12, 4, 0)]
                             ).tz_localize('UTC')
    sunrise = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 7, 8, 15),
                                datetime.datetime(2004, 12, 4, 4, 38, 57)]
                               ).tz_localize('UTC').tolist()
    sunset = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 17, 1, 4),
                               datetime.datetime(2004, 12, 4, 19, 2, 2)]
                              ).tz_localize('UTC').tolist()
    result = solarposition.get_sun_rise_set_transit(times, south.latitude,
                                                    south.longitude,
                                                    delta_t=64.0)
    frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times)
    result_rounded = pd.DataFrame(index=result.index)
    # need to iterate because to_datetime does not accept 2D data
    # the rounding fails on pandas < 0.17
    for col, data in result.iteritems():
        result_rounded[col] = pd.to_datetime(
            np.floor(data.values.astype(np.int64) / 1e9)*1e9, utc=True)

    del result_rounded['transit']
    assert_frame_equal(frame, result_rounded)


    # tests from USNO
    # Golden
    golden = Location(39.0, -105.0, tz='MST')
    times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2),
                              datetime.datetime(2015, 8, 2),]
                             ).tz_localize('MST')
    sunrise = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 7, 19, 2),
                                datetime.datetime(2015, 8, 2, 5, 1, 26)
                                ]).tz_localize('MST').tolist()
    sunset = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 16, 49, 10),
                               datetime.datetime(2015, 8, 2, 19, 11, 31)
                               ]).tz_localize('MST').tolist()
    result = solarposition.get_sun_rise_set_transit(times, golden.latitude,
                                                    golden.longitude,
                                                    delta_t=64.0)
    frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times)
    result_rounded = pd.DataFrame(index=result.index)
    # need to iterate because to_datetime does not accept 2D data
    # the rounding fails on pandas < 0.17
    for col, data in result.iteritems():
        result_rounded[col] = (pd.to_datetime(
            np.floor(data.values.astype(np.int64) / 1e9)*1e9, utc=True)
            .tz_convert('MST'))

    del result_rounded['transit']
    assert_frame_equal(frame, result_rounded)
Example #4
0
def test_get_sun_rise_set_transit(expected_rise_set_spa, golden):
    south = Location(-35.0, 0.0, tz='UTC')
    times = pd.DatetimeIndex(
        [datetime.datetime(1996, 7, 5, 0),
         datetime.datetime(2004, 12, 4, 0)]).tz_localize('UTC')
    sunrise = pd.DatetimeIndex([
        datetime.datetime(1996, 7, 5, 7, 8, 15),
        datetime.datetime(2004, 12, 4, 4, 38, 57)
    ]).tz_localize('UTC').tolist()
    sunset = pd.DatetimeIndex([
        datetime.datetime(1996, 7, 5, 17, 1, 4),
        datetime.datetime(2004, 12, 4, 19, 2, 3)
    ]).tz_localize('UTC').tolist()
    frame = pd.DataFrame({'sunrise': sunrise, 'sunset': sunset}, index=times)

    result = solarposition.get_sun_rise_set_transit(times,
                                                    south.latitude,
                                                    south.longitude,
                                                    delta_t=65.0)
    result_rounded = pd.DataFrame(index=result.index)
    # need to iterate because to_datetime does not accept 2D data
    # the rounding fails on pandas < 0.17
    for col, data in result.iteritems():
        result_rounded[col] = data.dt.round('1s')

    del result_rounded['transit']
    assert_frame_equal(frame, result_rounded)

    # test for Golden, CO compare to NREL SPA
    result = solarposition.get_sun_rise_set_transit(
        expected_rise_set_spa.index,
        golden.latitude,
        golden.longitude,
        delta_t=65.0)

    # round to nearest minute
    result_rounded = pd.DataFrame(index=result.index)
    # need to iterate because to_datetime does not accept 2D data
    for col, data in result.iteritems():
        result_rounded[col] = data.dt.round('s').tz_convert('MST')

    assert_frame_equal(expected_rise_set_spa, result_rounded)
Example #5
0
def test_deprecated_07():
    tt = pd.DatetimeIndex(['2015-01-01 00:00:00']).tz_localize('MST')
    with pytest.warns(pvlibDeprecationWarning):
        solarposition.get_sun_rise_set_transit(tt, 39.7, -105.2)
def test_deprecated_07():
    tt = pd.DatetimeIndex(['2015-01-01 00:00:00']).tz_localize('MST')
    with pytest.warns(pvlibDeprecationWarning):
        solarposition.get_sun_rise_set_transit(tt,
                                               39.7,
                                               -105.2)