{"id":13720323,"url":"https://github.com/robinthibaut/pysgems","last_synced_at":"2025-09-07T14:34:56.210Z","repository":{"id":40268838,"uuid":"261676899","full_name":"robinthibaut/pysgems","owner":"robinthibaut","description":"Use SGeMS (Stanford Geostatistical Modeling Software) within Python.","archived":false,"fork":false,"pushed_at":"2023-03-08T10:25:14.000Z","size":3144,"stargazers_count":52,"open_issues_count":8,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T22:14:37.434Z","etag":null,"topics":["geostatistics","sgems"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robinthibaut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"robinthibaut","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-05-06T06:55:58.000Z","updated_at":"2025-04-03T19:27:10.000Z","dependencies_parsed_at":"2023-02-19T04:16:11.076Z","dependency_job_id":"71ba9c10-1109-4bd1-89fd-9d4d58fa079c","html_url":"https://github.com/robinthibaut/pysgems","commit_stats":{"total_commits":250,"total_committers":9,"mean_commits":27.77777777777778,"dds":0.12,"last_synced_commit":"7a4e72b63f118d72dca2c0dbd1e4a20b8df4b0a1"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinthibaut%2Fpysgems","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinthibaut%2Fpysgems/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinthibaut%2Fpysgems/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinthibaut%2Fpysgems/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robinthibaut","download_url":"https://codeload.github.com/robinthibaut/pysgems/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248943444,"owners_count":21186958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geostatistics","sgems"],"created_at":"2024-08-03T01:01:02.493Z","updated_at":"2025-04-14T19:03:40.095Z","avatar_url":"https://github.com/robinthibaut.png","language":"Python","funding_links":["https://github.com/sponsors/robinthibaut"],"categories":["Software"],"sub_categories":["Geostatistics"],"readme":"\u003cimg src=\"docs/img/Pysgems-03.png\" height=\"150\"\u003e\n\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4773587.svg)](https://doi.org/10.5281/zenodo.4773587)\n[![PyPI version](https://badge.fury.io/py/pysgems.svg)](https://badge.fury.io/py/pysgems)\n[![Downloads](https://pepy.tech/badge/pysgems)](https://pepy.tech/project/pysgems)\n[![Documentation Status](https://readthedocs.org/projects/pysgems/badge/?version=latest)](https://pysgems.readthedocs.io/en/latest/?badge=latest)\n\n# pysgems\nUse SGeMS (Stanford Geostatistical Modeling Software) within Python.\n\nContributors / feedback from users are welcome.\n\nSGeMS home page: http://sgems.sourceforge.net/\n\nThe kriging example described in this file can be found in the 'demo_kriging.py' file.\n\n## Installation\n\nClone this repository, or:\n\n```bash\npip install pysgems\n```\nNote that SGEMS only runs on Microsoft Windows.\n\nUsers need to add this variable to their system **environment variables**:\n\nName: `GSTLAPPLIHOME`\n\nValue: Path to your SGEMS folder (e.g., `C:\\Program Files (x86)\\SGeMS`)\n\n*Important*: It is also necessary to add the path of your SGEMS folder to the **system variable** 'Path'.\n\n## Documentation\n\n[pysgems.readthedocs.io](https://pysgems.readthedocs.io/en/latest/)\n\n## Introduction\n\nThis package works by calling SGEMS via the command in the Command Prompt:\n```bash\nsgems.exe sgems.script\n```\n\nThe sgems.script contains a command that SGEMS will execute internally:\n\n```bash\nRunScript python_script.py\n```\n\nThe python_script file contains a Python script (ver. \u003c= 2.7.x) that SGEMS will execute, as if ran into the `Run Script...` window of SGEMS.\n\nThis package revolves around modifying this Python script file.\n\n## Usage\n\nThis package was designed with 2D estimation/simulation problems in mind, it should support 3D grids but it hasn't been tested yet.\n\n### Creating an SGEMS project\n\n#### Initiate\nA SGEMS project is created by first creating a pjt object \"Sgems\". When you create the project object you can define the project's name, workspace path, results directory path, python scripts templates directory path, and the last parameter is the 'no-data' value to take into accounts 'no-data points'. All of these are optional parameters. If no result directory is provided, one will automatically be generated with an unique name.\n\n```python\nimport os\nfrom os.path import join as join_path\n\nfrom pysgems.algo.sgalgo import XML\nfrom pysgems.dis.sgdis import Discretize\nfrom pysgems.io.sgio import PointSet\nfrom pysgems.plot.sgplots import Plots\nfrom pysgems.sgems import sg\n\n# Initiate sgems project\ncwd = os.getcwd()  # Working directory\nrdir = join_path(cwd, 'results', 'demo_kriging')  # Results directory\npjt = sg.Sgems(project_name='sgems_test', project_wd=cwd, res_dir=rdir)\n```\n\n#### Load point set\n\nThe next step is to create a package object \"PointSet\". The first parameter of the PointSet class is a project object, which ties a PointSet object to a specific project. The second parameter is the path to the dataset file. The package expects the ASCII GEOEAS data format.\n\n```python\n# Load data point set\ndata_dir = join_path(cwd, 'datasets', 'demo_kriging')\ndataset = 'sgems_dataset.eas'\nfile_path = join_path(data_dir, dataset)\n\nps = PointSet(project=pjt, pointset_path=file_path)\n```\n\n#### Tie the project to a grid\n\nThe next package to add is the spatial discretization package. Create a package object \"Discretize\". The first parameter is the project object to which the package will be tied. You have to input cell dimensions dx, dy. By default, dz=0. Optionally specify the grid bounding box by adding parameters xo, yo, zo, x_lim, y_lim, z_lim. If none is provided, the bounding box will automatically be computed based on the data points coordinates (assuming that a \"PoinSet\" object has been added to the project).\n\n```python\n# Generate grid. Grid dimensions can automatically be generated based on the data points\n# unless specified otherwise, but cell dimensions dx, dy, (dz) must be specified\nds = Discretize(project=pjt, dx=5, dy=5)\n```\n\n#### Visualize your project geometry\n\nTo check your grid geometry and visualize data points, create a package object \"Plots\" and tie it to the project.\n\n```python\n# Display point coordinates and grid\npl = Plots(project=pjt)\npl.plot_coordinates()\n```\n\n\u003cimg src=\"pysgems/examples/results/demo_kriging/grid.png\" alt=\"plot\" style=\"width:30;height:30\"\u003e\n\n#### Get algorithm XML from SGeMS\n\nUsers must first run their algorithm inside SGeMS, view the Commands Panel, copy the algorithm XML and paste it into a XML file (e.g., algorithm.xml), and save this file into the 'algorithms' folder.\n\nThe algorithm XML starts and ends with:\n```xml\n\u003cparameters\u003e ... \u003c/parameters\u003e\n```\n\nUse a package object \"XML\" to load your algorithms. The first parameter is the project object. The second parameter is the path to the folder in which your algorithms xml files are stored.\n\n```python\n#  Load your algorithm xml file in the 'algorithms' folder.\nalgo_dir = join_path(os.path.dirname(cwd), 'algorithms')\nal = XML(project=pjt, algo_dir=algo_dir)\n```\n\nLet's take for example the kriging algorithm stored in ../algorithms/kriging.xml.\nRead the 'kriging.xml' file in the following way:\n\n```python\nal.xml_reader('kriging')\n```\n\nDisplay the XML structure:\n\n```python\n\nal.show_tree()\n\n```\n\nIt will output:\n\n```python\nPath\n{attribute1: value1, ..., attribute_n: value_n}\n```\n\nFor the kriging algorithm the first lines will be:\n\n```python\nalgorithm\n{'name': 'kriging_mean'}\nVariogram\n{'nugget': '0', 'structures_count': '1'}\nVariogram//structure_1\n{'contribution': '1', 'type': 'Spherical'}\nVariogram//structure_1//ranges\n{'max': '150', 'medium': '150', 'min': '150'}\n```\n\nTo modify an element:\n\n```python\nal.xml_update(path, attribute_name, new_value)\n```\n\nFor example:\n\n```python\nal.xml_update('Variogram', 'nugget', '0.01')\nal.xml_update('Variogram', 'structure_1', 'type', 'Exponential')\n```\n\nThe following is also acceptable:\n\n```python\nal.xml_update('Variogram//structure_1//ranges', new_attribute_dict={'max': '150', 'medium': '150', 'min': '150'})\n```\n\n#### Exports needed point sets in SGEMS binary format.\n\nIn order to use the data set within SGEMS, it is necessary to export the needed point sets in the SGEMS binary format.\nGet the list of features name available to export:\n\n```python\nprint(sg.point_set.columns)\nout: ['x', 'y', 'z', 'ag', 'as', 'au', 'cu', 'pb', 's', 'zn']\n```\n\nThe line\n\n```python\nps.export_01('feature_name')\n```\n\nWill export the desired feature point set in SGEMS binary format to the results folder. Rows containing the no-data value will not be exported.\n\nAt this time, the export_01 method only supports point sets for individual features. It should be extended to support grids and multiple features.\n\n#### Run SGEMS\n\nTo load the updated XML algorithm into the SGEMS Python script template:\n\n```python\nsg.write_command()\n```\n\nThe files will be loaded in the results folder (automatically generated or user-defined).\n\nRun the algorithm by:\n\n```python\nsg.run()\n```\n\nIt will generate a batch file and a script file. The batch file can later be used outside of Python.\n\nCheck the results:\n\n\u003cimg src=\"pysgems/examples/results/demo_kriging/results.png\" alt=\"plot\" style=\"width:30;height:30\"\u003e\n\n\u003cimg src=\"pysgems/examples/results/demo_kriging/results_var.png\" alt=\"plot\" style=\"width:30;height:30\"\u003e\n\n## Contribution and points to improve\n\n- Contributors and feedback from users are welcome. \n\n- The package should be made more robust and able to support all SGEMS features.\n\n- More methods should be build to export/import binary grids and point sets with multiple features.\n\n- The package should be properly documented.\n\n- The package should have more built-in visualization methods.\n\n- The Python script template should be more generic and its modification more flexible.\n\n- More examples should be uploaded.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinthibaut%2Fpysgems","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinthibaut%2Fpysgems","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinthibaut%2Fpysgems/lists"}