DummyArray¶
Represents a single array (variable or coordinate) with metadata.
Overview¶
DummyArray is used for both coordinates and variables in a DummyDataset. Each array contains:
- Dimensions - List of dimension names
- Attributes - Metadata dictionary
- Data - Optional numpy array
- Encoding - Encoding parameters (dtype, chunks, compression)
Key Features¶
- Automatic dimension inference from data shape
- xarray-compatible attribute assignment
- History tracking (if enabled)
- Rich repr for interactive exploration
Usage¶
from dummyxarray import DummyArray
import numpy as np
# Create array with dimensions
arr = DummyArray(dims=["time", "lat", "lon"])
# Set attributes
arr.assign_attrs(
standard_name="air_temperature",
units="K",
long_name="Air Temperature"
)
# Add data
arr.data = np.random.rand(10, 64, 128)
# Set encoding
arr.encoding = {
"dtype": "float32",
"chunks": (5, 32, 64),
"compressor": "zstd"
}
API Reference¶
Represents a single array (variable or coordinate) with metadata.
Source code in src/dummyxarray/core.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
__init__ ¶
Initialize a DummyArray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dims
|
list of str
|
List of dimension names |
None
|
attrs
|
dict
|
Metadata attributes |
None
|
data
|
array - like
|
Data array (numpy array or list) |
None
|
encoding
|
dict
|
Encoding parameters (dtype, chunks, compressor, fill_value, etc.) |
None
|
_record_history
|
bool
|
Whether to record operation history (default: True) |
True
|
Source code in src/dummyxarray/core.py
__repr__ ¶
Return a string representation of the DummyArray.
Source code in src/dummyxarray/core.py
infer_dims_from_data ¶
Infer dimension names and sizes from data shape.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary mapping dimension names to sizes |
Source code in src/dummyxarray/core.py
get_history ¶
Get the operation history for this array.
Returns:
| Type | Description |
|---|---|
list of dict
|
List of operations |
Examples:
>>> arr = DummyArray(dims=["time"], attrs={"units": "days"})
>>> arr.get_history()
[{'func': '__init__', 'args': {'dims': ['time'], 'attrs': {'units': 'days'}}}]
Source code in src/dummyxarray/core.py
replay_history ¶
Replay a sequence of operations to recreate an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
history
|
list of dict
|
History to replay. If None, uses self.get_history() |
None
|
Returns:
| Type | Description |
|---|---|
DummyArray
|
New array with operations replayed |
Source code in src/dummyxarray/core.py
assign_attrs ¶
Assign new attributes to this array (xarray-compatible API).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Attributes to assign |
{}
|
Returns:
| Type | Description |
|---|---|
self
|
Returns self for method chaining |
Examples:
Source code in src/dummyxarray/core.py
to_dict ¶
Export structure (without data) for serialization.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary representation |