Skip to main content

No project description provided

Project description

CircleCI codecov DOI

TimeAxis

Manages Time Axis and different operations related to time. Main focus is on Earth Science Data. The main goal of this package is to provide a unified mechanism to convert/transform date from time axis to another. For example, if your original data set is on a daily basis, and you want to convert it to weekly average, TimeAxis package would be handy. This package follows the same concept as in ESMF and SCRIPS. Although these two packages are for spatial coordinate interpolation, TimeAxis, obviously, deals with the time dimension of the data. It calculates a weight matrix stored as sparse matrix. Once you have the weights, any data field could be converted from the original time axis to the provided destination time axis.

How To Install

using pip

as usual, you could use pip installation as follows:

pip install timeaxis

Examples:

Daily data averaged to weekly

In this example, first we create a daily time-axis of length 14 days, i.e. we just have 14 data points along the time axis:

from_axis = DailyTimeAxisBuilder(
    start_date=date(2019, 1, 1),
    n_interval=14
).build()

Now we create a weekly time-axis of length 3, i.e. the time axis would have three elements with span of 3 weeks:

to_axis = WeeklyTimeAxisBuilder(
    start_date=date(2019, 1, 1),
    n_interval=3
).build()

now we create a time axis converter object, as follows:

tc = TimeAxisConverter(
    from_time_axis=from_axis, 
    to_time_axis=to_axis
)

Now we can use tc to convert data from the from_axis to to_axis, as follows:

to_data = tc.average(from_data)

the resulting to_data is the weekly average of the from_data. By default, we are assuming that the first dimension is the time dimension. If the time dimension is not the first dimension, you could define it as the following:

to_data = tc.average(from_data, time_dimension=n)

where n is the time dimension.

Rolling/moving weekly avarage

You could easily calculate a rolling or moving average of your data. Here is an example:

from_axis = DailyTimeAxisBuilder(
    start_date=date(2019, 1, 1),
    n_interval=14
).build()

to_axis = RollingWindowTimeAxisBuilder(
    start_date=date(2019, 1, 1),
    end_date=date(2019, 1, 15),
    window_size=7
).build()

tc = TimeAxisConverter(from_time_axis=from_axis, to_time_axis=to_axis)

to_data = tc.average(from_data)

as you can see, the only difference is the construction og the to_axis. In this example, we are building a rolling time axis that starts on Jan. 1st, 2019 and ends on Jan. 15th, 2019 with a window size of 7. Since the base time delta, if not provided, is one day, our window is one week (7 * 1day). However, this is a rolling time axis, meaning that the next element on time axis is shifted only one day. Yes, the intervals in the time-axis overlap each other.

Daily Averaged to Monthly

# Daily time axis spanning ten years.
from_axis = DailyTimeAxisBuilder(
    start_date=date(2010, 1, 1),
    end_date=date(2020, 1, 1)
).build()

# Monthly Time Axis spanning 10 years.
to_axis = MonthlyTimeAxisBuilder(
    start_year=2010,
    end_year=2019,
).build()

tc = TimeAxisConverter(from_time_axis=from_axis, to_time_axis=to_axis)
monthly_avg = tc.average(daily_data)

if you do not provide any month, the start month is assumed to be the January and the end month is assumed to be the December. If you want to control that you could pass the start_month and/or end_month to change this behavior:

to_axis = MonthlyTimeAxisBuilder(
    start_year=2010,
    start_monnth=4,
    end_year=2019,
    end_month=10
).build()

Authors:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TimeAxis-19.11.7.59750.tar.gz (16.1 kB view hashes)

Uploaded Source

Built Distribution

TimeAxis-19.11.7.59750-py3-none-any.whl (24.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page