-
Notifications
You must be signed in to change notification settings - Fork 228
Wrap blockmean #1092
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
Merged
Wrap blockmean #1092
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7568f8e
Refactor blockmedian to support mean and mode
fa4a049
Rename blockmedian.py to blockm.py
b80af1f
Wrap method blockmean
43b8a40
Add tests for blockmean method
ebcec0a
Merge branch 'master' into blockm
6cce446
Remove blockmode mentions
344f9cd
Merge branch 'master' into blockm
b161292
Merge branch 'master' into blockm
ea573a5
Add aspatial alias
62a763b
Add parameters to blockm docstring
55a97be
Only describe block_method in params
f34e778
Move internal function to top of module
ff5c49e
Merge branch 'master' into blockm
4b66eb6
Merge branch 'master' into blockm
seisman 47e7210
Merge branch 'master' into blockm
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ Operations on tabular data: | |
.. autosummary:: | ||
:toctree: generated | ||
|
||
blockmean | ||
blockmedian | ||
surface | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
Tests for blockmean. | ||
""" | ||
import os | ||
|
||
import numpy.testing as npt | ||
import pandas as pd | ||
import pytest | ||
from pygmt import blockmean | ||
from pygmt.datasets import load_sample_bathymetry | ||
from pygmt.exceptions import GMTInvalidInput | ||
from pygmt.helpers import GMTTempFile, data_kind | ||
|
||
|
||
def test_blockmean_input_dataframe(): | ||
""" | ||
Run blockmean by passing in a pandas.DataFrame as input. | ||
""" | ||
dataframe = load_sample_bathymetry() | ||
output = blockmean(table=dataframe, spacing="5m", region=[245, 255, 20, 30]) | ||
assert isinstance(output, pd.DataFrame) | ||
assert all(dataframe.columns == output.columns) | ||
assert output.shape == (5849, 3) | ||
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0]) | ||
|
||
return output | ||
|
||
|
||
def test_blockmean_wrong_kind_of_input_table_matrix(): | ||
""" | ||
Run blockmean using table input that is not a pandas.DataFrame but still a | ||
matrix. | ||
""" | ||
dataframe = load_sample_bathymetry() | ||
invalid_table = dataframe.values | ||
assert data_kind(invalid_table) == "matrix" | ||
with pytest.raises(GMTInvalidInput): | ||
blockmean(table=invalid_table, spacing="5m", region=[245, 255, 20, 30]) | ||
|
||
|
||
def test_blockmean_wrong_kind_of_input_table_grid(): | ||
""" | ||
Run blockmean using table input that is not a pandas.DataFrame or file but | ||
a grid. | ||
""" | ||
dataframe = load_sample_bathymetry() | ||
invalid_table = dataframe.bathymetry.to_xarray() | ||
assert data_kind(invalid_table) == "grid" | ||
with pytest.raises(GMTInvalidInput): | ||
blockmean(table=invalid_table, spacing="5m", region=[245, 255, 20, 30]) | ||
|
||
|
||
def test_blockmean_input_filename(): | ||
""" | ||
Run blockmean by passing in an ASCII text file as input. | ||
""" | ||
with GMTTempFile() as tmpfile: | ||
output = blockmean( | ||
table="@tut_ship.xyz", | ||
spacing="5m", | ||
region=[245, 255, 20, 30], | ||
outfile=tmpfile.name, | ||
) | ||
assert output is None # check that output is None since outfile is set | ||
assert os.path.exists(path=tmpfile.name) # check that outfile exists at path | ||
output = pd.read_csv(tmpfile.name, sep="\t", header=None) | ||
assert output.shape == (5849, 3) | ||
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0]) | ||
|
||
return output | ||
|
||
|
||
def test_blockmean_without_outfile_setting(): | ||
""" | ||
Run blockmean by not passing in outfile parameter setting. | ||
""" | ||
with pytest.raises(GMTInvalidInput): | ||
blockmean(table="@tut_ship.xyz", spacing="5m", region=[245, 255, 20, 30]) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.