-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from GeoStat-Framework/field_update
Field: enable standalone use
- Loading branch information
Showing
6 changed files
with
160 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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) | ||
plotter(pos=(x0, x1, x2, x3), field=values) | ||
plotter.plot() |
This file contains 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 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 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 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() |