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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
84177ce
preliminary interface
mmaelicke Jul 4, 2023
eecc104
add typing extensions to requirements
mmaelicke Jul 4, 2023
5b208da
change typing to avoid circular imports
mmaelicke Jul 5, 2023
bd5eab1
draft GStatSim interface
mmaelicke Jul 5, 2023
1767421
Merge pull request #153 from mmaelicke/main
mmaelicke Jul 5, 2023
48dfabd
add some docstrings
mmaelicke Jul 5, 2023
7804cc3
fix typo
mmaelicke Jul 5, 2023
9fa6b29
fixed column setting bugs
mmaelicke Jul 5, 2023
8bdfe43
add some tests
mmaelicke Jul 5, 2023
0e89977
add gstatsim to test dependencies
mmaelicke Jul 5, 2023
c5040d9
check for python>=3.7 if using gstatsim
mmaelicke Jul 5, 2023
e682928
emove python3.6 tests for gstatsim
mmaelicke Jul 5, 2023
88339fc
also exclude python 3.8
mmaelicke Jul 5, 2023
f70bdfd
make check function public
mmaelicke Jul 5, 2023
56bd696
update to quiet parameter
mmaelicke Jul 11, 2023
b53e1bc
update interaface to new params
mmaelicke Jul 11, 2023
929354a
add docstring to prediction grid
mmaelicke Jul 16, 2023
ac3c8b2
add interfaces to the docs
mmaelicke Jul 16, 2023
074e6f9
test prediction grid interface function
mmaelicke Jul 17, 2023
3f01059
Merge branch 'gstatsim-interface' into resolve-gstatsim-conflict
mmaelicke Oct 14, 2023
277b057
Merge pull request #171 from mmaelicke/resolve-gstatsim-conflict
mmaelicke Oct 14, 2023
f315c84
update interface to gstatsim>=1.0.6
mmaelicke Oct 16, 2023
bec6115
pre-commit fixes
mmaelicke Oct 16, 2023
a7d540e
change coverage settings
mmaelicke Oct 16, 2023
a4720b9
fix to coverage
mmaelicke Oct 16, 2023
f649dc3
use newer codecov version
mmaelicke Oct 16, 2023
c5071b0
ignore @overloads
mmaelicke Oct 16, 2023
8abaee4
add test for bbox init with resolution
mmaelicke Oct 16, 2023
5980f22
check most init params combinations
mmaelicke Oct 16, 2023
11ef090
Update main.yml
mmaelicke Oct 16, 2023
11a60c5
add tests for Variogram interface
mmaelicke Oct 19, 2023
4c9090a
fix pre-commit
mmaelicke Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ exclude_lines =
raise NotImplementedError
raise ModuleNotFoundError
if __name__ == .__main__.:
if TYPE_CHECKING:
@overload
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run tests
run: pytest --cov-config=.coveragerc --cov=./ --cov-report=xml
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
env_vars: OS, PYTHON
Expand Down
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.0.6
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.0.6
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>=1.0.6
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 specifying 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