Loading and processing data#
Functions for importing and processing proxy and age constraint data.
Import and pre-process proxy data and age constraints from .csv files formatted according to the Data table formatting guidelines. |
|
Helper function for merging |
|
Custom load command for pickle (.pkl) object (variables can be saved as .pkl files with |
|
Custom load command for NetCDF file containing a trace ( |
|
Save variable as a pickle (.pkl) object. |
|
Save trace ( |
|
Helper function for combining multiple |
|
Remove a subset of chains from a |
|
Remove a subset of draws from a |
|
Calculate apparent sediment accumulation rate between successive samples (if |
|
Helper function for cleaning sample data before running an inversion. |
|
Helper function for converting depth in core to height in section. |
|
Helper function for combining multiple proxy measurements from the same stratigraphic horizon. |
- stratmc.data.accumulation_rate(full_trace, sample_df, ages_df, method='all', age_model='posterior', include_age_constraints=True, **kwargs)[source]#
Calculate apparent sediment accumulation rate between successive samples (if
method = 'successive') or every possible sample pairing (method = 'all').Note that if
method = 'all', rate is returned in mm/year, and duration is returned in years. Ifmethod = 'successive', rate is returned in m/Myr, and duration is returned in Myr. Input data are assumed to have units of meters and millions of years. Used as input tosadler_plot()andaccumulation_rate_stratigraphy()instratmc.plotting.- Parameters:
- full_trace: arviz.InferenceData
An
arviz.InferenceDataobject containing the full set of prior and posterior samples fromget_trace()instratmc.inference.- sample_df: pandas.DataFrame
pandas.DataFramecontaining all proxy data.- ages_df: pandas.DataFrame
pandas.DataFramecontaining age constraints from all sections.- method: str, optional
Whether to calculate accumulation rates between every possible sample pairing (‘all`), or between successive samples (‘successive`); defaults to ‘all`.
- age_model: str, optional
Whether to calculate accumulation rates using the the posterior or prior age model for each section; defaults to ‘posterior`.
- include_age_constraints: bool, optional
Whether to include radiometric age constraints in accumulation rate calculations; defaults to
True.- sections: list(str) or numpy.array(str), optional
List of sections to include. Defaults to all sections in
sample_df.
- Returns:
- rate_df: pandas.DataFrame
pandas.DataFramecontaining sediment accumulation rates and associated durations.
- stratmc.data.clean_data(sample_df, ages_df, proxies, sections)[source]#
Helper function for cleaning sample data before running an inversion. Sets
Exclude?toTruefor samples with no relevant proxy observations, removes sections where all samples have been excluded, and drops excluded age constraints.- Parameters:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining proxy data for all sections.- ages_df: pandas.DataFrame
pandas.DataFramecontaining age constraints for all sections.- proxies: str or list(str)
Tracers to include in the inference.
- sections: list(str) or numpy.array(str)
List of sections to include in the inference (as named in
sample_dfandages_df).
- Returns:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining cleaned proxy data for all sections.- ages_df: pandas.DataFrame
pandas.DataFramecontaining cleaned age constraint data for all sections.
- stratmc.data.combine_data(dataframes)[source]#
Helper function for merging
pandas.DataFrameobjects containing proxy observations or age constraints. Data are merged using thesectionandheightcolumns.- Parameters:
- dataframes: list(pandas.DataFrame)
List of
pandas.DataFrameobjects to merge.
- Returns:
- merged_data: pandas.DataFrame
pandas.DataFramecontaining merged data.
- stratmc.data.combine_duplicates(sample_df, proxies, proxy_sigma_default=0.1)[source]#
Helper function for combining multiple proxy measurements from the same stratigraphic horizon. For each horizon with multiple proxy values, replaces the proxy value with the mean, and replaces the standard deviation with the combined uncertainty (
proxy_stdvalues summed in quadrature) for all measurements. The standard deviation of the population of proxy values for each horizon is stored in theproxy_population_stdcolumn ofsample_df(inbuild_model(), the uncertainty of each proxy observation is modeled as theproxy_stdandproxy_population_stdvalues summed in quadrature).- Parameters:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining proxy data for all sections.- proxies: list(str)
List of proxies to include in the inference.
- proxy_sigma_default: float or dict{float}, optional
Measurement uncertainty (\(1\sigma\)) to use for proxy observations if not specified in
proxy_stdcolumn ofsample_df. To set a different value for each proxy, pass a dictionary with proxy names as keys. Defaults to 0.1.
- Returns:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining proxy data with duplicates combined.
- stratmc.data.combine_traces(trace_list)[source]#
Helper function for combining multiple
arviz.InferenceDataobjects (saved as NetCDF files) that contain prior and posterior samples for the same inference model (sampled withget_trace()instratmc.inference). Thearviz.InferenceDataobjects are concatenated along thechaindimension such that if two traces with 8 chains each are concatenated, the new combined trace will have 16 chains.- Parameters:
- trace_list: list(str)
List of paths to
arviz.InferenceDataobjects (saved as NetCDF files) to be merged.
- Returns:
- combined_trace: arviz.InferenceData
New
arviz.InferenceDataobject containing the prior and posterior draws for all traces intrace_list.
- stratmc.data.depth_to_height(sample_df, ages_df)[source]#
Helper function for converting depth in core to height in section.
- Parameters:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining proxy data for all sections.- ages_df: pandas.DataFrame
pandas.DataFramecontaining age constraints for all sections.
- Returns:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining proxy data for all sections, with depth in core converted to height in section.- ages_df: pandas.DataFrame
pandas.DataFramecontaining age constraints for all sections, with depth in core converted to height in section.
- stratmc.data.drop_chains(full_trace, chains)[source]#
Remove a subset of chains from a
arviz.InferenceDataobject.- Parameters:
- full_trace: arviz.InferenceData
An
arviz.InferenceDataobject containing the full set of prior and posterior samples fromget_trace()instratmc.inference.- chains: list or np.array of int
Indices of chains to remove from
full_trace.
- Returns:
- full_trace_clean: arviz.InferenceData
Copy of
full_tracewithout the chains specified inchains.
- stratmc.data.load_data(sample_file, ages_file, proxies=['d13c'], proxy_sigma_default=0.1, drop_excluded_samples=False, drop_excluded_ages=True)[source]#
Import and pre-process proxy data and age constraints from .csv files formatted according to the Data table formatting guidelines. To combine data from different .csv files, load each file separately and then combine the DataFrames with
combine_data().If
sample_file.csvincludes multiple proxy observations from the same stratigraphic horizon (for a given proxy), then all measurements markedExclude? = Falsewill be combined usingcombine_duplicates().- Parameters:
- sample_file: str
Path to .csv file containing proxy data for all sections (without ‘.csv` extension).
- ages_file: str
Path to .csv file containing age constraints for all sections (without ‘.csv` extension).
- proxies: str or list(str), optional
Tracer names (must match column headers in
sample_file.csv); defaults to ‘d13c`.- proxy_sigma_default: float or dict{float}, optional
Measurement uncertainty (\(1\sigma\)) to use for proxy observations if not specified in
proxy_stdcolumn ofsample_df. To set a different value for each proxy, pass a dictionary with proxy names as keys. Defaults to 0.1.- drop_excluded_samples: bool, optional
Whether to remove samples with
Exclude? = Truefrom thesample_df; defaults toFalse. If excluded samples are not dropped, their ages will be passively tracked within the inference model (but they will not be considered during the proxy signal reconstruction).- drop_excluded_ages: bool, optional
Whether to remove ages with
Exclude? = Truefrom theages_df; defaults toTrue.
- Returns:
- sample_df: pandas.DataFrame
pandas.DataFramecontaining proxy data for all sections.- ages_df: pandas.DataFrame
pandas.DataFramecontaining age constraints for all sections.
- stratmc.data.load_object(path)[source]#
Custom load command for pickle (.pkl) object (variables can be saved as .pkl files with
save_object()).- Parameters:
- path: str
Path to saved .pkl file (without the ‘.pkl` extension).
- Returns:
- var:
Variable saved in
path.
- stratmc.data.load_trace(path)[source]#
Custom load command for NetCDF file containing a trace (
arviz.InferenceDataobject saved withsave_trace()).- Parameters:
- path: str
Path to saved NetCDF file (without the ‘.nc` extension).
- Returns:
- trace: arviz.InferenceData
Trace saved as NetCDF file.
- stratmc.data.save_object(var, path)[source]#
Save variable as a pickle (.pkl) object.
- Parameters:
- var:
Variable to be saved.
- path: str
Location (including the file name, without ‘.pkl` extension) to save
var.
- stratmc.data.save_trace(trace, path)[source]#
Save trace (
arviz.InferenceDataobject) as a NetCDF file.- Parameters:
- trace: arviz.InferenceData
An
arviz.InferenceDataobject containing the full set of prior and posterior samples frombuild_model()instratmc.model(the output ofget_trace()instratmc.inference).- path: str
Location (including the file name, without ‘.nc` extension) to save
trace.
- stratmc.data.thin_trace(full_trace, drop_freq=2)[source]#
Remove a subset of draws from a
arviz.InferenceDataobject. Only applies to groups associated with the posterior (the prior draws will not be affected).- Parameters:
- full_trace: arviz.InferenceData
An
arviz.InferenceDataobject containing the full set of prior and posterior samples fromget_trace()instratmc.inference.- drop_freq: int
Frequency of draw removal. For example, 2 will remove every other draw, while 4 will remove every fourth draw.
- Returns:
- thinned_trace: arviz.InferenceData
Thinned version of
full_trace.