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 (case-insensitive):
"Mean", "Linear" and "Spline" port dplR's fill.internal.NA() and 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. The input's |
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.
References
.. [1] https://opendendro.github.io/dplPy/reference/utilities/#fill_internal
edit_rwl¶
Insert, delete, or change one ring in a single series.
Returns a new object; the input is never modified in place (unlike the
old Fortran programs, where the edit mutated the record). Assign the result
to keep it. The fix that pairs with the crossdating checks: xdate,
series_corr, and check find a misdated ring (a NEGATIVE lag there means
a MISSING ring, so action="insert"), and edit_rwl corrects it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame or Series
|
a ring-width collection (then |
required |
series
|
str or None
|
the series (column) to edit; required when |
None
|
year
|
int
|
the calendar year to act on (a whole number; NaN or 2003.7 is an error).
For |
None
|
action
|
(insert, delete, change)
|
|
"insert"
|
value
|
float or None
|
the ring width, a finite non-negative number. Required for |
None
|
fix_last
|
bool
|
insert/delete only. |
True
|
fix_length
|
bool or None
|
insert/delete on a Series only. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame or Series
|
a copy with the one edit applied, same type as |
Examples:
>>> import dplpy as dpl
>>> rwl = dpl.readers("co021.rwl")
>>> fixed = dpl.edit_rwl(rwl, series="641114", year=1900, action="insert")
>>> fixed = dpl.edit_rwl(rwl, series="641114", year=1905, action="delete")
>>> fixed = dpl.edit_rwl(rwl, series="641114", year=1912, action="change", value=0.44)
References
.. [1] https://rdrr.io/cran/dplR/man/insert.ring.html .. [2] https://opendendro.github.io/dplPy/reference/utilities/#edit_rwl
po_to_wc¶
Convert pith offset to (partial) wood completeness (dplR's po.to.wc()).
The number of missing heartwood rings equals the pith offset (dplPy's pith offset is itself the count of rings between pith and first measured ring; 0 = pith present).
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 (0 = pith present), 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
yrs_to_pith¶
Estimate years (rings) to pith from an estimated distance to pith.
Ports modendro's yrs_to_pith() (C. Maher). The number of unmeasured
rings between the pith and the innermost measured ring is estimated as the
distance to pith divided by a mean innermost ring width, rounded to a whole
number of rings. The distance to pith is whatever you measured (e.g. in
CooRecorder, as returned by dpl.read_pos().attributes); only the table
format matters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rwl
|
DataFrame
|
ring widths, years as the index and series IDs as columns. |
required |
d2pith
|
DataFrame
|
one row per series, with a |
required |
method
|
(dist, rings)
|
|
"dist"
|
n_rings
|
int
|
number of innermost rings to average ( |
10
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
columns |
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.github.io/dplPy/reference/utilities/#plot
help¶
Print help for dplPy in the console.
With no argument, print an overview of every public function (grouped by
task, each with the first line of its docstring). With a function name --
dpl.help("readers") -- or the function itself -- dpl.help(dpl.readers)
-- print that function's live signature and full docstring. The listing is
generated from the installed package, so it always matches the real API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str or callable
|
A public dplPy function name ( |
None
|
Examples:
readme¶
Open the online dplPy manual (https://opendendro.github.io/dplPy/) in a web browser. Prints the URL as well, for machines without a display.