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

Res class update #444

Merged
merged 5 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions pyleoclim/core/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def describe(self):
'''

stats = st.describe(self.resolution)._asdict()

median = np.median(self.resolution)
stats['median'] = median

return stats

Expand Down
16 changes: 13 additions & 3 deletions pyleoclim/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4017,12 +4017,22 @@ def resolution(self):
resolution.dashboard()

"""

res,_,_ = tsbase.resolution(self.time)

copy = self.copy()

x = copy.time
v = copy.value

if any(np.isnan(v)):
v,x = tsbase.dropna(ts=x,ys=v)
copy.time = x
copy.value = v

res,_,_ = tsbase.resolution(x=x)

resolution = Resolution(
resolution = res,
timeseries = self
timeseries = copy
)

return resolution
Expand Down
10 changes: 10 additions & 0 deletions pyleoclim/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def unevenly_spaced_series():
series = pyleo.Series(time=t, value =v, verbose=False)
return series

@pytest.fixture
def unevenly_spaced_series_nans():
"""Pyleoclim series with unevenly spaced time axis"""
length = 10
t = np.linspace(1,length,length) ** 2
v = np.ones(length)
v[2:4] = np.nan
series = pyleo.Series(time=t, value =v, dropna=False, verbose=False)
return series

@pytest.fixture
def evenly_spaced_series():
"""Pyleoclim series with evenly spaced time axis"""
Expand Down
29 changes: 17 additions & 12 deletions pyleoclim/tests/test_core_Resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,40 @@
5. for more details, see https://docs.pytest.org/en/stable/usage.html
'''

import pytest
import pyleoclim as pyleo

class TestUIResolutionDescribe:
"""Tests for Resolution.describe()"""

def test_describe_t0(self,unevenly_spaced_series):
resolution = unevenly_spaced_series.resolution()
@pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans'])
def test_describe_t0(self,series,request):
series = request.getfixturevalue(series)
resolution = series.resolution()
resolution.describe()

class TestUIResolutionPlot:
"""Tests for Resolution.plot()"""

def test_plot_t0(self,unevenly_spaced_series):
resolution = unevenly_spaced_series.resolution()
@pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans'])
def test_plot_t0(self,series,request):
series = request.getfixturevalue(series)
resolution = series.resolution()
fig, ax = resolution.plot()
pyleo.closefig(fig)

class TestUIHistPlot:
"""Tests for Resolution.plot()"""

def test_histplot_t0(self,unevenly_spaced_series):
resolution = unevenly_spaced_series.resolution()
@pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans'])
def test_histplot_t0(self,series,request):
series = request.getfixturevalue(series)
resolution = series.resolution()
fig, ax = resolution.histplot()
pyleo.closefig(fig)

class TestUIDashboard:
"""Tests for Resolution.dashboard()"""

def test_dashboard_t0(self,unevenly_spaced_series):
resolution = unevenly_spaced_series.resolution()
@pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans'])
def test_dashboard_t0(self,series,request):
series = request.getfixturevalue(series)
resolution = series.resolution()
fig, ax = resolution.dashboard()
pyleo.closefig(fig)