Skip to content

Commit

Permalink
Fix up docs
Browse files Browse the repository at this point in the history
  • Loading branch information
znicholls committed Jan 4, 2025
1 parent b5242b7 commit 6547ed7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
22 changes: 10 additions & 12 deletions docs/further-background/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
import pint
from IPython.lib.pretty import pretty

from continuous_timeseries.time_axis import TimeAxis
from continuous_timeseries.timeseries_discrete import TimeseriesDiscrete
from continuous_timeseries.values_at_bounds import ValuesAtBounds
import continuous_timeseries as ct

# %% [markdown]
# ## Set up pint
Expand All @@ -54,26 +52,26 @@
# ## Set up some example objects

# %%
basic_ts = TimeseriesDiscrete(
basic_ts = ct.TimeseriesDiscrete(
name="basic",
time_axis=TimeAxis(Q([1750.0, 1850.0, 1950.0], "yr")),
values_at_bounds=ValuesAtBounds(Q([1.0, 2.0, 3.0], "m")),
time_axis=ct.TimeAxis(Q([1750.0, 1850.0, 1950.0], "yr")),
values_at_bounds=ct.ValuesAtBounds(Q([1.0, 2.0, 3.0], "m")),
)
basic_ts

# %%
long_ts = TimeseriesDiscrete(
long_ts = ct.TimeseriesDiscrete(
name="basic",
time_axis=TimeAxis(Q(np.arange(1850.0, 2300.0, 1), "yr")),
values_at_bounds=ValuesAtBounds(Q(np.arange(450.0), "m")),
time_axis=ct.TimeAxis(Q(np.arange(1850.0, 2300.0, 1), "yr")),
values_at_bounds=ct.ValuesAtBounds(Q(np.arange(450.0), "m")),
)
long_ts

# %%
really_long_ts = TimeseriesDiscrete(
really_long_ts = ct.TimeseriesDiscrete(
name="basic",
time_axis=TimeAxis(Q(np.arange(1850.0, 2300.0, 1 / 12), "yr")),
values_at_bounds=ValuesAtBounds(Q(np.arange(450.0 * 12), "m")),
time_axis=ct.TimeAxis(Q(np.arange(1850.0, 2300.0, 1 / 12), "yr")),
values_at_bounds=ct.ValuesAtBounds(Q(np.arange(450.0 * 12), "m")),
)
really_long_ts

Expand Down
8 changes: 4 additions & 4 deletions docs/further-background/why-this-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@
for label, updated_time_axis, updated_interpolation in (
("starting_point", None, None),
(
"same time - piecewise constant previous",
"same time - piecewise constant next left-closed",
ts_varying_step_size.time_axis,
ct.InterpolationOption.PiecewiseConstantPreviousLeftClosed,
ct.InterpolationOption.PiecewiseConstantNextLeftClosed,
),
(
"decadal steps - piecewise constant previous",
"decadal steps - piecewise constant next left-closed",
decadal_steps,
ct.InterpolationOption.PiecewiseConstantPreviousLeftClosed,
ct.InterpolationOption.PiecewiseConstantNextLeftClosed,
),
):
if updated_time_axis is not None:
Expand Down
14 changes: 6 additions & 8 deletions docs/tutorials/continuous_timeseries_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@
import pint
import scipy.interpolate

import continuous_timeseries as ct
from continuous_timeseries.exceptions import ExtrapolationNotAllowedError
from continuous_timeseries.timeseries_continuous import (
ContinuousFunctionScipyPPoly,
TimeseriesContinuous,
)
from continuous_timeseries.timeseries_continuous import ContinuousFunctionScipyPPoly

# %% [markdown]
# ## Handy pint aliases
Expand Down Expand Up @@ -110,7 +108,7 @@
# We then create our `TimeseriesContinuous` instance.

# %%
ts = TimeseriesContinuous(
ts = ct.TimeseriesContinuous(
name="piecewise_constant",
time_units=time_axis.u,
values_units=values.u,
Expand Down Expand Up @@ -143,7 +141,7 @@
)
continuous_linear = ContinuousFunctionScipyPPoly(piecewise_polynomial_linear)

ts_linear = TimeseriesContinuous(
ts_linear = ct.TimeseriesContinuous(
name="piecewise_linear",
time_units=time_axis.u,
values_units=values.u,
Expand Down Expand Up @@ -178,7 +176,7 @@
)
continuous_quadratic = ContinuousFunctionScipyPPoly(piecewise_polynomial_quadratic)

ts_quadratic = TimeseriesContinuous(
ts_quadratic = ct.TimeseriesContinuous(
name="piecewise_quadratic",
time_units=time_axis.u,
values_units=values.u,
Expand Down Expand Up @@ -215,7 +213,7 @@
)
continuous_quadratic = ContinuousFunctionScipyPPoly(piecewise_polynomial_quadratic)

ts_cubic = TimeseriesContinuous(
ts_cubic = ct.TimeseriesContinuous(
name="piecewise_cubic",
time_units=time_axis.u,
values_units=values.u,
Expand Down
22 changes: 10 additions & 12 deletions docs/tutorials/discrete_timeseries_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import matplotlib.units
import pint

from continuous_timeseries.time_axis import TimeAxis
from continuous_timeseries.timeseries_discrete import TimeseriesDiscrete
from continuous_timeseries.values_at_bounds import ValuesAtBounds
import continuous_timeseries as ct

# %% [markdown]
# ## Handy pint aliases
Expand All @@ -55,7 +53,7 @@
# the third from `bounds[2]`, to `bounds[3]` etc.

# %%
time_axis = TimeAxis(
time_axis = ct.TimeAxis(
Q([1900.0, 1950.0, 1975.0, 2000.0, 2010.0, 2020.0, 2030.0, 2050.0], "yr")
)
time_axis
Expand All @@ -67,7 +65,7 @@
# These must represent the values at each bound (i.e. value) in `time_axis`.

# %%
values_at_bounds = ValuesAtBounds(
values_at_bounds = ct.ValuesAtBounds(
Q([2.3, 4.5, 6.4, 10.0, 11.0, 12.3, 10.2, 3.5], "Gt / yr")
)
values_at_bounds
Expand All @@ -79,7 +77,7 @@
# and initialise our instance.

# %%
ts = TimeseriesDiscrete(
ts = ct.TimeseriesDiscrete(
name="example",
time_axis=time_axis,
values_at_bounds=values_at_bounds,
Expand Down Expand Up @@ -134,15 +132,15 @@
# will automatically be plotted with the same units.

# %%
ts_compatible_unit = TimeseriesDiscrete(
ts_compatible_unit = ct.TimeseriesDiscrete(
name="example_compatible_unit",
time_axis=TimeAxis(
time_axis=ct.TimeAxis(
Q(
[(1932 + 6) * 12.0, 2000 * 12.0, (2010 + 5) * 12.0, (2025 + 3) * 12.0],
"month",
)
),
values_at_bounds=ValuesAtBounds(Q([140.0, 160.0, 120.0, -10.0], "Mt / month")),
values_at_bounds=ct.ValuesAtBounds(Q([140.0, 160.0, 120.0, -10.0], "Mt / month")),
)

ax = ts.plot()
Expand Down Expand Up @@ -177,15 +175,15 @@
# Instead, you will get an error.

# %%
ts_incompatible_unit = TimeseriesDiscrete(
ts_incompatible_unit = ct.TimeseriesDiscrete(
name="example_incompatible_unit",
time_axis=TimeAxis(
time_axis=ct.TimeAxis(
Q(
[(1932 + 6) * 12.0, 2000 * 12.0, (2010 + 5) * 12.0, (2025 + 3) * 12.0],
"month",
)
),
values_at_bounds=ValuesAtBounds(Q([10.0, 20.0, 30.0, 40.0], "Mt")),
values_at_bounds=ct.ValuesAtBounds(Q([10.0, 20.0, 30.0, 40.0], "Mt")),
)

ax = ts.plot()
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/timeseries_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
integral_preserving_demo_annual_time_axis
)
annual_average = ts_linear_annual_to_show.update_interpolation_integral_preserving(
interpolation=ct.InterpolationOption.PiecewiseConstantPreviousLeftClosed,
interpolation=ct.InterpolationOption.PiecewiseConstantNextLeftClosed,
name_res="annual_average",
)

Expand All @@ -404,7 +404,7 @@
decadal_average = ts_integral_preserving_demo_start.interpolate(
Q(np.hstack([[2025, 2040], np.arange(2060, 2100 + 1, 20)]), "yr"),
).update_interpolation_integral_preserving(
interpolation=ct.InterpolationOption.PiecewiseConstantPreviousLeftClosed,
interpolation=ct.InterpolationOption.PiecewiseConstantNextLeftClosed,
name_res="custom_average",
)

Expand Down Expand Up @@ -523,12 +523,12 @@
),
show_discrete=True,
discrete_plot_kwargs=dict(
alpha=0.3,
alpha=0.7,
zorder=3,
marker="x",
s=150,
color="tab:blue",
label="demo_continuous_and_discrete",
zorder=3,
),
)

Expand Down

0 comments on commit 6547ed7

Please sign in to comment.