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

GStatSim interface #155

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

GStatSim interface #155

wants to merge 32 commits into from

Conversation

mmaelicke
Copy link
Owner

@GatorGlaciology, this might be interesting for you.
This pull request introduces an preliminary interface to GStatSim. There are 3 main options for interfacing:

  • generate a GStatSim compatible prediction_grid from a Variogram instance
  • generate the input to a skrige_sgs or okrige_sgs simulation from a Variogram
  • directly run skrige_sgs or okrige_sgs in parallel, from a Variogram instance

additionally, the interface defines a Grid class, which generates the prediction_grid but keeps track of the shape needed for the target field, to transform the result. @GatorGlaciology, maybe this class is also helpful for you? I could open a pull request to add it to GStatSim instead of SciKit-GStat, if you are interested.

interfaces

prediction grid

You can generate a prediction_grid like:

coords, vals = skg.data.pancake(N=300).get('sample')
vario = skg.Variogram(coords, vals, maxlag=0.6, n_lags=25)

# use like
grid = vario.gstatsim_prediction_grid(resolution=5)

# this will find rows, cols as close to 400x400 as possible to have the same resolution in both directions
grid = pred_grid = vario.gstatsim_prediction_grid(rows=400, cols=400)  
print(grid).   # prints <Grid with 401 rows and 405 cols at 1.235 resolution>

# then convert to GStatSim:
grid.prediction_grid

simulation parameters

The simulation params can be accessed via the interface

from skgstat.interfaces import gstatsim_mod

# you can pass a grid, or a resolution or a (rows, cols) tuple as grid
grid, cond_df, variogram_params = gstatsim_mod.simulation_params(vario, 5)

all in one

And finally use the simulation directly

fields = vario.simulate(grid, method='simple', n_jobs=8, size=8)

This creates a list of 8 simulated fields. If 8 cores are available, this is as fast as using GStatSim only (or n_jobs=1) as each simulation is run in parallel.

ToDos

@GatorGlaciology, I will add a bit of docs and tests. Meanwhile you are more than welcome to comment on this interface.
I also need to define, which Variogram instances actually can be exported to GStatSim.

@mmaelicke mmaelicke self-assigned this Jul 5, 2023
@GatorGlaciology
Copy link

Very cool! This looks incredibly useful. Let us know if we can help in any way

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Attention: 22 lines in your changes are missing coverage. Please review.

Comparison is base (a59da91) 90.74% compared to head (4c9090a) 90.48%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   90.74%   90.48%   -0.26%     
==========================================
  Files          23       24       +1     
  Lines        2475     2639     +164     
==========================================
+ Hits         2246     2388     +142     
- Misses        229      251      +22     
Files Coverage Δ
skgstat/Variogram.py 96.41% <100.00%> (+0.04%) ⬆️
skgstat/interfaces/gstatsim_mod.py 85.71% <85.71%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mmaelicke mmaelicke mentioned this pull request Oct 13, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants