Skip to main content

RecarrayTools

Some simple tools for managing numpy.recarray objects

Installation

Install via pip:

pip3 install --user RecarrayTools

Or this repo:

#clone the repo
git clone https://github.com/mattkjames7/RecarrayTools
cd RecarrayTools

#either use a wheel
python3 setup.py bdist_wheel
pip3 install --user dist/RecarrayTools-0.0.3-py3-none-any.whl

#or just install directly
python3 setup.py install

Usage

This module contains a small number of routines...

SaveRecarray()

This will save a record array to a binary file - note that the dtype of the record array shouldn't be too exotic (object arrays would not work - use pickle for those).

import numpy as np
import RecarrayTools as RT

#create some recarray
dtype = [('a','int32'),('b','float64',(6,))]
arr = np.recarray(10,dtype=dtype)

#fill it
arr.a = blah #shape (10,)
arr.b = stuff #shape (10,6)

#save it
RT.SaveRecarray(arr,'path/to/file.name',Progress=True)

The file format used here is simple:

The first 4 bytes correspond to a 32-bit integer containing the size of the recarray (i.e. arr.size).

Then each field arr.dtype.names is stored contiguously as whatever dtype it was assigned with, one field at a time.

The file created in the above example would be formatted in the following way:

Bytes 0-3 : 32-bit integer - total length of the recarray

Bytes 4-43 : Array of 32-bit integers, length 10 (arr.a)

Bytes 44-523: Array of 64-bit floating points, shape (10,6), length 60

EOF

ReadRecarray()

This will read in the files created by SaveRecarray(), e.g.

dtype = [('a','int32'),('b','float64',(6,))]
fname = 'path/to/file.name'
arr = RT.ReadRecarray(fname,dtype)

ReduceRecarray()

This reduces the number of fields in a recarray object, e.g.:

#initial object with fields 'a', 'b', 'c' and 'd'
dtype = [('a','int32'),('b','float64',(6,)),('c','int64'),('d','float64')]
obj0 = np.recarray(10,dtype=dtype)

#new object with just fields 'a' and 'c'
obj1 = RT.ReduceRecarray(obj0,['a','c'])

JoinRecarray()

Append two recarrays with identical dtypes:

C = RT.JoinRecarray(A,B)

AppendFields()

Append some extra fields to a recarray:

#some initial recarray
A = np.recarray(n,dtype=dtype)

#new fields for the array
x = np.arange(n)
y = x**2

#add them
B = RT.AppendFields(A,[('x','float32'),('y','float32')],(x,y))
#B now has fields B.x and B.y

InterpRecarrayFields()

Interpolate fields within a recarray:

#a would be the initial recarray, b would be the new recarray
#RefField = name of field to interpolate over
#InterpFields = list of names of fields to interpolate
b = RT.InterpRecarrayFields(a,b,RefField='x',InterpFields=['a','b','c','d','x'])

Metadata

Release files for RecarrayTools 0.1.1

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

Built distribution (wheel)

Table of built distributions (wheels) for RecarrayTools 0.1.1
File Interpreter ABI Platform
RecarrayTools-0.1.1-py3-none-any.whl Python 3 none any Details

Release files / RecarrayTools-0.1.1-py3-none-any.whl

Download URL RecarrayTools-0.1.1-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4ea81f402228cde62cdd876248138876764b637e65782a991c5aa9372525df5
BLAKE2b-256 checksum
How to use checksums
939832b03a474f2aebeeb9794dcb8e79ac689c0dee7aef4fd6b85c349f9932b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

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