pytesmo.timedate package

Submodules

pytesmo.timedate.dekad module

This module provides functions for date manipulation on a dekadal basis.

A dekad is defined as days 1-10, 11-20 and 21-last day of a month.

Or in numbered dekads:

1: day 1-10 2: day 11-20 3: day 21-last

pytesmo.timedate.dekad.check_dekad(date)[source]

Checks the dekad of a date and returns the dekad date.

Parameters

date (datetime) – Date to check.

Returns

new_date – Date of the dekad.

Return type

datetime

pytesmo.timedate.dekad.check_dekad_enddate(dt)[source]

Check if a date is a dekad enddate

pytesmo.timedate.dekad.check_dekad_startdate(dt)[source]

Check if a date is a dekad startdate

pytesmo.timedate.dekad.day2dekad(day)[source]

Returns the dekad of a day.

Parameters

day (int) – Day of the date.

Returns

dekad – Number of the dekad in a month.

Return type

int

pytesmo.timedate.dekad.dekad2day(year, month, dekad)[source]

Gets the day of a dekad.

Parameters
  • year (int) – Year of the date.

  • month (int) – Month of the date.

  • dekad (int) – Dekad of the date.

Returns

day – Day value for the dekad.

Return type

int

pytesmo.timedate.dekad.dekad_index(begin, end=None)[source]

Creates a pandas datetime index on a decadal basis.

Parameters
  • begin (datetime) – Datetime index start date.

  • end (datetime, optional) – Datetime index end date, set to current date if None.

Returns

dtindex – Dekadal datetime index.

Return type

pandas.DatetimeIndex

pytesmo.timedate.dekad.dekad_startdate_from_date(dt_in)[source]

dekadal startdate that a date falls in

Parameters

run_dt (datetime.datetime) –

Returns

startdate – startdate of dekad

Return type

datetime.datetime

pytesmo.timedate.dekad.get_dekad_period(dates)[source]

Checks number of the dekad in the current year for dates given as list.

Parameters

dates (list of datetime) – Dates to check.

Returns

period – List of dekad periods.

Return type

list of int

pytesmo.timedate.dekad.group_into_dekads(dates, use_dekad_startdate=False)[source]

Group a list of dates into dekads.

Parameters
  • dates (list of datetime.datetime) –

  • use_dekad_startdates (boolean, optional) – If set the dekad reference dates will be the startdates of the dekad

Returns

groups – keys: dekad reference dates values: list of dates belonging to dekad

Return type

dict

pytesmo.timedate.dekad.runningdekad2date(year, rdekad)[source]

Gets the date of the running dekad of a spacifc year.

Parameters
  • year (int) – Year of the date.

  • rdekad (int) – Running dekad of the date.

Returns

Date value for the running dekad.

Return type

datetime.datetime

pytesmo.timedate.julian module

Created on Tue Apr 02 16:50:34 2013

@author: tm

computes julian date, given month (1..12). day(1..31) and year, its inverse (calendar date from julian), and the day of the year (doy), assuming it is a leap year.

julday and caldat are adapted from “Numerical Recipes in C’, 2nd edition, pp. 11

restrictions - no error handling implemented - works only for years past 1582 - time not yet supported

pytesmo.timedate.julian.caldat(julian)[source]

Calendar date (month, day, year) from julian date, inverse of ‘julday()’ Return value: month, day, and year in the Gregorian Works only for years past 1582!

Parameters

julian (numpy.ndarray or double) – Julian day.

Returns

  • month (numpy.ndarray or int32) – Month.

  • day (numpy.ndarray or int32) – Day.

  • year (numpy.ndarray or int32) – Year.

pytesmo.timedate.julian.doy(month, day, year=None)[source]

Calculation of day of year. If year is provided it will be tested for leap years.

Parameters
pytesmo.timedate.julian.is_leap_year(year)[source]

Check if year is a leap year.

Parameters

year (numpy.ndarray or int32) –

Returns

leap_year – True if year is a leap year.

Return type

numpy.ndarray or boolean

pytesmo.timedate.julian.julday(month, day, year, hour=0, minute=0, second=0)[source]

Julian date from month, day, and year (can be scalars or arrays)

Parameters
Returns

jul – Julian day.

Return type

numpy.ndarray or double

pytesmo.timedate.julian.julian2date(julian)[source]

Calendar date from julian date. Works only for years past 1582!

Parameters

julian (numpy.ndarray or double) – Julian day.

Returns

  • year (numpy.ndarray or int32) – Year.

  • month (numpy.ndarray or int32) – Month.

  • day (numpy.ndarray or int32) – Day.

  • hour (numpy.ndarray or int32) – Hour.

  • minute (numpy.ndarray or int32) – Minute.

  • second (numpy.ndarray or int32) – Second.

pytesmo.timedate.julian.julian2datetime(julian, tz=None)[source]

converts julian date to python datetime default is not time zone aware

Parameters

julian (float) – julian date

pytesmo.timedate.julian.julian2datetimeindex(j, tz=<UTC>)[source]

Converting Julian days to datetimeindex.

Parameters
  • j (numpy.ndarray or int32) – Julian days.

  • tz (instance of pytz, optional) – Time zone. Default: UTC

Returns

datetime – Datetime index.

Return type

pandas.DatetimeIndex

pytesmo.timedate.julian.julian2doy(j, consider_nonleap_years=True)[source]

Calendar date from julian date. Works only for years past 1582!

Parameters
  • j (numpy.ndarray or double) – Julian days.

  • consider_nonleap_years (boolean, optional) – Flag if all dates are interpreted as leap years (False) or not (True).

Returns

doy – Day of year.

Return type

numpy.ndarray or int32

pytesmo.timedate.julian.julian2num(j)[source]

Convert a matplotlib date to a Julian days.

Parameters

j (numpy.ndarray : int32) – Julian days.

Returns

num – Number of days since 0001-01-01 00:00:00 UTC plus one.

Return type

numpy.ndarray : int32

pytesmo.timedate.julian.num2julian(n)[source]

Convert a Julian days to a matplotlib date.

Parameters

n (numpy.ndarray : int32) – Number of days since 0001-01-01 00:00:00 UTC plus one.

Returns

j – Julian days.

Return type

numpy.ndarray : int32

Module contents