Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple resolution #527

Merged
merged 29 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4b407ad
create multipleresolution.py
alexkjames Mar 5, 2024
ee76ee2
create multipleresolution class
alexkjames Mar 5, 2024
f4197da
add resolution and multipleresolution to init
alexkjames Mar 5, 2024
55a34bb
improve resolution docstring
alexkjames Mar 5, 2024
6d6f6ad
improve series.resolution clarity
alexkjames Mar 5, 2024
a9f9a48
minor docstring fix
alexkjames Mar 5, 2024
98ed19e
create resolution function in multipleseries
alexkjames Mar 5, 2024
006fd16
docstring change
alexkjames Mar 5, 2024
3264949
include time unit in multipleresolution
alexkjames Mar 5, 2024
3d9feb3
multipleseries.resolution improvement
alexkjames Mar 5, 2024
64756cf
multipleseries.resolution tests
alexkjames Mar 5, 2024
78060b9
bug fixes
alexkjames Mar 6, 2024
f366d37
multipleresolution plot and describe functions
alexkjames Mar 6, 2024
07a34ba
docstring fixes
alexkjames Mar 6, 2024
26920ab
bugfix
alexkjames Mar 6, 2024
f7cedea
include default behaviour and tests + new conftest
alexkjames Mar 6, 2024
5145370
rename plot to summary plot
alexkjames Mar 6, 2024
201ee47
deprecation warnings for statistic arg
alexkjames Mar 6, 2024
cdf6322
msr tests
alexkjames Mar 6, 2024
e72f38e
test fixes
alexkjames Mar 6, 2024
4c4d908
improve unit tests
alexkjames Mar 6, 2024
f6de3b6
unit test fix
alexkjames Mar 6, 2024
fa93376
bugfix
alexkjames Mar 6, 2024
3392736
more test fixes
alexkjames Mar 6, 2024
c72d853
last unit test fix (maybe)
alexkjames Mar 6, 2024
b3c8379
increase seaborn version requirement
alexkjames Mar 7, 2024
ceb7fc5
various fixes
alexkjames Mar 7, 2024
e24b1a0
trying a different seaborn version
alexkjames Mar 7, 2024
71bf9f0
remove log_scale option
alexkjames Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyleoclim/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
from .ssares import SsaRes
from .lipd import Lipd
from .lipdseries import LipdSeries
from .resolutions import Resolution, MultipleResolution
137 changes: 99 additions & 38 deletions pyleoclim/core/multipleseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..core.scalograms import MultipleScalogram
from ..core.psds import MultiplePSD
from ..core.multivardecomp import MultivariateDecomp
from ..core.resolutions import MultipleResolution

import warnings
import numpy as np
Expand Down Expand Up @@ -2323,43 +2324,6 @@ def sel(self, value=None, time=None, tolerance=0):

return ms_new

def resolution(self, statistic='median'):
'''
Extracts representative statistic for the resolution of each series in the object.

Parameters
----------
statistic : str, optional
The statistic applied to the res9lution array of each series.
Possible values: 'mean' or 'median'. The default is 'median'.


Returns
-------
res: NumPy array
array containing the statistic of interest for all series.

Examples
--------
.. jupyter-execute::

co2ts = pyleo.utils.load_dataset('AACO2')
edc = pyleo.utils.load_dataset('EDC-dD')
ms = edc & co2ts # create MS object
ms.convert_time_unit('kyr BP').resolution()

Note that the output is only meaningful if all constituent series have the same units.
'''

if statistic=='median':
res = [np.median(ts.resolution().resolution) for ts in self.series_list]
elif statistic=='mean':
res = [np.mean(ts.resolution().resolution) for ts in self.series_list]
else:
raise ValueError('Unknown statistic',stacklevel=2)

return np.array(res)

def to_json(self, path=None):
'''
Export the pyleoclim.MultipleSeries object to a json file
Expand Down Expand Up @@ -2654,4 +2618,101 @@ def time_coverage_plot(self, figsize=[10, 3],
plotting.savefig(fig, settings=savefig_settings)
return fig, ax
else:
return ax
return ax

def resolution(self,time_unit=None,verbose=True,statistic='median'):
"""Generate a MultipleResolution object

Increments are assigned to the preceding time value.
E.g. for time_axis = [0,1,3], resolution.resolution = [1,2] resolution.time = [0,1].
Note that the MultipleResolution class requires a shared time unit. If the time_unit parameter is not passed, a time unit will be automatically determined.

Returns
-------

multipleresolution : pyleoclim.MultipleResolution
MultipleResolution object

time_unit : str
Time unit to convert objects to. See pyleo.Series.convert_time_unit for options.

verbose : bool
Whether or not to print messages warning the user about automated decisions.

statistic : str; {'median','mean',None}
If a recognized statistic is passed, this function will simply output that statistic applied to the resolution of each series in the MulitipleSeries object. Options are 'mean' or 'median'.
If statistic is None, then the function will return a new MultipleResolution class with plotting capabilities.

See Also
--------

pyleoclim.core.resolutions.MultipleResolution

pyleoclim.core.series.Series.convert_time_unit

Examples
--------

To create a resolution object, apply the .resolution() method to a Series object with `statistic=None`.

.. jupyter-execute::

import pyleoclim as pyleo

co2ts = pyleo.utils.load_dataset('AACO2')
edc = pyleo.utils.load_dataset('EDC-dD')
ms = edc & co2ts # create MS object
ms_resolution = ms.resolution(statistic=None)

Several methods are then available:

Summary statistics can be obtained via .describe()

.. jupyter-execute::

ms_resolution.describe()

A simple plot can be created using .summary_plot()

.. jupyter-execute::

ms_resolution.summary_plot()
"""

if statistic=='median':
warnings.warn('The statistic parameter will be deprecated in a future release. Statistic = None will become the default behavior.',DeprecationWarning)
res = [np.median(ts.resolution().resolution) for ts in self.series_list]
elif statistic=='mean':
warnings.warn('The statistic parameter will be deprecated in a future release. Statistic = None will become the default behavior.',DeprecationWarning)
res = [np.mean(ts.resolution().resolution) for ts in self.series_list]
elif statistic is None:
resolution_list = []

if time_unit:
series_list = self.series_list
for series in series_list:
resolution = series.convert_time_unit(time_unit).resolution()
resolution_list.append(resolution)
else:
if self.time_unit:
series_list = self.series_list
for series in series_list:
resolution = series.resolution()
resolution_list.append(resolution)
else:
if verbose:
print('Time unit not found, attempting conversion.')
new_ms = self.convert_time_unit()
time_unit = new_ms.time_unit
series_list = new_ms.series_list
if verbose:
print(f'Converted to {time_unit}')
for series in series_list:
resolution = series.resolution()
resolution_list.append(resolution)

res = MultipleResolution(resolution_list=resolution_list,time_unit=time_unit)
else:
raise ValueError('Unrecognized statistic, please use "mean", "median", or None')

return res
Loading
Loading