Skip to main content

A library to read and write AGS4 files using Pandas DataFrames

Project description

NOTE - this repo has been ported from (https://github.com/asitha-sena/python-ags4) which is now read-only


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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-AGS4-0.3.6.tar.gz (151.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_AGS4-0.3.6-py3-none-any.whl (157.2 kB view details)

Uploaded Python 3

File details

Details for the file python-AGS4-0.3.6.tar.gz.

File metadata

  • Download URL: python-AGS4-0.3.6.tar.gz
  • Upload date:
  • Size: 151.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.5 Linux/5.8.0-59-generic

File hashes

Hashes for python-AGS4-0.3.6.tar.gz
Algorithm Hash digest
SHA256 8f0ec45bcd100bc7db3d650c3db68601d611d1dfddb2a21cad3db6c279c15e4f
MD5 3e72e898e23c6e75b47fc6a573b41df8
BLAKE2b-256 982f05b1c058b1980d7966b2072453a9b2fccfea75f4318b78886779efd06e72

See more details on using hashes here.

File details

Details for the file python_AGS4-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: python_AGS4-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 157.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.5 Linux/5.8.0-59-generic

File hashes

Hashes for python_AGS4-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5542365cb4d39dae4f73d6c180ad214f900bd9470e95cc24e45131449bd392a0
MD5 875d5f7fd488956de2169a271611775f
BLAKE2b-256 44f9e9405b4db34c10b4fb8b65521b0e01d6172aff982971fc4a2ac848b76416

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page