Skip to content

Commit

Permalink
Merge branch 'gstatsim-interface' into resolve-gstatsim-conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelicke authored Oct 14, 2023
2 parents a59da91 + 074e6f9 commit 3f01059
Show file tree
Hide file tree
Showing 9 changed files with 755 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/reference/interfaces.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=======================
Scikit-GStat interfaces
=======================

Scikit-GStat can interface with a number of other packages.
This sections describes the interface functions. Check the
tutorials folder for examples.

GSTools
=======

.. automodule:: skgstat.interfaces.gstools
:members: stable_scale, skgstat_to_gstools, skgstat_to_krige


GStatSim
========

.. automodule:: skgstat.interfaces.gstatsim_mod
:members: Grid, prediction_grid, simulation_params, run_simulation, simulate
1 change: 1 addition & 0 deletions docs/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Code Reference
estimator
models
kriging
interfaces
data
metric_space
util
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ numba
scikit-learn
imageio
tqdm
typing_extensions
1 change: 1 addition & 0 deletions requirements.unittest.3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-depends
pykrige
gstools>=1.3
plotly
gstatsim
1 change: 1 addition & 0 deletions requirements.unittest.3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-depends
pykrige
gstools>=1.3
plotly
gstatsim
1 change: 1 addition & 0 deletions requirements.unittest.3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-depends
pykrige
gstools>=1.3
plotly
gstatsim
57 changes: 56 additions & 1 deletion skgstat/Variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""
import copy
import inspect
from typing_extensions import Literal
import warnings
from typing import Iterable, Callable, Union, Tuple
from typing import Iterable, Callable, List, Optional, Union, Tuple

import numpy as np
from pandas import DataFrame
Expand All @@ -18,6 +19,7 @@
from skgstat.util import shannon_entropy
from .MetricSpace import MetricSpace, ProbabalisticMetricSpace
from skgstat.interfaces.gstools import skgstat_to_gstools, skgstat_to_krige
from skgstat.interfaces import gstatsim_mod


class Variogram(object):
Expand Down Expand Up @@ -2794,6 +2796,59 @@ def to_DataFrame(self, n=100, force=False):
self._model_name: data}
).copy()

def gstatsim_prediction_grid(self, resolution: Optional[int] = None, rows: Optional[int] = None, cols: Optional[int] = None, as_numpy: bool = False) -> Union[gstatsim_mod.Grid, np.ndarray]:
"""
Generate a structured gried of coordinates from this Variogram instance.
The grid has the shape (N, 2), where N is the number of grid points.
It can be created by specifiying the resolution or the number of rows and cols.
If rows and cols are used, the grid will have the same resolution in both directions,
which means, that the final grid will have a different number of rows, cols
than specified.
Parameters
----------
resolution : int, optional
The resolution of the grid, by default None
rows : int, optional
The number of rows, by default None
cols : int, optional
The number of cols, by default None
as_numpy : bool, optional
If True, the grid will be returned as a numpy.ndarray, by default False
Raises
------
ValueError
If the Variogram instance is not 2D
Returns
-------
Union[gstatsim_mod.Grid, np.ndarray]
The grid as a gstatsim_mod.Grid instance or a numpy.ndarray
"""
# this does only work in 2D
if self.dim != 2:
raise ValueError('This function only works in 2D')

# generate the grid
grid = gstatsim_mod.prediction_grid(self, resolution, rows, cols, as_numpy=as_numpy)
return grid

def simulation(
self,
grid: Optional[Union[gstatsim_mod.Grid, np.ndarray, Union[int, float], Tuple[int, int]]] = None,
num_points: int = 20,
radius: Optional[Union[int, float]] = None,
method: Union[Literal['simple'], Literal['ordinary']] = 'simple',
quiet: bool = True,
n_jobs: int = 1,
size: int = 1,
**kwargs,
) -> List[np.ndarray]:
""""""
fields = gstatsim_mod.simulate(self, grid, num_points, radius, method, quiet, n_jobs, size, **kwargs)
return fields

def to_gstools(self, **kwargs):
"""
Instantiate a corresponding GSTools CovModel.
Expand Down
Loading

0 comments on commit 3f01059

Please sign in to comment.