esm_calendar package
Top-level package for ESM Calendar.
Submodules
esm_calendar.esm_calendar module
Module Docstring.,..?
- class esm_calendar.esm_calendar.Calendar(calendar_type=1)[source]
Bases:
object
Class to contain various types of calendars.
- Parameters
calendar_type (int) –
The type of calendar to use.
Supported calendar types: 0
no leap years
- 1
proleptic greogrian calendar (default)
n
equal months of
n
days
- timeunits
A list of accepted time units.
- Type
list of str
- monthnames
A list of valid month names, using 3 letter English abbreviation.
- Type
list of str
- day_in_month(year, month)[source]
Returns the total number of days in a given month for a given year (considering leapyears)
- day_in_month(year, month)[source]
Finds the number of days in a given month
- Parameters
year (int) – The year to check
month (int or str) – The month number or short name.
- Returns
The number of days in this month, considering leapyears if needed.
- Return type
int
- Raises
TypeError – Raised when you give an incorrect type for month
- day_in_year(year)[source]
Finds total number of days in a year, considering leapyears if the calendar type allows for them.
- Parameters
year (int) – The year to check
- Returns
The total number of days for this specific calendar type
- Return type
int
- isleapyear(year)[source]
Checks if a year is a leapyear
- Parameters
year (int) – The year to check
- Returns
True if the given year is a leapyear
- Return type
bool
- monthnames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
- timeunits = ['years', 'months', 'days', 'hours', 'minutes', 'seconds']
- class esm_calendar.esm_calendar.Date(indate, calendar=esm_calendar(calendar_type=1))[source]
Bases:
object
A class to contain dates, also compatiable with paleo (negative dates)
- Parameters
indate (str) –
The date to use.
See pyesm.core.time_control.esm_calendar.Dateformat for available formatters.
calendar (Calendar`, optional) – The type of calendar to use. Defaults to a greogrian proleptic calendar if nothing is specified.
- year
The year
- Type
int
- month
The month
- Type
int
- day
The day
- Type
int
- hour
The hour
- Type
int
- minute
The minute
- Type
int
- second
The second
- Type
int
- _calendar
The type of calendar to use
- Type
Calendar`
- add(to_add)[source]
Adds another date to this one.
- Parameters
to_add (Date`) – The other date to add to this one.
- Returns
new_date – A new date object with the added dates
- Return type
Date`
- day_of_year()[source]
Gets the day of the year, counting from Jan. 1
- Returns
The day of the current year.
- Return type
int
- format(form='SELF', givenph=None, givenpm=None, givenps=None)[source]
Beautifully returns a
Date
object as a string.- Parameters
form (str or int) – Logic taken from from MPI-Met
givenph (bool-ish) – Print hours
givenpm (bool-ish) – Print minutes
givenps (bool-ish) – Print seconds
Note
- How to use the ``form`` argument
The following forms are accepted: + SELF: uses the format which was given when constructing the date + 0: A Date formatted as YYYY
In [5]: test.format(form=1) Out[5]: ‘1850-01-01_00:00:00’
In [6]: test.format(form=2) Out[6]: ‘1850-01-01T00:00:00’
In [7]: test.format(form=3) Out[7]: ‘1850-01-01 00:00:00’
In [8]: test.format(form=4) Out[8]: ‘1850 01 01 00 00 00’
In [9]: test.format(form=5) Out[9]: ‘01 Jan 1850 00:00:00’
In [10]: test.format(form=6) Out[10]: ‘18500101_00:00:00’
In [11]: test.format(form=7) Out[11]: ‘1850-01-01_000000’
In [12]: test.format(form=8) Out[12]: ‘18500101000000’
In [13]: test.format(form=9) Out[13]: ‘18500101_000000’
In [14]: test.format(form=10) Out[14]: ‘01/01/1850 00:00:00’
- classmethod from_list(_list)[source]
Creates a new Date from a list
- Parameters
_list (list of ints) – A list of [year, month, day, hour, minute, second]
- Returns
date – A new date of year month day, hour minute, second
- Return type
Date`
- classmethod fromlist(_list)
Creates a new Date from a list
- Parameters
_list (list of ints) – A list of [year, month, day, hour, minute, second]
- Returns
date – A new date of year month day, hour minute, second
- Return type
Date`
- makesense(ndate)[source]
Puts overflowed time back into the correct unit.
When manipulating the date, it might be that you have “70 seconds”, or something similar. Here, we put the overflowed time into the appropriate unit.
- property sday
- property sdoy
- property shour
- property sminute
- property smonth
- property ssecond
- sub_tuple(to_sub)[source]
Adds another date to from one.
- Parameters
to_sub (Date`) – The other date to sub from this one.
- Returns
new_date – A new date object with the subtracted dates
- Return type
Date`
- property syear
- class esm_calendar.esm_calendar.Dateformat(form=1, printhours=True, printminutes=True, printseconds=True)[source]
Bases:
object
- datesep = ['', '-', '-', '-', ' ', ' ', '', '-', '', '', '/']
- dtsep = ['_', '_', 'T', ' ', ' ', ' ', '_', '_', '', '_', ' ']
- timesep = ['', ':', ':', ':', ' ', ':', ':', '', '', '', ':']
- esm_calendar.esm_calendar.find_remaining_hours(seconds)
Finds the remaining full minutes of a given number of seconds
- Parameters
seconds (int) – The number of seconds to allocate
- Returns
The leftover seconds once new minutes have been filled.
- Return type
int