How to use the pytesmo.timedate.julian.doy function in pytesmo

To help you get started, we’ve selected a few pytesmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUW-GEO / pytesmo / tests / test_timedate / test_julian.py View on Github external
def test_doy():
    day_of_year = doy(1, 28)
    assert day_of_year == 28
    day_of_year = doy(2, 29)
    assert day_of_year == 31 + 29
    day_of_year = doy(3, 1, year=2004)
    assert day_of_year == 31 + 29 + 1
    # test numpy arrays as input
    days = np.array([28, 29, 1], dtype=int)
    months = np.array([1, 2, 3])
    days_of_year = doy(months, days, year=np.array([2005, 2004, 2004]))
    nptest.assert_allclose(days_of_year, np.array([28,
                                                   31 + 29,
                                                   31 + 29 + 1]))

    days_of_year = doy(months, days, year=2004)
    nptest.assert_allclose(days_of_year, np.array([28,
                                                   31 + 29,
github TUW-GEO / pytesmo / tests / test_timedate / test_julian.py View on Github external
def test_doy():
    day_of_year = doy(1, 28)
    assert day_of_year == 28
    day_of_year = doy(2, 29)
    assert day_of_year == 31 + 29
    day_of_year = doy(3, 1, year=2004)
    assert day_of_year == 31 + 29 + 1
    # test numpy arrays as input
    days = np.array([28, 29, 1], dtype=int)
    months = np.array([1, 2, 3])
    days_of_year = doy(months, days, year=np.array([2005, 2004, 2004]))
    nptest.assert_allclose(days_of_year, np.array([28,
                                                   31 + 29,
                                                   31 + 29 + 1]))

    days_of_year = doy(months, days, year=2004)
    nptest.assert_allclose(days_of_year, np.array([28,
                                                   31 + 29,
                                                   31 + 29 + 1]))
github TUW-GEO / pytesmo / tests / test_timedate / test_julian.py View on Github external
def test_doy():
    day_of_year = doy(1, 28)
    assert day_of_year == 28
    day_of_year = doy(2, 29)
    assert day_of_year == 31 + 29
    day_of_year = doy(3, 1, year=2004)
    assert day_of_year == 31 + 29 + 1
    # test numpy arrays as input
    days = np.array([28, 29, 1], dtype=int)
    months = np.array([1, 2, 3])
    days_of_year = doy(months, days, year=np.array([2005, 2004, 2004]))
    nptest.assert_allclose(days_of_year, np.array([28,
                                                   31 + 29,
                                                   31 + 29 + 1]))

    days_of_year = doy(months, days, year=2004)
    nptest.assert_allclose(days_of_year, np.array([28,
                                                   31 + 29,
                                                   31 + 29 + 1]))
github TUW-GEO / pytesmo / src / pytesmo / time_series / anomaly.py View on Github external
Ser = pd.DataFrame(Ser)

    if type(Ser.index) == pd.DatetimeIndex:
        year, month, day = (np.asarray(Ser.index.year),
                            np.asarray(Ser.index.month),
                            np.asarray(Ser.index.day))
    else:
        year, month, day = julian2date(Ser.index.values)[0:3]




    if respect_leap_years:
        doys = doy(month, day, year)
    else:
        doys = doy(month, day)


    Ser['doy'] = doys

    if median:
        clim = Ser.groupby('doy').median()
    else:
        clim = Ser.groupby('doy').mean()

    clim_ser = pd.Series(clim.values.flatten(),
                         index=clim.index.values)

    if interpolate_leapday and not respect_leap_years:
        clim_ser[60] = np.mean((clim_ser[59], clim_ser[61]))
    elif interpolate_leapday and respect_leap_years:
        clim_ser[366] = np.mean((clim_ser[365], clim_ser[1]))
github TUW-GEO / pytesmo / src / pytesmo / time_series / anomaly.py View on Github external
Ser = moving_average(Ser, window_size=moving_avg_orig, fillna=fillna, min_obs=min_obs_orig)

    Ser = pd.DataFrame(Ser)

    if type(Ser.index) == pd.DatetimeIndex:
        year, month, day = (np.asarray(Ser.index.year),
                            np.asarray(Ser.index.month),
                            np.asarray(Ser.index.day))
    else:
        year, month, day = julian2date(Ser.index.values)[0:3]




    if respect_leap_years:
        doys = doy(month, day, year)
    else:
        doys = doy(month, day)


    Ser['doy'] = doys

    if median:
        clim = Ser.groupby('doy').median()
    else:
        clim = Ser.groupby('doy').mean()

    clim_ser = pd.Series(clim.values.flatten(),
                         index=clim.index.values)

    if interpolate_leapday and not respect_leap_years:
        clim_ser[60] = np.mean((clim_ser[59], clim_ser[61]))
github TUW-GEO / pytesmo / pytesmo / io / sat / ascat.py View on Github external
d = d * self.scale_factor[into_df]
            dict_df[into_df] = d

        df = pd.DataFrame(dict_df, index=datetimes_correct)

        if self.include_advflags:
            adv_flags, topo, wetland = self.read_advisory_flags(gpi)

            if topo >= self.topo_threshold:
                warnings.warn(
                    "Warning gpi shows topographic complexity of %d %%. Data might not be usable." % topo)
            if wetland >= self.wetland_threshold:
                warnings.warn(
                    "Warning gpi shows wetland fraction of %d %%. Data might not be usable." % wetland)

            df['doy'] = doy(df.index.month, df.index.day)
            df = df.join(adv_flags, on='doy', how='left')
            del df['doy']

            if 'mask_frozen_prob' in kwargs:
                mask_frozen = kwargs['mask_frozen_prob']
                df = df[df['frozen_prob'] <= mask_frozen]

            if 'mask_snow_prob' in kwargs:
                mask_snow = kwargs['mask_snow_prob']
                df = df[df['snow_prob'] <= mask_snow]

        lon, lat = self.grid.gpi2lonlat(gpi)

        return df, gpi, lon, lat, cell
github TUW-GEO / pytesmo / src / pytesmo / time_series / anomaly.py View on Github external
if climatology is not None:

        if type(Ser.index) == pd.DatetimeIndex:

            year, month, day = (np.asarray(Ser.index.year),
                                np.asarray(Ser.index.month),
                                np.asarray(Ser.index.day))

        else:
            year, month, day = julian2date(Ser.index.values)[0:3]

        if respect_leap_years:
            doys = doy(month, day, year)
        else:
            doys = doy(month, day)

        df = pd.DataFrame()
        df['absolute'] = Ser
        df['doy'] = doys

        clim = pd.DataFrame({'climatology': climatology})

        df = df.join(clim, on='doy', how='left')

        anomaly = df['absolute'] - df['climatology']
        anomaly.index = df.index

        if return_clim:
            anomaly = pd.DataFrame({'anomaly': anomaly})
            anomaly['climatology'] = df['climatology']
github TUW-GEO / pytesmo / src / pytesmo / time_series / anomaly.py View on Github external
Series containing the calculated anomalies
    '''

    if climatology is not None:

        if type(Ser.index) == pd.DatetimeIndex:

            year, month, day = (np.asarray(Ser.index.year),
                                np.asarray(Ser.index.month),
                                np.asarray(Ser.index.day))

        else:
            year, month, day = julian2date(Ser.index.values)[0:3]

        if respect_leap_years:
            doys = doy(month, day, year)
        else:
            doys = doy(month, day)

        df = pd.DataFrame()
        df['absolute'] = Ser
        df['doy'] = doys

        clim = pd.DataFrame({'climatology': climatology})

        df = df.join(clim, on='doy', how='left')

        anomaly = df['absolute'] - df['climatology']
        anomaly.index = df.index

        if return_clim:
            anomaly = pd.DataFrame({'anomaly': anomaly})