Skip to main content

XBoolArray: A multidimensional boolean array with annotated dimensions and coordinates.

Project description

XBoolArray

A Python module providing a multidimensional boolean array with annotated dimensions and coordinates.

Overview

XBoolArray is a versatile class that allows you to create and manipulate multidimensional boolean arrays with named dimensions and coordinates. Built on top of xarray and numpy, it makes it easier to work with complex boolean data structures.

Key Features

  • Named Dimensions: Every axis in the array has a meaningful name
  • Dynamic Expansion: Dimensions and coordinates can be added dynamically at any time
  • Flexible Coordinate Selection: Select data by coordinate names rather than numeric indices
  • Boolean Operations: Designed specifically for boolean data with appropriate methods
  • Dimension Reduction: Sum over specified dimensions to analyze data patterns
  • Intuitive API: Simple interface for adding data, selecting slices, and performing operations

Installation

pip install xboolarray

Dependencies

  • numpy
  • xarray

Usage

Basic Usage

from xboolarray import XBoolArray

# Initialize with some axis names
xboolarray = XBoolArray(["axis1", "axis2"])

# Add data with existing dimensions
xboolarray.add_data({"axis1": "coord1_1", "axis2": "coord2_1"})

# Add data with new coordinates
xboolarray.add_data({"axis1": "coord1_2", "axis2": ["coord2_2", "coord2_3"]})

# Print the current state of the XBoolArray
print(xboolarray)

Dynamic Dimension Addition

# Add data with a new dimension
xboolarray.add_data({"axis1": "coord1_3", "axis2": "coord2_3", "axis3": "coord3_1"})

# Add more data across multiple dimensions
xboolarray.add_data({
    "axis1": "coord1_4", 
    "axis2": ["coord2_1", "coord2_2"], 
    "axis3": ["coord3_1", "coord3_2"]
})

Selecting Slices

# Select a specific slice of the array
slice_result = xboolarray.select({
    "axis1": ["coord1_3", "coord1_4"], 
    "axis2": "coord2_1"
})
print(slice_result)

Summing Over Dimensions

# Sum over one dimension
sum_result = xboolarray.sum("axis2")
print(sum_result)

# Sum over multiple dimensions
sum_result = xboolarray.sum(["axis2", "axis1"])
print(sum_result)

# Select and then sum
sum_selected = xboolarray.sum_selected({"axis1": "coord1_4"}, "axis3")
print(sum_selected)

Complete Example

from xboolarray import XBoolArray

# Initialize with some axis names
xboolarray = XBoolArray(["axis1", "axis2"])

# Add data with existing dimensions
xboolarray.add_data({"axis1": "coord1_1", "axis2": "coord2_1"})

# Add data with new coordinates
xboolarray.add_data({"axis1": "coord1_2", "axis2": ["coord2_2", "coord2_3"]})

# Add data with a new dimension
xboolarray.add_data({"axis1": "coord1_3", "axis2": "coord2_3", "axis3": "coord3_1"})

# Add more data
xboolarray.add_data({"axis1": "coord1_4", "axis2": ["coord2_1", "coord2_2"], "axis3": ["coord3_1", "coord3_2"]})

# Print the current state of the XBoolArray
print(xboolarray)

# Example of selecting a slice
print("\nSelecting axis1=['coord1_3', 'coord1_4'] and axis2='coord2_1':")
slice_result = xboolarray.select({"axis1": ["coord1_3", "coord1_4"], "axis2": "coord2_1"})
print(slice_result)

# Example of summing over one dimension
print("\nSum over 'axis2' dimension:")
sum_result = xboolarray.sum("axis2")
print(sum_result)

# Example of summing over multiple dimensions
print("\nSum over 'axis2' and 'axis1' dimensions:")
sum_result = xboolarray.sum(["axis2", "axis1"])
print(sum_result)

# Example of selecting and then summing
print("\nSelect axis1='coord1_4' then sum over 'axis3':")
sum_selected = xboolarray.sum_selected({"axis1": "coord1_4"}, "axis3")
print(sum_selected)

Use Cases

XBoolArray is particularly useful for:

  • Tracking combinations of features/properties in complex systems
  • Building truth tables with named dimensions
  • Managing boolean flags across multiple categories
  • Data filtering and selection based on multiple criteria
  • Sparse boolean representation of multidimensional data

API Reference

Constructor

  • XBoolArray(axis_names): Initialize with a list of axis names

Methods

  • add_data(coord_dict): Add data to the array using coordinates
  • select(selection): Select a slice of the array based on coordinates
  • sum(dims=None): Sum boolean values over specified dimensions
  • sum_selected(selection, dims=None): Select a slice and sum over dimensions
  • get_array(): Return the underlying xarray DataArray

Properties

  • shape: The shape of the underlying data array
  • dims: The dimension names of the array
  • coords: Dictionary of coordinates for each dimension

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

xboolarray-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

xboolarray-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file xboolarray-0.1.0.tar.gz.

File metadata

  • Download URL: xboolarray-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for xboolarray-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6de503871fd864135fef543b41f927fa1853254ca0fa2167baf4e5ded2a18e05
MD5 8a68d25a8bb4c636e003a021db12352a
BLAKE2b-256 77327971b244189096f1827723aa374a3edc47827a292d56ab90810d6a944a00

See more details on using hashes here.

Provenance

The following attestation bundles were made for xboolarray-0.1.0.tar.gz:

Publisher: build_and_publish_to_pypi.yml on alussana/xboolarray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xboolarray-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: xboolarray-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for xboolarray-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b52454ae7d5a055e9534e3305ecfe667ddafba34679eb8b6c08112ffc24b6a03
MD5 dba04e846cc6fe3c354a1fee0dbbe542
BLAKE2b-256 3c303545f220e40b360552df899f4c73e1d7c49a81759ef5f467a95263a6a15b

See more details on using hashes here.

Provenance

The following attestation bundles were made for xboolarray-0.1.0-py3-none-any.whl:

Publisher: build_and_publish_to_pypi.yml on alussana/xboolarray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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