Skip to main content

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

Juypter Notebook

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

See here

Installation

pip install python-ags4

Code Examples

first import the module

from python_ags4 import AGS4

Import data from an AG4 file:

tables, headings = AGS4.AGS4_to_dataframe('/home/asitha/Projects/python-AGS4/tests/test_data.ags')
  • 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

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.

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

The AGS4.convert_to_numeric() function automatically converts all columns in the input DataFrame with the 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:

AGS4.dataframe_to_AGS4(tables, headings, '/home/asitha/Documents/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.

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.)

Command Line Interface

A cli tool was added in version 0.2.0. It should be available from the terminal (or on the Anaconda Powershell prompt in Windows) after running python pip install python-ags4>=0.2.0

It does not yet have the full functionality of the library, but it does provide a quick and easy way to convert .ags files to Excel spreadsheets (.xlsx) and back. 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.)

asciicast

A checking tool is available as of version 0.3.0 and it can be used to make sure that the file conforms to the AGS4 rules. The tool has been tested in both bash and Powershell.

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 funtionality to plot and visualize the data.

from pandasgui import show

tables, headings = AGS4.AGS4_to_dataframe('/home/asitha/Projects/python-AGS4/tests/test_data.ags')
gui = show(**tables)

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

updated_tables = gui.get_dataframes()

AGS4.dataframe_to_AGS4(updated_tables, headings, '/home/asitha/Documents/output.ags')

Implementations

This library has been used to create

Metadata

Release files for python-ags4 0.3.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-ags4 0.3.7
File Size Uploaded
python-AGS4-0.3.7.tar.gz 155.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-ags4 0.3.7
File Interpreter ABI Platform
python_AGS4-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 315.5 kB

Release files / python-AGS4-0.3.7.tar.gz

Download URL python-AGS4-0.3.7.tar.gz
Size 155.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1a7cc996688a12597dc17d96d412c3bc1b0f89cd902534d2a9550da3703c9a24
BLAKE2b-256 checksum
How to use checksums
0b386c1789f7bba7e390b1d740b99606ed2d73baeeb685ade0950972faff6881
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.8.5 Linux/5.11.0-40-generic

Release files / python_AGS4-0.3.7-py3-none-any.whl

Download URL python_AGS4-0.3.7-py3-none-any.whl
Size 160.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8febf69eea60925f694dcd22c66860cf467de9cffdc616bf36c30c11290559a
BLAKE2b-256 checksum
How to use checksums
10587ce710af19d0c4f11c49dba8ab99ec6e7f5b171e229ee6fa5e0d5d735d61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.8.5 Linux/5.11.0-40-generic

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

This release

0.3.7 This release

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page