-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add a Fourier generator for periodic spatial random fields #302
Merged
Merged
Changes from all commits
Commits
Show all changes
107 commits
Select commit
Hold shift + click to select a range
e4032d7
initial commit of Fourier generator
LSchueler ed0d0bf
Fix k and delta k generation
LSchueler f61799c
Fix len-scale problem
LSchueler 79f1fc2
Add optional arg `period_len` to `Fourier` gen
LSchueler d011d26
Add optional arg `period_offset` to `Fourier` gen
LSchueler a5e7574
Cleanup
LSchueler 2321900
Add getters & setters
LSchueler 724e2b8
Cleanup
LSchueler f4a8a9d
Covmodel: all kwargs after dim are now keyword only
MuellerSeb 5bf5404
tests: minimal black fixes
MuellerSeb 970847d
covmodel: add time attribute
MuellerSeb 0855f59
time: add time axis to plotter
MuellerSeb befa9e4
Examples: update examples with new time attribute
MuellerSeb 8dc919c
pylint: ignore 'use-dict-literal', increase max limits
MuellerSeb eb1213a
CovModel: add radius property; correctly scale time axis for latlon; …
MuellerSeb 005f89f
examples: use radius instead of rescale for latlon models now
MuellerSeb 4fa6f7c
CovModel: update __repr__
MuellerSeb 11bd0e0
CovModel: rename 'radius' to 'geo_scale' and add more scales
MuellerSeb 7f70c10
Better geo_scale documentation
MuellerSeb 923c002
examples: fix typo
MuellerSeb 7c387eb
vario: rename 'bin_centres' to 'bin_center' following doc-string
MuellerSeb dcc69fd
tools: add great_circle_to_chordal; add radius to chordal_to_great_ci…
MuellerSeb 9fe9f58
vario: add geo_scale to variogram estimation routines
MuellerSeb ecaf914
vario: forward kwargs to standard_bins routine
MuellerSeb 42d33df
examples: update examples for geo_scale
MuellerSeb a91bac2
debug fix
MuellerSeb 7e034a4
update latlon auto-bin example with geo_scale
MuellerSeb 8edd1e4
examples: update readme for geo_scale
MuellerSeb 1901c89
krige: auto fitting not possible for spatio-temporal latlon models; u…
MuellerSeb f68c990
CovModel: spatial vario/cov/cor now also use xyz with latlon models
MuellerSeb b150275
plot: minor fixes for latlon
MuellerSeb 0c6a124
CovModel: rename 'time' to 'temporal'
MuellerSeb 7e30a54
geo_scale: better docs; always use KM_SCALE in examples
MuellerSeb 717da08
Plot: minor fixes for st plots
MuellerSeb 1049cc9
Krige: bugfix for renamed attribute temporal
MuellerSeb d0232cd
CovModel: prevent rotation between spatial and temporal dims
MuellerSeb 66740a3
CovModel: saver setting of anis
MuellerSeb c961fd2
minor f-string fix
MuellerSeb 5d7790f
test temporal related stuff
MuellerSeb 250bee0
more temporal tests
MuellerSeb aab6967
CovModel: add 'spatial_dim' argument
MuellerSeb 0a3ce91
minor f-string fixes
MuellerSeb 63d49be
update changelog
MuellerSeb edbbe48
CovModel: be less strict about key-word-only args (don't want to both…
MuellerSeb ba95019
variogram: rename bin_center to bin_centers
MuellerSeb 87a516e
changelog: minor fix
MuellerSeb 639ecdb
vario: revert moving code-block
MuellerSeb 64d9a14
changelog: minor markdown fixes
MuellerSeb e654a6e
Generator: remove 'verbose' argument; make arguments key-word only
MuellerSeb 6cfb74b
Tests: use kwargs from now on
MuellerSeb ae4ec7a
transform: add low/high to uniform trans
MuellerSeb 2b755d3
uniform: forward low/high
MuellerSeb b91a96e
finalize changelog for v1.5
MuellerSeb b40bf5a
fix cython-lint complains
MuellerSeb b9bc3d3
add lint opt deps; add cython-lint check in CI
MuellerSeb dd0f2a6
apply isort to pyx files
MuellerSeb e6f3529
cython: switch to cython >3.0
MuellerSeb 04adf65
lint: remove caps for lint deps
MuellerSeb f10ae35
python: drop py37 and add 312
MuellerSeb 26efefb
update changelog
MuellerSeb beb4f44
rtd config fix
MuellerSeb f5bd2bd
Add a simple example of how to use the Fourier gen
LSchueler ad413d5
Add exception for Fourier with unstruct grid
LSchueler 3a3b5fe
Black
LSchueler ec96449
Remove `period_offset`, should be pre- or post-pro
LSchueler d55e52b
Add a few first test cases
LSchueler 362f501
Add another example, including field transf.
LSchueler 4cceaf4
Merge branch 'main' into fourier-gen
LSchueler 657e8e8
Merge branch 'main' into fourier-gen
LSchueler f92fd63
[WIP] Add variable pre-factors to Fourier gen.
LSchueler 701124e
Merge branch 'main' into fourier-gen
MuellerSeb aaf84bb
Fix Fourier meth. eq. and let user generate modes
LSchueler 1a6aae1
Improve user interface of Fourier method
LSchueler 1c755e4
Update unittests
LSchueler 7c07f6e
Update examples
LSchueler 3474d02
Black
LSchueler 23e1b3a
Oh damn... also blacken tests
LSchueler c10d4c7
And of course also black the examples
LSchueler 17013f9
Isort
LSchueler a197eac
Fix test
LSchueler e33bcf6
Fix example
LSchueler 6449f92
Delinting
LSchueler 15bd8c1
Isort
LSchueler a76d6ab
Fix formatting problem
LSchueler 2c05f2f
Deactivate Cython lint & coverage, both broken atm
LSchueler 456611b
Fix factor
LSchueler afad191
Fix mode generation & variance
LSchueler db7444e
Fix period. in Fourier gen, update tests, examples
LSchueler 5ac2d99
Remove unused import
LSchueler 6e09342
Let's be more inclusive
LSchueler 6960bee
Add setters, some cleanup
LSchueler d4370da
Add setter tests
LSchueler 6a12024
Fix docstring
LSchueler b76119c
Merge branch 'main' into fourier-gen
LSchueler 38b6c0d
Fix docstring
LSchueler 7397bc6
Remove keyword `verbose`
LSchueler 59952a8
Use GSTools-Core for Fourier meth., if USE_RUST
LSchueler fa4dbbf
Turn coveralls back on again
LSchueler c3ec1e2
Drop exception for unstruct's, not needed!
LSchueler f1e7f7c
Improve Fourier's interface
LSchueler 6e709f2
Fix exception text
LSchueler 4fcf784
Change the way ani. fields are handled by Fourier
LSchueler cd1f5ac
Update readme's, examples
LSchueler 29d0ea6
Fix stupid typo
LSchueler 7849284
Improve Fourier examples
LSchueler 7e2c9f3
Merge branch 'main' into fourier-gen
LSchueler c04c924
Black example & fix typo
LSchueler 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 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,44 @@ | ||
""" | ||
Generating a Simple Periodic Random Field | ||
----------------------------------------- | ||
|
||
In this simple example we are going to learn how to generate periodic spatial | ||
random fields. The Fourier method comes naturally with the property of | ||
periodicity, so we'll use it to create the random field. | ||
""" | ||
|
||
import numpy as np | ||
|
||
import gstools as gs | ||
|
||
# We start off by defining the spatial grid. For the sake of simplicity, we | ||
# use a square domain. We set the optional argument `endpoint` to `False`, to | ||
# not make the domain in each dimension one grid cell larger than the | ||
# periodicity. | ||
L = 500.0 | ||
x = np.linspace(0, L, 256, endpoint=False) | ||
y = np.linspace(0, L, 128, endpoint=False) | ||
|
||
# Now, we create a Gaussian covariance model with a correlation length which is | ||
# roughly half the size of the grid. | ||
model = gs.Gaussian(dim=2, var=1, len_scale=200) | ||
|
||
# Next, we hand the cov. model to the spatial random field class `SRF` | ||
# and set the generator to `"Fourier"`. The argument `period` is set to the | ||
# domain size. If only a single number is given, the same periodicity is | ||
# applied in each dimension, as shown in this example. The `mode_no` argument | ||
# sets the number of Fourier modes. If only an integer is given, that number | ||
# of modes is used for all dimensions. | ||
srf = gs.SRF( | ||
model, | ||
generator="Fourier", | ||
period=L, | ||
mode_no=32, | ||
seed=1681903, | ||
) | ||
|
||
# Now, we can calculate the field with the given parameters. | ||
srf((x, y), mesh_type="structured") | ||
|
||
# GSTools has a few simple visualization methods built in. | ||
srf.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Generating a Transformed Periodic Random Field | ||
---------------------------------------------- | ||
|
||
Building on the precious example, we are now going to generate periodic | ||
spatial random fields with a transformation applied, resulting in a level set. | ||
""" | ||
|
||
import numpy as np | ||
|
||
import gstools as gs | ||
|
||
# We start off by defining the spatial grid. As in the previous example, we do | ||
# not want to include the endpoints. | ||
L = np.array((500, 400)) | ||
x = np.linspace(0, L[0], 300, endpoint=False) | ||
y = np.linspace(0, L[1], 200, endpoint=False) | ||
|
||
# Instead of using a Gaussian covariance model, we will use the much rougher | ||
# exponential model and we will introduce an anisotropy by using two different | ||
# length scales in the x- and y-directions | ||
model = gs.Exponential(dim=2, var=2, len_scale=[80, 20]) | ||
|
||
# Same as before, we set up the spatial random field. But this time, we will | ||
# use a periodicity which is equal to the domain size in x-direction, but | ||
# half the domain size in y-direction. And we will use different `mode_no` for | ||
# the different dimensions. | ||
srf = gs.SRF( | ||
model, | ||
generator="Fourier", | ||
period=[L[0], L[1] / 2], | ||
mode_no=[30, 20], | ||
seed=1681903, | ||
) | ||
# and compute it on our spatial domain | ||
srf((x, y), mesh_type="structured") | ||
|
||
# With the field generated, we can now apply transformations starting with a | ||
# discretization of the field into 4 different values | ||
thresholds = np.linspace(np.min(srf.field), np.max(srf.field), 4) | ||
srf.transform("discrete", store="transform_discrete", values=thresholds) | ||
srf.plot("transform_discrete") | ||
|
||
# This is already a nice result, but we want to pronounce the peaks of the | ||
# field. We can do this by applying a log-normal transformation on top | ||
srf.transform( | ||
"lognormal", field="transform_discrete", store="transform_lognormal" | ||
) | ||
srf.plot("transform_lognormal") |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be solved with #343
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll solve that in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's going to be solved in PR #354.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #354 should be merged first and then I can update this branch with the fixes.