Skip to main content

Tool to easily convert numpy arrays into latex tables with astropy units support.

Project description

LaTab

Utility to help convert numpy arrays to a LateX table. The main goal is to provide a code snippet with proper number and unit formatting, with a basic table layout. Formatting of the table itself is expected to be done manually by the user in the LateX document, but simpler features might be added in later versions if the need arises.

Examples

Imports and sample data

import numpy as np
from astropy import units
from latab import DataColumn, Table, SerialNumberColumn, EmptyColumn, FloatFormatter

array1 = np.array([13.35000606, 0.76642346, 1.42476496, 9.27577478, 3.83978828,
                   1.88922311, 8.46868664, 3.6269277, 2.86984472, 4.13375383])
array2 = np.array([1.8131508, 5.3586463, 5.6288616, 7.4245393, 8.1266426, 4.5811065,
                   8.7617888, 9.972409, 9.2422739, 4.1967336]) * units.g / units.cm**3
array3 = np.array([9.47738782e+20, 9.06469621e+20, 2.50771562e+20, 8.85737743e+20, 7.04538193e+20,
                   8.90478371e+20, 3.58848823e+18, 6.37444615e+20, 2.72502714e+19, 8.95868100e+20]) * units.kg
errors = np.array([0.034574, 0.072827, 0.04782, 0.098236, 0.018896, 0.071311, 0.065703, 0.080372,
                   0.078894, 0.072819]) * units.g / units.cm**3

Example using explicit definition

col1 = SerialNumberColumn("Planet", 10)
col2 = DataColumn("Semi-major Axis", array1).fixError(0.005, 3).unit("AU")
col3 = DataColumn("$\\varrho$", array2, formatter=FloatFormatter(2, 0)).absoluteError(errors)
col4 = DataColumn("Mass", array3).relativeError(0.05)
col5 = EmptyColumn("Note", 10)

table = Table([col1, col2, col3, col4, col5], "Nobody expects the Spanish inquisition.")
table.print()

Example 1

Localized example with different decimal separator

col1 = SerialNumberColumn("Bolygó", 10)
col2 = DataColumn("Félnagytengely", array1).fixError(0.005, 3).unit("AU")
col3 = DataColumn("$\\varrho$", array2, formatter=FloatFormatter(2, 0)).absoluteError(errors)
col4 = DataColumn("Tömeg", array3).relativeError(0.05)
col5 = EmptyColumn("Megjegyzés", 10)

table = Table([col1, col2, col3, col4, col5], "Aprócska kalapocska, benne csacska macska mocska.")
table.print(separator=',')

Example 2

Example using the simple dictionary interface

There is a simple interface to create a table, but you are limited to the default Formatter with precision 3 and without errors:

Table.fromDictionary({
    "Semi-major Axis [AU]": array1,
    "$\\varrho$": array2,
    "Mass": array3,
}, "Tis but a scratch!").print()

Example 3

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

latab-1.0.0rc1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

latab-1.0.0rc1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file latab-1.0.0rc1.tar.gz.

File metadata

  • Download URL: latab-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for latab-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 e66dd61410bcdd9a32318768d3817fbcd5df0a455fef2fa6f27649a058011ef0
MD5 204165aede359e910a9b5fd94d65b285
BLAKE2b-256 f92e66fa6ec3164593fe1b93f853537fa02a6f309b90fd0593627405cce4e971

See more details on using hashes here.

File details

Details for the file latab-1.0.0rc1-py3-none-any.whl.

File metadata

  • Download URL: latab-1.0.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for latab-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 db401a89494f6e81577079b7aea721bafa67a4ecea6783efcaf031f1c17472f7
MD5 82388877cf56e2ad316a0f7d2c2f90f0
BLAKE2b-256 a5b2c6e06a322ce30e54c17adf8af31e3d67f28a458483279ddeb4e76d6e0737

See more details on using hashes here.

Supported by

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