-
Notifications
You must be signed in to change notification settings - Fork 74
Field: enable standalone use #166
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fce7f59
Field: enable standalone use with given 'dim'; add 'points' method; a…
MuellerSeb e823796
Tests: more tests for Field class
MuellerSeb 325bbcf
Field: allow None as field values in standalone Field class (will be …
MuellerSeb 7b62641
Field: remove points methods to prevent confusion
MuellerSeb d0cefac
Field: add example for standalone usage
MuellerSeb ad95b5e
Field: ignore pylint W0222 for differing signature in CondSRF.__call__
MuellerSeb aeba3c1
Field: remove test for points method
MuellerSeb 1ae83ed
Field.mesh: minor doc update
MuellerSeb 6c5692a
update Changelog
MuellerSeb 68e2c53
Field: use single RandomState in example
MuellerSeb 9862838
Field: better doc for field in __call__
MuellerSeb 11db203
Field.mesh: better doc for kwargs
MuellerSeb 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
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,28 @@ | ||
""" | ||
Standalone Field class | ||
---------------------- | ||
|
||
The :any:`Field` class of GSTools can be used to plot arbitrary data in nD. | ||
|
||
In the following example we will produce 10000 random points in 4D with | ||
random values and plot them. | ||
""" | ||
import numpy as np | ||
import gstools as gs | ||
|
||
rng = np.random.RandomState(19970221) | ||
x0 = rng.rand(10000) * 100.0 | ||
x1 = rng.rand(10000) * 100.0 | ||
x2 = rng.rand(10000) * 100.0 | ||
x3 = rng.rand(10000) * 100.0 | ||
values = rng.rand(10000) * 100.0 | ||
|
||
############################################################################### | ||
# Only thing needed to instantiate the Field is the dimension. | ||
# | ||
# Afterwards we can call the instance like all other Fields | ||
# (:any:`SRF`, :any:`Krige` or :any:`CondSRF`), but with an additional field. | ||
|
||
plotter = gs.field.Field(dim=4) | ||
MuellerSeb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
plotter(pos=(x0, x1, x2, x3), field=values) | ||
plotter.plot() |
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,51 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" | ||
This is the unittest of SRF class. | ||
""" | ||
|
||
import unittest | ||
import numpy as np | ||
import gstools as gs | ||
|
||
|
||
class TestField(unittest.TestCase): | ||
def setUp(self): | ||
self.cov_model = gs.Gaussian(dim=2, var=1.5, len_scale=4.0) | ||
rng = np.random.RandomState(123018) | ||
x = rng.uniform(0.0, 10, 100) | ||
y = rng.uniform(0.0, 10, 100) | ||
self.field = rng.uniform(0.0, 10, 100) | ||
self.pos = np.array([x, y]) | ||
|
||
def test_standalone(self): | ||
fld = gs.field.Field(dim=2) | ||
fld_cov = gs.field.Field(model=self.cov_model) | ||
field1 = fld(self.pos, self.field) | ||
field2 = fld_cov(self.pos, self.field) | ||
self.assertTrue(np.all(np.isclose(field1, field2))) | ||
self.assertTrue(np.all(np.isclose(field1, self.field))) | ||
|
||
def test_raise(self): | ||
# vector field on latlon | ||
fld = gs.field.Field(gs.Gaussian(latlon=True), value_type="vector") | ||
self.assertRaises(ValueError, fld, [1, 2], [1, 2]) | ||
# no pos tuple present | ||
fld = gs.field.Field(dim=2) | ||
self.assertRaises(ValueError, fld.post_field, [1, 2]) | ||
# wrong model type | ||
with self.assertRaises(ValueError): | ||
gs.field.Field(model=3.1415) | ||
# no model and no dim given | ||
with self.assertRaises(ValueError): | ||
gs.field.Field() | ||
# wrong value type | ||
with self.assertRaises(ValueError): | ||
gs.field.Field(dim=2, value_type="complex") | ||
# wrong mean shape | ||
with self.assertRaises(ValueError): | ||
gs.field.Field(dim=3, mean=[1, 2]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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.