python-ags4

python-ags4: A Python library to read, write, and validate AGS4 geodata files - Published in JOSS (2022)

https://gitlab.com/ags-data-format-wg/ags-python-library

Science Score: 89.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org
  • Committers with academic emails
    2 of 17 committers (11.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

Geotechnics geology geospatial geotechnical openml python
Last synced: 4 months ago · JSON representation

Repository

[Documentation](https://ags-data-format-wg.gitlab.io/ags-python-library/index.html) | A library to read and write AGS files using Pandas DataFrames

Basic Info
  • Host: gitlab.com
  • Owner: ags-data-format-wg
  • License: gpl-3.0+
  • Default Branch: main
Statistics
  • Stars: 20
  • Forks: 20
  • Open Issues: 29
  • Releases: 0
Topics
Geotechnics geology geospatial geotechnical openml python
Created almost 5 years ago
Metadata Files
Readme Changelog License

README.md

PyPI PyPI - Downloads Conda DOI Tests

python-ags4

[[TOC]]

Introduction

python-ags4 is a library of functions that

  • imports/reads AGS4 files to a collection of Pandas DataFrames.
  • data can be analyzed, manipulated, and updated using Pandas
  • and then exported/written back to an AGS4 file

Release available at pypi.org/project/python-ags4/

This project is maintained by the AGS Data Format Working Group

Note This repo was forked from github.com/asitha-sena/python-ags4 which is now archived and read-only

HEAD is gitlab.com/ags-data-format-wg/ags-python-library

Documentation

Installation

bash pip install python-ags4

Note Installation requires Python 3.9 or later.

Code Examples

First import the module.

python from python_ags4 import AGS4

Import data from an AGS4 file

```python

Load from a file

tables, headings = AGS4.AGS4todataframe('path/to/file.ags')

Or use our sample data

from pythonags4.data import loadtestdata tables, headings = loadtest_data() ``` * tables is a dictionary of Pandas DataFrames. Each DataFrame contains the data from a GROUP in the AGS4 file. * headings is a dictionary of lists. Each list has the header names of the corresponding GROUP

Important: If the above code throws an exception or returns an empty dictionary, it very likely that the input file is not a valid AGS4 file. In such a case, the AGS4.check_file() function can be used to validate the file and see whether anything needs to be fixed before trying again. Most users will find it easier to perform this step using the command line interface as it will provide a formatted error report that is much easier to read than the python dictionary created by directly calling the function.

All data are imported as text so they cannot be analyzed or plotted immediately. You can use the following code to convert all the numerical data in a DataFrame from text to numeric.

python LOCA = AGS4.convert_to_numeric(tables['LOCA'])

The AGS4.convert_to_numeric() function automatically converts all columns in the input DataFrame with a numeric TYPE to a float. (Note: The UNIT and TYPE rows are removed during this operation as they are non-numeric.)

Export data back to an AGS4 file

python AGS4.dataframe_to_AGS4(tables, headings, 'output.ags')

A DataFrame with numeric columns may not get exported with the correct precision so they should be converted back to formatted text. The AGS4.convert_to_text() function will do this automatically if an AGS4 dictionary file is provided with the necessary UNIT and TYPE information. Numeric fields in the DataFrame that are not described in the dictionary file will be skipped with a warning. python LOCA_txt = AGS4.convert_to_text(LOCA, 'DICT.ags')

Tables converted to numeric using the AGS4.convert_to_numeric() function should always be converted back to text before exporting to an AGS4 file. (Note: The UNIT and TYPE rows will be added back in addition to formatting the numeric columns.)

Jupyter Notebook

We have created an example Jupyter Notebook which imports an AGS file, plots boreholes on a map and creates a Striplog.

See here

Command Line Interface

A command-line interface (CLI) to access the core functionality of the library is available since version 0.2.0. It is automatically installed together with the library and can be accessed by typing ags4_cli in a terminal/shell. If you want the CLI to be available globally (i.e. not limited to a single virtual environment), then you can install it using pipx.

You can do the following operations via the CLI: 1. Check/validate AGS4 files asciicast

  1. Convert AGS4 to Excel spreadsheets (.xlsx) and back asciicast The data can be easily edited in a spreadsheet and then converted back a .ags file. The TYPE values for numeric columns can be changed in the spreadsheet and the data will be automatically reformatted correctly when converted back to .ags, as long as all values in a column are numbers. Any supposedly numeric columns with text entries will be skipped with a warning message. (Note: All data is imported to the spreadsheet as text entries so any column that should be reformatted should be explicitly converted to numbers in Excel.)

  2. Sort groups/tables in AGS4 files asciicast

Graphical User Interface using pandasgui

The output from python-ags4 can be directly used with pandasgui to view and edit AGS4 files using an interactive graphical user interface. It also provides functionality to plot and visualize the data.

```python from pandasgui import show from pythonags4.data import loadtest_data

tables, headings = loadtestdata() gui = show(**tables) ```

Any edits made in the GUI can be saved and exported back to an AGS4 file as follows:

```python updatedtables = gui.getdataframes()

AGS4.dataframetoAGS4(updated_tables, headings, 'output.ags') ```

Development

Please refer to the Wiki page for details about the development environment and how to get involved in the project.

API documentation available at https://ags-data-format-wg.gitlab.io/ags-python-library

Citation

Senanayake et al., (2022). python-ags4: A Python library to read, write, and validate AGS4 geodata files. Journal of Open Source Software, 7(79), 4569, https://doi.org/10.21105/joss.04569

Implementations

This library has been used to create

  • Windows Desktop Application - https://gitlab.com/ags-data-format-wg/ags-checker-desktop-app
  • Web application and API (pyagsapi) - https://github.com/BritishGeologicalSurvey/pyagsapi
    • Deployed as https://agsapi.bgs.ac.uk/
  • Excel Add On - https://gitlab.com/RogerChandler/ags-validator-excel-add-in

Owner

  • Name: AGS Data Format WG
  • Login: ags-data-format-wg
  • Kind: organization

AGS Data Format Working Group

JOSS Publication

python-ags4: A Python library to read, write, and validate AGS4 geodata files
Published
November 04, 2022
Volume 7, Issue 79, Page 4569
Authors
Asitha I. Senanayake ORCID
Norwegian Geotechnical Institute (formerly Fugro USA Marine, Inc.)
Roger J. Chandler
Seequent
Tony Daly
Association of Geotechnical and Geoenvironmental Specialists
Edward Lewis ORCID
British Geological Survey, Keyworth, UK
Editor
Jed Brown ORCID
Tags
geodata geotechnical geoenvironmental geophysics geoscience

Committers

Last synced: 4 months ago

All Time
  • Total Commits: 454
  • Total Committers: 17
  • Avg Commits per committer: 26.706
  • Development Distribution Score (DDS): 0.134
Past Year
  • Commits: 21
  • Committers: 1
  • Avg Commits per committer: 21.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Asitha Senanayake a****a@y****m 393
Edd Lewis e****w@b****k 19
Roger Chandler r****r@k****m 12
Tony Daly t****y@a****k 6
Phil Wade P****e@d****m 4
John A Stevenson j****v@b****k 3
Jostein Leira 9****l@u****m 3
Pete Morgan -****l 3
Jostein Leira j****n@l****t 2
Neil Chadwick 8****g@u****m 2
Alexandru Ifrim a****m@g****m 1
Bane Sullivan b****n@g****m 1
Jed Brown j****d@j****g 1
Jostein Leira j****a@c****m 1
Pete 'mash# Morgan p****n@g****m 1
banesullivan b****n@k****m 1
koalageo e****5@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 5
conda-forge.org: python-ags4
  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Forks count: 41.0%
Average: 46.1%
Stargazers count: 51.3%
Last synced: 4 months ago

Dependencies

poetry.lock pypi
  • atomicwrites 1.4.0 develop
  • attrs 20.3.0 develop
  • importlib-metadata 3.4.0 develop
  • more-itertools 8.7.0 develop
  • packaging 20.9 develop
  • pluggy 0.13.1 develop
  • py 1.10.0 develop
  • pyparsing 2.4.7 develop
  • pytest 5.4.3 develop
  • toml 0.10.2 develop
  • wcwidth 0.2.5 develop
  • zipp 3.4.0 develop
  • click 7.1.2
  • colorama 0.4.4
  • commonmark 0.9.1
  • defusedxml 0.6.0
  • et-xmlfile 1.0.1
  • jdcal 1.4.1
  • numpy 1.20.1
  • openpyxl 3.0.6
  • pandas 1.1.5
  • pygments 2.8.0
  • python-dateutil 2.8.1
  • pytz 2021.1
  • rich 9.11.0
  • six 1.15.0
  • typing-extensions 3.7.4.3
pyproject.toml pypi
  • pytest ^5.2 develop
  • toml ^0.10 develop
  • click >=7.0, <9.0
  • defusedxml >=0.6, <0.8
  • openpyxl ^3.0
  • pandas ^1.0
  • python ^3.7
  • rich >=9.0, <13.0