Utilities¶
Gap infilling, pith-offset conversion, LiPD interchange, plotting, and CLI helpers.
fill_internal¶
Fill interior gaps (interior NaN) in a ring-width dataset.
Only interior NaN -- those between a series' first and last real ring -- are filled; leading and trailing NaN are left untouched. A real 0 (a locally absent ring) is data and is never treated as a gap. Series with one or no real value are returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
pandas dataframe
|
ring widths (or indices), years as the index and series as columns. |
required |
fill |
(Mean, Spline, Linear, ARSTAN)
|
how to fill each interior gap:
The four simple options are a port of dplR's fill.internal.NA(); "Mean", "Linear" and "Spline" interpolate within each series only. |
"Mean"
|
**kwargs |
for fill="ARSTAN", forwarded to _fill_arstan (e.g. growth_nyrs, long_gap, flank). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
out |
pandas dataframe, same shape/index/columns as `data`, with interior
|
gaps filled. |
Notes
The simple methods know nothing about the other series -- they just bridge each hole -- so use them when you need an NaN-free series for a downstream step, not as if the filled values were measured. "ARSTAN" instead borrows the shared year-to-year signal from all series, which is the point of Cook's method.
po_to_wc¶
Convert pith offset to (partial) wood completeness (dplR's po.to.wc()).
The number of missing heartwood rings is the pith offset minus one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
po |
DataFrame
|
pith-offset table with a |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
one column, |
References
.. [1] https://rdrr.io/cran/dplR/man/po.to.wc.html
wc_to_po¶
Convert wood completeness to pith offset (dplR's wc.to.po()).
The pith offset is the number of missing heartwood rings plus the number of
unmeasured inner rings plus one, for every series whose pith presence is
known (complete/incomplete) or whose missing-heartwood count is
given; other series get a missing pith offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wc |
DataFrame
|
wood-completeness table indexed by series, with any of the optional
columns |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
a pith-offset table with |
References
.. [1] https://rdrr.io/cran/dplR/man/wc.to.po.html
to_lipd¶
Write dplPy chronologies to a LiPD .lpd file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chron |
DataFrame
|
Chronology output from |
required |
filename |
str
|
Output path. |
required |
rwl |
DataFrame
|
Raw ring widths the chronology was built from. Written as a further
measurement table, and -- if |
None
|
metadata |
SiteMetadata or dict
|
Site metadata for the |
None
|
dsname |
str
|
LiPD dataset name; defaults to the filename stem (a purely-numeric name is avoided -- pylipd cannot resolve one). |
None
|
column |
str
|
The primary chronology column (written with |
'std'
|
chronologies |
None | 'all' | list of str
|
Which chronology columns to write. None writes just |
None
|
stats |
DataFrame
|
Per-year running statistics (e.g. |
None
|
publication |
dict
|
Citation for the record: any of |
None
|
provenance |
str
|
Free-text description of how the chronology was built (detrending, AR, robust mean, ...). Stored on each chronology variable's description/notes and PaST long name. |
None
|
archive_type |
str
|
LiPD archiveType. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The path written. |
Notes
Requires the optional pylipd dependency: pip install "dplpy[lipd]".
from_lipd¶
Read a LiPD .lpd file into dplPy-native objects.
Returns a dict with:
'rwl': the raw ring widths as a year-indexed DataFrame (series as columns), ready fordpl.detrend/dpl.chron, or None.'chronology': the primary (headline) chronology as a year-indexed DataFrame (trsgiplus anycount/RBAR/EPS), or None.'chronologies': a dict of all chronologies found (keyed by a label such as'standard'/'residual'/'arstan'), from measurement tables and/or model summaries.'metadata': adpl.metadata()-shape dict from thegeoblock.'dsname': the LiPD dataset name.
Requires the optional pylipd dependency: pip install "dplpy[lipd]".
lipd_metadata¶
Read just the site metadata from a LiPD .lpd file, as a
dpl.metadata()-shape dict. Requires the optional pylipd dependency.
plot¶
Plot a ring-width dataset as a line, spaghetti, or segment plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inp |
str | DataFrame
|
a file path to a .csv or .rwl file, or a dataframe from dpl.readers(). |
required |
type |
str
|
'seg' (coverage segments, one bar per series), 'spag' (spaghetti: each series offset vertically, black by default -- pass color= a colormap name to shade by first year), or 'line' (all series overplotted against year). |
'seg'
|
ax |
matplotlib Axes
|
draw into this Axes instead of creating a new figure. When omitted, a figure is created and auto-sized to the data. |
None
|
show |
bool
|
call |
True
|
**kwargs |
passed through to the underlying plotter (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
(fig, ax) : tuple of matplotlib Figure and Axes
|
the figure and axes drawn on, so callers can save or restyle them. (Earlier versions returned None; the figure is now returned for reuse.) |
Examples:
>>> dpl.plot(data)
>>> dpl.plot(data, type="spag")
>>> fig, ax = dpl.plot(data, type="seg", show=False); fig.savefig("seg.png")
References
.. [1] https:/opendendro.org/dplpy-man/#plot