A library to read and write AGS4 files using Pandas DataFrames
Project description
python-ags4
A library to read and write AGS4 files using Pandas DataFrames
Installation
pip install python-ags4
Introduction
python-ags4
is a library of functions that lets a user import AGS4 files to a collection of Pandas DataFrames. The data can be analyzed, manipulated, and updated using Pandas and then exported back to an AGS4 file.
Examples
Import 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.)
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:
(Note: The code should be run before closing the GUI window)
updated_tables = gui.get_dataframes()
AGS4.dataframe_to_AGS4(updated_tables, headings, '/home/asitha/Documents/output.ags')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-AGS4-0.1.7.tar.gz
.
File metadata
- Download URL: python-AGS4-0.1.7.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.6 Linux/5.4.0-53-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 484d2d074efea59727f81bcbc092c058b7351cba600cb63814e2282ff8226aed |
|
MD5 | b1a9a0d4b740f81ded1272f40c3fd797 |
|
BLAKE2b-256 | 09f84549ca63a564132306f70e8c92ddaa138b8041cd8833d525fffbb2f002e3 |
File details
Details for the file python_AGS4-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: python_AGS4-0.1.7-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.6 Linux/5.4.0-53-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf8b1a0c81efb19929725f9239db5767e3e455ae92826d0f0523e8c5b884856 |
|
MD5 | 2aa356dac90c340350a05fbc050c1119 |
|
BLAKE2b-256 | 7ca2d9c06725b1e908f8fed38bb0e169a47b8e1125379712e1b8e4e89e7cca72 |