Readers¶
Simulation data readers, the reader protocols, and the auto-detection
registry. The FieldDataset they return is documented under
Core Containers.
readers
¶
Simulation data readers and auto-detection registry.
ReaderBase
¶
Base class for readers that turn a run's files into FieldDataset.
Subclasses implement available_timesteps, read_timestep and
available_fields_mapping; everything else a Simulation may ask
for has a default here. The contract every reader honours:
read_timestepbuilds its dataset through_finish, the one place arrays become aFieldDataset. It stampsmetadata["step"]and, when the file records one,metadata["time"], and takes normalization, species, physics, frame and transforms from the mergedSimulationConfig, so asimulation.tomlreaches the data.- Arrays handed to
_finishare in code units on a co-located grid. Destaggering, when a reader gains it, happens before that call. available_fieldsis the sorted key set ofavailable_fields_mapping: readers list, they do not load.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim_config
|
SimulationConfig | None
|
Merged run configuration. A reader that only learns its grid
from each file ( |
None
|
Source code in src/pypic/readers/_base.py
18 19 20 21 22 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 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Source code in src/pypic/readers/_base.py
46 47 48 | |
available_fields(path, step)
¶
Sorted canonical field names at step, without loading arrays.
Source code in src/pypic/readers/_base.py
50 51 52 | |
available_auxiliary(path)
¶
Names of auxiliary datasets at path; none unless overridden.
Source code in src/pypic/readers/_base.py
54 55 56 | |
load_auxiliary(path, name)
¶
Load a named auxiliary dataset; raises unless overridden.
Source code in src/pypic/readers/_base.py
58 59 60 61 | |
AuxiliaryDataReader
¶
Bases: Protocol
Opt-in protocol for readers that provide auxiliary tabular data.
Readers implement this alongside SimulationReader to advertise
and load non-field data (conserved quantities, diagnostics, probes).
Source code in src/pypic/readers/_protocols.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
available_auxiliary(path)
¶
Return names of auxiliary datasets discoverable at path.
Source code in src/pypic/readers/_protocols.py
104 105 106 | |
load_auxiliary(path, name)
¶
Load a named auxiliary dataset from path.
Source code in src/pypic/readers/_protocols.py
108 109 110 | |
ParticleDataReader
¶
Bases: Protocol
Opt-in protocol for readers that provide particle data.
Readers implement this alongside SimulationReader to advertise
and load per-species particle arrays (position, velocity, weight)
plus scalar species charge/mass — see docs/schema.md § Per-particle
data columns.
Source code in src/pypic/readers/_protocols.py
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 | |
available_particle_steps(path)
¶
Return sorted timestep indices that have particle data.
Source code in src/pypic/readers/_protocols.py
42 43 44 | |
read_particles(path, step, species, *, columns=None)
¶
Load particle data for one species at one timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
species
|
int
|
Zero-based species index. |
required |
columns
|
Iterable[str] | None
|
Subset of |
None
|
Source code in src/pypic/readers/_protocols.py
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 | |
SimulationReader
¶
Bases: Protocol
Protocol for simulation-specific file readers.
Any class with read_timestep and available_timesteps methods
satisfies this protocol — no inheritance required.
Source code in src/pypic/readers/_protocols.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
read_timestep(path, step)
¶
Read field data for a single timestep.
Source code in src/pypic/readers/_protocols.py
23 24 25 | |
available_timesteps(path)
¶
Return sorted list of available timestep indices.
Source code in src/pypic/readers/_protocols.py
27 28 29 | |
ProbeResult
dataclass
¶
Result of a single reader's format probe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Reader name. |
required |
confidence
|
float
|
Confidence score in |
required |
error
|
str | None
|
Error message if the probe or factory raised, else |
None
|
Source code in src/pypic/readers/_registry.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
ReaderEntry
dataclass
¶
A registered reader with its format detector and factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Short identifier (e.g. |
required |
can_read_confidence
|
CanReadFunction
|
Returns a confidence score in |
required |
factory
|
ReaderFactory
|
Callable that opens a simulation directory. |
required |
Source code in src/pypic/readers/_registry.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
Simulation
¶
Ergonomic wrapper around a simulation reader, config, and path.
Returned by open_simulation. Provides direct access to config
properties and reads timesteps without repeating the data path.
Also unpacks as a (reader, config) tuple::
sim = open_simulation(path) # preferred
reader, config = open_simulation(path) # still works
Cross-model comparison workflow:
- Open both simulations via
open_simulation(). - Read matching timesteps from each.
- Regrid to a common grid via
align_gridswhen the two runs do not already share one. - Compare fields: use
in_si()for cross-model comparison (different normalizations make code units incomparable), or compare in code units for same-model parameter studies (identical normalization). Dimensionless quantities (beta, Mach number, entropy) need no conversion.
Known limitations: no automatic timestep alignment across simulations (different codes use different step numbering and output cadences).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
SimulationReader
|
The underlying reader instance. |
required |
config
|
SimulationConfig
|
Parsed simulation metadata. |
required |
path
|
Path
|
Data directory (remembered for |
required |
Examples:
>>> from unittest.mock import MagicMock
>>> r = MagicMock()
>>> r.available_timesteps.return_value = [0, 10]
>>> from pypic.containers import SimulationConfig
>>> from pypic.grid import GridInfo
>>> from pypic.coordinates.geometry import CARTESIAN
>>> from pypic.units import Normalization, SpeciesInfo
>>> cfg = SimulationConfig(
... model_name="test", model_type="PIC",
... grid=GridInfo(
... dimensions=(4,), spacing=(1.0,), origin=(0.0,),
... geometry=CARTESIAN,
... ),
... normalization=Normalization.identity(),
... species=(SpeciesInfo(name="e", charge=-1.0, mass=1.0),),
... )
>>> sim = Simulation(r, cfg, path="/tmp")
>>> sim.model_name
'test'
>>> sim.steps
[0, 10]
Source code in src/pypic/readers/_registry.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
reader
property
¶
The underlying reader instance.
config
property
¶
Full simulation configuration.
path
property
¶
Data directory.
run
property
¶
[run] provenance from the merged configuration.
Resolved once when the simulation is opened. A per-file /run/
group is attached per dataset instead, so
sim.read(step).metadata["run"] is the authoritative record for
a given timestep when the two disagree.
model_name
property
¶
Simulation code name (e.g. "iPIC3D").
model_type
property
¶
Model type (e.g. "PIC", "MHD").
grid
property
¶
Grid metadata.
normalization
property
¶
Unit normalization.
species
property
¶
Species definitions.
physics
property
¶
Physics parameters.
shrink_factor
property
¶
Domain shrink factor (1.0 when unscaled).
probe_results
property
¶
Auto-detection probe results, or None if reader was explicit.
steps
property
¶
Available timestep indices (cached after first access).
first_step
property
¶
First available timestep index.
last_step
property
¶
Last available timestep index.
auxiliary_names
property
¶
Names of available auxiliary datasets, or [] if unsupported.
particle_steps
property
¶
Timesteps with particle data, or [] if unsupported.
refresh_steps()
¶
Re-scan for available timesteps, clearing the cache.
Source code in src/pypic/readers/_registry.py
305 306 307 308 | |
read(step, *, fields=None, strict_fields=True, **kwargs)
¶
Read field data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int
|
Timestep index. |
required |
fields
|
Iterable[str] | None
|
When given, only these fields are read. Accepts canonical
names ( |
None
|
strict_fields
|
bool
|
When |
True
|
**kwargs
|
Any
|
Forwarded to readers that accept extra parameters
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If strict_fields is true (the default) and any requested field name yielded nothing. |
Source code in src/pypic/readers/_registry.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
available_fields(step)
¶
List canonical field names at step without loading arrays.
Uses the reader's lightweight probe when available (via
FieldListingReader);
otherwise falls back to a full read and extracts
field_names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted canonical field names. |
Source code in src/pypic/readers/_registry.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
available_fields_mapping(step)
¶
Map canonical field names to native (on-disk) names at step.
Uses the reader's lightweight probe when available; otherwise
falls back to available_fields with None for all
native names (native mapping unknown without reader support).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical name → native name, or |
Source code in src/pypic/readers/_registry.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
particles(step, species, *, columns=None)
¶
Load particle data for a species at a timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int
|
Timestep index. |
required |
species
|
int
|
Zero-based species index. |
required |
columns
|
Iterable[str] | None
|
Subset of |
None
|
Returns:
| Type | Description |
|---|---|
ParticleData
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the reader does not support particle data. |
UnknownFieldError
|
If columns names a column the reader does not recognize. |
Source code in src/pypic/readers/_registry.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
auxiliary(name)
¶
Load a named auxiliary dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Dataset name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
TabularData
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the reader does not support auxiliary data. |
Source code in src/pypic/readers/_registry.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
describe()
¶
Multi-line summary of the simulation (no I/O).
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/pypic/readers/_registry.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
__iter__()
¶
Support reader, config = open_simulation(path).
Source code in src/pypic/readers/_registry.py
627 628 629 630 | |
SimpleReader
¶
Bases: ReaderBase
Minimal HDF5 reader implementing the SimulationReader protocol.
Reads HDF5 files where field arrays live under a configurable group
(default "fields/"). Grid metadata is resolved in priority
order:
- HDF5
grid/group attributes (self-describing files). - Explicit grid parameter.
- Grid from config, if provided.
You only need to supply what the HDF5 files don't already contain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_pattern
|
str
|
Python format string with a |
'output_{step:06d}.h5'
|
field_map
|
dict[str, str] | None
|
Mapping from native HDF5 dataset names to canonical field
names (e.g. |
None
|
grid
|
GridInfo | None
|
Explicit grid metadata. Takes precedence over config but
is overridden by HDF5 |
None
|
normalization
|
Normalization | None
|
Unit normalization. Defaults to |
None
|
config
|
SimulationConfig | None
|
Full simulation configuration. Used as a fallback for grid, normalization, species, and physics when individual params are not given. |
None
|
fields_group
|
str
|
HDF5 group containing field datasets. Use |
'fields'
|
Examples:
>>> from pathlib import Path
>>> reader = SimpleReader(file_pattern="out_{step:04d}.h5")
>>> reader.file_pattern
'out_{step:04d}.h5'
Source code in src/pypic/readers/_simple.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
file_pattern
property
¶
The file naming pattern.
available_timesteps(path)
¶
Return sorted timestep indices found in path.
Scans for files matching file_pattern and extracts the
step number from each filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory to scan. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted step numbers. |
Source code in src/pypic/readers/_simple.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Opens the HDF5 file and lists dataset names in the fields
group, applying field_map if configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing the data files. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name. |
Source code in src/pypic/readers/_simple.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
read_timestep(path, step, *, fields=None)
¶
Read field data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing the data files. |
required |
step
|
int
|
Timestep index. |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the expected file does not exist (default I/O path). |
ValueError
|
If grid metadata is missing from both the file
and |
Source code in src/pypic/readers/_simple.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
BATSRUSConfig
dataclass
¶
Parsed BATSRUS PARAM.in configuration.
Source code in src/pypic/readers/batsrus/_config.py
22 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 | |
BATSRUSOutputFormat
¶
Bases: StrEnum
BATSRUS output file format.
Source code in src/pypic/readers/batsrus/__init__.py
41 42 43 44 45 46 | |
BATSRUSReader
¶
Bases: ReaderBase
Read BATSRUS simulation output in IDL or HDF5 format.
Supports three output formats:
- Per-cell IDL (
.h+*_pe*.idl): raw per-processor binary - Merged IDL (
.out/.outs): postprocessed snapshot files - HDF5 BATL (
.batl): block-structured HDF5
AMR grids are automatically regridded to the finest resolution.
Source code in src/pypic/readers/batsrus/_reader.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
available_timesteps(path)
¶
Return sorted list of available timestep indices.
Source code in src/pypic/readers/batsrus/_reader.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Parses file headers or HDF5 metadata without loading arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing the simulation output. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name. |
Source code in src/pypic/readers/batsrus/_reader.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
read_timestep(path, step, *, fields=None, target_resolution=None)
¶
Read field data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing the simulation output. |
required |
step
|
int
|
Timestep index. |
required |
fields
|
Iterable[str] | None
|
When given, only include these canonical field names. |
None
|
target_resolution
|
float | None
|
Target cell size in code units for AMR regridding. When
|
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names, optionally converted to SI. |
Source code in src/pypic/readers/batsrus/_reader.py
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 | |
ConservedQuantities
dataclass
¶
Time series of conserved quantities from an iPIC3D run.
Two output formats exist:
Format A (Roman numeral header) — single file from phdf5/shdf5 runs. Columns: cycle, electric energy (total, x, y, z), magnetic energy (total, x, y, z), kinetic energy, total energy, energy variation, momentum.
Format B (comment header) — per-restart-segment files from H5hut runs. Columns: cycle, total energy, energy variation, electric energy, local B energy, kinetic energy, momentum, total B energy, internal B energy, KE removed, E removed, then per-species (npart, charge, KE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
FloatArray
|
Cycle numbers (int-valued but stored as float for array uniformity). |
required |
total_energy
|
FloatArray
|
Total energy at each cycle. |
required |
electric_energy
|
FloatArray
|
Total electric field energy. |
required |
magnetic_energy
|
FloatArray
|
Total magnetic field energy. |
required |
kinetic_energy
|
FloatArray
|
Total kinetic energy (all species). |
required |
momentum
|
FloatArray
|
Total momentum magnitude. |
required |
species_npart
|
tuple[FloatArray, ...]
|
Number of particles per species at each cycle. |
required |
species_charge
|
tuple[FloatArray, ...]
|
Total charge per species. |
required |
species_kinetic_energy
|
tuple[FloatArray, ...]
|
Kinetic energy per species. |
required |
Source code in src/pypic/readers/ipic3d/_conserved.py
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 | |
IPic3DConfig
dataclass
¶
Native iPIC3D simulation parameters.
Stores the raw values from an .inp file or settings.hdf,
before any conversion to the canonical pypic schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nxc
|
int
|
Number of cells along each axis. |
required |
nyc
|
int
|
Number of cells along each axis. |
required |
nzc
|
int
|
Number of cells along each axis. |
required |
lx
|
float
|
Domain size along each axis (code units). |
required |
ly
|
float
|
Domain size along each axis (code units). |
required |
lz
|
float
|
Domain size along each axis (code units). |
required |
dx
|
float
|
Cell spacing (code units). Computed as |
required |
dy
|
float
|
Cell spacing (code units). Computed as |
required |
dz
|
float
|
Cell spacing (code units). Computed as |
required |
dt
|
float
|
Timestep in code units. |
required |
xlen
|
int
|
MPI topology (processors per axis). |
required |
ylen
|
int
|
MPI topology (processors per axis). |
required |
zlen
|
int
|
MPI topology (processors per axis). |
required |
c
|
float
|
Speed of light in code units. |
required |
th
|
float
|
Implicitness parameter (0.5 = Crank-Nicolson). |
required |
b0
|
tuple[float, float, float]
|
Background magnetic field |
required |
ns
|
int
|
Number of particle species. |
required |
qom
|
tuple[float, ...]
|
Charge-to-mass ratio per species. |
required |
uth
|
tuple[float, ...]
|
Thermal velocities per species (x, y, z components). |
required |
vth
|
tuple[float, ...]
|
Thermal velocities per species (x, y, z components). |
required |
wth
|
tuple[float, ...]
|
Thermal velocities per species (x, y, z components). |
required |
u0
|
tuple[float, ...]
|
Drift velocities per species (x, y, z components). |
required |
v0
|
tuple[float, ...]
|
Drift velocities per species (x, y, z components). |
required |
w0
|
tuple[float, ...]
|
Drift velocities per species (x, y, z components). |
required |
rho_init
|
tuple[float, ...]
|
Initial number density per species (code units). |
required |
npcelx
|
tuple[int, ...]
|
Particles per cell per species (x, y, z). |
required |
npcely
|
tuple[int, ...]
|
Particles per cell per species (x, y, z). |
required |
npcelz
|
tuple[int, ...]
|
Particles per cell per species (x, y, z). |
required |
periodic_x
|
bool
|
Periodicity per axis. |
required |
periodic_y
|
bool
|
Periodicity per axis. |
required |
periodic_z
|
bool
|
Periodicity per axis. |
required |
write_method
|
str
|
Output format ( |
required |
field_output_cycle
|
int
|
Field output frequency (cycles between dumps). |
required |
field_output_tag
|
str
|
Space-separated tags controlling which fields are written. |
required |
particles_output_cycle
|
int
|
Particle output frequency (cycles between dumps; <=0 = disabled). |
required |
case
|
str
|
Simulation case identifier. |
required |
simulation_name
|
str
|
Human-readable simulation name. |
required |
Source code in src/pypic/readers/ipic3d/_config.py
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 | |
IPic3DH5hutReader
¶
Bases: IPic3DReaderBase
Read iPIC3D H5hut field output.
H5hut files store all fields for a single timestep in one file
named {SimulationName}-Fields_{cycle:06d}.h5. Arrays are stored
in ZYX order ((nzc+1, nyc+1, nxc+1)) and must be transposed.
H5hut stores all moment quantities (density, current, pressure) divided by 4π (Gaussian convention). The reader applies the 4π correction to density, current, and pressure, matching the phdf5/shdf5 readers. Electromagnetic fields are unaffected.
Unique to this reader: the single-file-per-timestep layout, ZYX
transpose, H5hut-specific field naming (uppercase axis letters
in _PRESSURE_COMPONENT_MAP), and passthrough of unknown native
fields. Field-name mapping for everything else, the Gaussian
conversions, pressure-tensor mass correction, and config
translation live in pypic.readers.ipic3d._field_map and
pypic.readers.ipic3d._config, shared with the parallel and
serial readers.
Source code in src/pypic/readers/ipic3d/_h5hut.py
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 | |
available_timesteps(path)
¶
Sorted cycle numbers, from the *-Fields_*.h5 files under path.
Source code in src/pypic/readers/ipic3d/_h5hut.py
76 77 78 79 80 81 82 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Opens the H5hut fields file and inspects Step#0/Block/
keys. Unknown native keys pass through with the same name as
both key and value, matching read_timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep (cycle) index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name, |
Source code in src/pypic/readers/ipic3d/_h5hut.py
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 | |
read_timestep(path, step, *, fields=None)
¶
Read field and moment data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Cycle number (e.g. 202500). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. Dependencies (per-species fields needed for totals) are expanded automatically and excluded from the result. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names. Density, current, and pressure tensor all corrected by 4π (Gaussian→SI-rationalized). |
Source code in src/pypic/readers/ipic3d/_h5hut.py
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 | |
IPic3DParallelReader
¶
Bases: IPic3DReaderBase
Read iPIC3D parallel HDF5 (phdf5) output.
Each timestep is stored in separate Fields_XXXXX/ and
Moments_XXXXX/ directories containing one .h5 file per
field group.
Unique to this reader: scanning timestep directories and the
one-file-per-moment layout. Field-name mapping, Gaussian-CGS unit
conversions, pressure-tensor mass correction, and config
translation live in pypic.readers.ipic3d._field_map and
pypic.readers.ipic3d._config, shared with the serial and
H5hut readers.
Source code in src/pypic/readers/ipic3d/_parallel.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
available_timesteps(path)
¶
Sorted timestep numbers, from the Fields_XXXXX directories.
Source code in src/pypic/readers/ipic3d/_parallel.py
107 108 109 110 111 112 113 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Probes HDF5 files in the Fields_XXXXX/ and
Moments_XXXXX/ directories without loading arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name, |
Source code in src/pypic/readers/ipic3d/_parallel.py
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 | |
read_timestep(path, step, *, fields=None)
¶
Read field and moment data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index (e.g. 0, 10, 20). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names and 4π corrections applied. |
Source code in src/pypic/readers/ipic3d/_parallel.py
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 | |
available_particle_steps(path)
¶
Return sorted timestep indices that have particle data.
Source code in src/pypic/readers/ipic3d/_parallel.py
221 222 223 | |
read_particles(path, step, species, *, columns=None)
¶
Load particle data for one species at one timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
species
|
int
|
Zero-based species index. |
required |
columns
|
Iterable[str] | None
|
Subset of |
None
|
Returns:
| Type | Description |
|---|---|
ParticleData
|
|
Source code in src/pypic/readers/ipic3d/_parallel.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
IPic3DSerialReader
¶
Bases: IPic3DReaderBase
Read iPIC3D serial HDF5 (shdf5) output.
Each MPI process writes to its own procN.hdf file containing all
timesteps. This reader assembles the global arrays from the per-process
local patches.
Unique to this reader: the per-process patch reassembly. Field-name
mapping, Gaussian-CGS unit conversions, pressure-tensor mass
correction, and config translation live in
pypic.readers.ipic3d._field_map and
pypic.readers.ipic3d._config, shared with the parallel and
H5hut readers.
Source code in src/pypic/readers/ipic3d/_serial.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
available_timesteps(path)
¶
Sorted timestep numbers, from the cycle keys in proc0.hdf.
Source code in src/pypic/readers/ipic3d/_serial.py
48 49 50 51 52 53 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Opens proc0.hdf and inspects HDF5 group keys without
loading array data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name, |
Source code in src/pypic/readers/ipic3d/_serial.py
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 | |
read_timestep(path, step, *, fields=None)
¶
Read field and moment data for a single timestep.
Assembles global arrays from per-process files, applies 4π correction to densities and currents, and computes totals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index (e.g. 0, 10, 20). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names and 4π corrections applied. |
Source code in src/pypic/readers/ipic3d/_serial.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
OpenGGCMGrid
dataclass
¶
Non-uniform grid definition from an OpenGGCM grid file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nx
|
int
|
Number of grid points along each axis. |
required |
ny
|
int
|
Number of grid points along each axis. |
required |
nz
|
int
|
Number of grid points along each axis. |
required |
x
|
FloatArray
|
X-coordinates (non-uniform), shape |
required |
y
|
FloatArray
|
Y-coordinates (non-uniform), shape |
required |
z
|
FloatArray
|
Z-coordinates (non-uniform), shape |
required |
stagger
|
MappingProxyType[str, tuple[FloatArray, FloatArray, FloatArray]]
|
Staggered grid positions keyed by field component ( |
required |
metadata
|
MappingProxyType[str, str]
|
Header metadata ( |
required |
Source code in src/pypic/readers/openggcm/_grid.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
OpenGGCMReader
¶
Bases: ReaderBase
Read OpenGGCM .3df field output on a non-uniform grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
OpenGGCMGrid
|
Parsed grid definition. |
required |
prefix
|
str
|
Filename prefix (e.g. |
required |
sim_config
|
SimulationConfig
|
Merged run configuration. Its normalization converts the SI values on disk to code units; identity leaves them in SI. |
required |
Source code in src/pypic/readers/openggcm/_reader.py
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 | |
grid
property
¶
The OpenGGCM non-uniform grid.
available_timesteps(path)
¶
Return sorted list of available timestep indices.
Scans for {prefix}.3df.* files under path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing .3df files. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted timestep indices. |
Source code in src/pypic/readers/openggcm/_reader.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native .3df record names at step.
Scans the file's FIELD-3D-1 markers without decoding any
WRN2 payload.
Source code in src/pypic/readers/openggcm/_reader.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
read_timestep(path, step, *, fields=None)
¶
Read fields for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing .3df files. |
required |
step
|
int
|
Timestep index (e.g. 6300). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. Skips WRN2 decompression for unwanted native fields. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names in SI (or normalized) units.
|
Source code in src/pypic/readers/openggcm/_reader.py
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 | |
merge_simulation_toml(sim_dir, base)
¶
Merge simulation.toml overrides into base if present.
Every SimulationConfig field outside READER_OWNED_FIELDS is taken
from the TOML when it is set there (normalization, frame,
transforms, run, probes, ...); metadata is merged with
TOML keys winning on conflict. Reader-owned fields come from base
unchanged, so the native config stays authoritative for the grid and
species the data was actually produced with.
Returns base unmodified if sim_dir is None or has no
simulation.toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim_dir
|
Path | None
|
Directory to scan for |
required |
base
|
SimulationConfig
|
Reader-built SimulationConfig to enrich. |
required |
Returns:
| Type | Description |
|---|---|
SimulationConfig
|
New |
Source code in src/pypic/readers/_config_helpers.py
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 | |
score_signals(path, signals)
¶
Sum weights of glob patterns that match entries under path.
For each (pattern, weight) pair the helper checks whether
path.glob(pattern) yields at least one entry and, if so, adds
weight to the running score. Intended for reader probe functions
(can_read_confidence) so the glob-and-accumulate boilerplate does
not get duplicated across every reader.
Signals that require reading file contents, filtering matches by regex, or distinguishing files from directories should be evaluated by the caller and added on top of the returned score. The caller is responsible for any conditional logic beyond "pattern present → add weight".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory to scan. Non-directories return |
required |
signals
|
Sequence[tuple[str, float]]
|
Pairs of |
required |
Returns:
| Type | Description |
|---|---|
float
|
Sum of matching weights, clamped to |
Examples:
>>> import tempfile
>>> from pathlib import Path
>>> with tempfile.TemporaryDirectory() as d:
... p = Path(d)
... (p / "config.toml").touch()
... (p / "data.h5").touch()
... score_signals(p, [("*.toml", 0.5), ("*.h5", 0.3), ("*.nc", 0.9)])
0.8
Source code in src/pypic/readers/_protocols.py
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 | |
supports_selective_read(reader)
¶
Check whether reader accepts a fields keyword on read_timestep.
Inspects the method signature once at dispatch time. This is more
reliable than @runtime_checkable protocols (which only check
method names, not parameter signatures) and clearer than calling
inspect.signature inline at the call site.
Examples:
>>> class Selective:
... def read_timestep(self, path, step, *, fields=None): ...
... def available_timesteps(self, path): return []
>>> supports_selective_read(Selective())
True
>>> class Basic:
... def read_timestep(self, path, step): ...
... def available_timesteps(self, path): return []
>>> supports_selective_read(Basic())
False
Source code in src/pypic/readers/_protocols.py
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 | |
open_simulation(path, *, reader=None, physical_extent=None, physical_extent_unit='m', **kwargs)
¶
Open a simulation directory, auto-detecting the format.
Returns a Simulation object that remembers the data path::
sim = open_simulation(path)
sim.model_name # "iPIC3D"
sim.grid.dimensions # (128, 64, 64)
sim.steps # [0, 100, 200, ...]
ds = sim.read(step=100)
Also unpacks as a (reader, config) tuple::
reader, config = open_simulation(path)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Simulation output directory (or file). |
required |
reader
|
str | ReaderFactory | None
|
How to select the reader:
|
None
|
physical_extent
|
tuple[float, ...] | None
|
Physical domain size per axis in physical_extent_unit.
When provided, auto-computes the spatial scale factor for
frame transforms. Overrides |
None
|
physical_extent_unit
|
str
|
Length unit for physical_extent (default |
'm'
|
**kwargs
|
Any
|
Forwarded to the reader factory (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
Simulation
|
Wraps the reader, config, and path. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If reader is a string not found in the registry. |
FileNotFoundError
|
If auto-detection finds no matching reader. |
ExceptionGroup
|
If every candidate reader was tried and each one failed — the usual outcome for a corrupt or ambiguous directory. The group carries one sub-exception per candidate. |
PypicError
|
Unwrapped, aborting the candidate loop, when a reader refuses the
data deliberately rather than failing to parse it — a
|
Source code in src/pypic/readers/_registry.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
register_reader(name, can_read_confidence, factory)
¶
Register a reader for auto-detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Short identifier (e.g. |
required |
can_read_confidence
|
CanReadFunction
|
Returns confidence in |
required |
factory
|
ReaderFactory
|
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is already registered; call |
Source code in src/pypic/readers/_registry.py
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 | |
registered_readers()
¶
Return a read-only view of all registered readers.
Source code in src/pypic/readers/_registry.py
152 153 154 | |
unregister_reader(name)
¶
Remove a reader from the registry.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not registered. |
Source code in src/pypic/readers/_registry.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
open_simple(path, *, file_pattern='output_{step:06d}.h5', field_map=None, grid=None, normalization=None, config=None, config_path=None, fields_group='fields')
¶
Open a directory of HDF5 files.
Returns a Simulation object::
sim = open_simple(path, field_map={...})
sim.steps # [0, 100, 200]
ds = sim.read(step=100)
Metadata resolution (each level overrides the next):
simulation.tomlfrom config_path or in path.- HDF5
grid/attributes in the first matching file. - Explicit grid / normalization parameters.
- Explicit config parameter.
For most cases you only need to supply what the files lack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing HDF5 output files. |
required |
file_pattern
|
str
|
Filename pattern with |
'output_{step:06d}.h5'
|
field_map
|
dict[str, str] | None
|
Native-to-canonical field name mapping. |
None
|
grid
|
GridInfo | None
|
Explicit grid metadata (when HDF5 files lack it). |
None
|
normalization
|
Normalization | None
|
Unit normalization (defaults to identity). |
None
|
config
|
SimulationConfig | None
|
Full simulation configuration. When provided, grid and normalization are ignored. |
None
|
config_path
|
Path | None
|
Explicit path to a |
None
|
fields_group
|
str
|
HDF5 group name containing field datasets. |
'fields'
|
Returns:
| Type | Description |
|---|---|
Simulation
|
Wraps the reader, config, and path. |
Source code in src/pypic/readers/_simple.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
open_batsrus(path, *, config_path=None)
¶
Auto-detect BATSRUS output format and return a reader.
Detection order:
1. .batl files → HDF5 BATL format
2. .h + *_pe*.idl files → per-cell IDL binary
3. .out / .outs files → merged IDL
Prefers 3D data over 2D slices when both are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing BATSRUS output files. |
required |
config_path
|
Path | None
|
Explicit path to a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
reader |
SimulationReader
|
A |
config |
SimulationConfig
|
Simulation configuration parsed from |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no recognizable BATSRUS output is found. |
Source code in src/pypic/readers/batsrus/__init__.py
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 | |
parse_param_in(path)
¶
Parse a BATSRUS PARAM.in file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BATSRUSConfig
|
Frozen dataclass with extracted configuration. |
Source code in src/pypic/readers/batsrus/_config.py
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 223 224 225 226 227 228 229 230 231 | |
load_config(path)
¶
Parse a simulation.toml file into a SimulationConfig.
Validates the file against the v2.0 schema
(pypic.schema) and builds the internal SimulationConfig
from the result. The raw TOML text is captured and attached to
metadata["simulation_toml"] so downstream FieldDataset writers
can round-trip it verbatim into attrs.simulation_toml (schema.md
§4.2) — losslessly preserving sections ([bodies], [drivers],
[output], [restart], [probes], ...) that the typed
SimulationConfig drops on the way to FieldDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to a TOML file conforming to the v2.0 schema. |
required |
Returns:
| Type | Description |
|---|---|
SimulationConfig
|
Fully typed configuration with grid, normalization, species, physics, frame, and transforms populated. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the document fails schema validation. Dotted field paths in the error message point to every violation. |
UnsupportedGridError
|
If the document is valid but declares a grid pypic cannot
represent — today, |
Source code in src/pypic/readers/config.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
conserved_to_tabular(cq)
¶
Convert a ConservedQuantities to a generic TabularData.
Scalar fields map directly. Per-species tuples are flattened to
"npart_s0", "charge_s0", "kinetic_energy_s0", etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cq
|
ConservedQuantities
|
Typed iPIC3D conserved quantities. |
required |
Returns:
| Type | Description |
|---|---|
TabularData
|
Columnar representation with |
Examples:
>>> import numpy as np
>>> cq = ConservedQuantities(
... cycle=np.array([0.0, 1.0]),
... total_energy=np.array([5.0, 5.1]),
... electric_energy=np.array([1.0, 1.1]),
... magnetic_energy=np.array([2.0, 2.0]),
... kinetic_energy=np.array([2.0, 2.0]),
... momentum=np.array([0.1, 0.1]),
... species_npart=(np.array([100.0, 100.0]),),
... species_charge=(np.array([1.0, 1.0]),),
... species_kinetic_energy=(np.array([1.0, 1.0]),),
... )
>>> tab = conserved_to_tabular(cq)
>>> "npart_s0" in tab
True
>>> tab.index_column
'cycle'
Source code in src/pypic/readers/ipic3d/_conserved.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
detect_particle_steps(path)
¶
Scan for Particles_XXXXX/ directories and return sorted step list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted timestep indices with particle output. |
Source code in src/pypic/readers/ipic3d/_particles.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
load_conserved_quantities(path)
¶
Load conserved quantities from an iPIC3D run, auto-detecting format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Either a single |
required |
Returns:
| Type | Description |
|---|---|
ConservedQuantities
|
Parsed time series. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no conserved quantities data is found. |
Source code in src/pypic/readers/ipic3d/_conserved.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
open_ipic3d(path, *, config_path=None)
¶
Auto-detect iPIC3D format and return the appropriate reader.
Detection priority:
- Parse config from
.inporsettings.hdf. - If
*-Fields_*.h5files exist →IPic3DH5hutReader. - If
WriteMethod == "shdf5"→IPic3DSerialReader. - If
WriteMethod == "h5hut"→IPic3DH5hutReader. - Default →
IPic3DParallelReader.
File-based detection (step 2) takes precedence because
WriteMethod is often commented out in H5hut runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
config_path
|
Path | None
|
Explicit path to an |
None
|
Returns:
| Type | Description |
|---|---|
tuple[SimulationReader, SimulationConfig]
|
A (reader, config) pair ready for
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no |
Source code in src/pypic/readers/ipic3d/__init__.py
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 | |
parse_inp(path)
¶
Parse an iPIC3D .inp configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
IPic3DConfig
|
Parsed configuration. |
Raises:
| Type | Description |
|---|---|
ExceptionGroup
|
If required keys are missing. |
Source code in src/pypic/readers/ipic3d/_config.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
read_phdf5_particles(path, step, species, config, *, columns=None)
¶
Read particle data from a phdf5-format iPIC3D output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
species
|
int
|
Zero-based species index. |
required |
config
|
IPic3DConfig
|
Parsed iPIC3D configuration. Provides per-species charge/mass via
|
required |
columns
|
Iterable[str] | None
|
Subset of |
None
|
Returns:
| Type | Description |
|---|---|
ParticleData
|
|
Raises:
| Type | Description |
|---|---|
UnknownFieldError
|
If columns names anything outside |
Source code in src/pypic/readers/ipic3d/_particles.py
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 | |
open_openggcm(path, normalization=None, *, config_path=None)
¶
Auto-detect OpenGGCM files and return a reader + config.
Looks for grid.*.dat and *.3df.* files under path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing OpenGGCM output files. |
required |
normalization
|
Normalization | None
|
If provided, data is normalized from SI to code units. |
None
|
config_path
|
Path | None
|
Explicit path to a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
reader |
OpenGGCMReader
|
Configured reader instance. |
config |
SimulationConfig
|
Simulation metadata. |
Source code in src/pypic/readers/openggcm/__init__.py
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 | |
parse_grid_file(path)
¶
Parse an OpenGGCM ASCII grid file.
The file contains header metadata followed by 21 FIELD-1D-1
sections: primary grids (gridx, gridy, gridz) then 18
staggered grids for the six field components (B and E, three
directions each).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
OpenGGCMGrid
|
|
Source code in src/pypic/readers/openggcm/_grid.py
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 | |
batsrus
¶
BATSRUS MHD simulation reader.
Supports three output formats:
- Per-cell IDL (
.h+*_pe*.idl): raw per-processor binary - Merged IDL (
.out/.outs): postprocessed snapshot files - HDF5 BATL (
.batl): block-structured HDF5 from BATL library
Auto-detection via open_batsrus examines directory contents to select
the appropriate reader.
BATSRUSConfig
dataclass
¶
Parsed BATSRUS PARAM.in configuration.
Source code in src/pypic/readers/batsrus/_config.py
22 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 | |
BATSRUSHeader
dataclass
¶
Parsed content of a BATSRUS .h output header file.
These header files accompany per-processor .idl data files and
contain all metadata needed to interpret the binary records.
Source code in src/pypic/readers/batsrus/_header.py
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 | |
BATSRUSReader
¶
Bases: ReaderBase
Read BATSRUS simulation output in IDL or HDF5 format.
Supports three output formats:
- Per-cell IDL (
.h+*_pe*.idl): raw per-processor binary - Merged IDL (
.out/.outs): postprocessed snapshot files - HDF5 BATL (
.batl): block-structured HDF5
AMR grids are automatically regridded to the finest resolution.
Source code in src/pypic/readers/batsrus/_reader.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
available_timesteps(path)
¶
Return sorted list of available timestep indices.
Source code in src/pypic/readers/batsrus/_reader.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Parses file headers or HDF5 metadata without loading arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing the simulation output. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name. |
Source code in src/pypic/readers/batsrus/_reader.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
read_timestep(path, step, *, fields=None, target_resolution=None)
¶
Read field data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing the simulation output. |
required |
step
|
int
|
Timestep index. |
required |
fields
|
Iterable[str] | None
|
When given, only include these canonical field names. |
None
|
target_resolution
|
float | None
|
Target cell size in code units for AMR regridding. When
|
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names, optionally converted to SI. |
Source code in src/pypic/readers/batsrus/_reader.py
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 | |
BATSRUSOutputFormat
¶
Bases: StrEnum
BATSRUS output file format.
Source code in src/pypic/readers/batsrus/__init__.py
41 42 43 44 45 46 | |
parse_param_in(path)
¶
Parse a BATSRUS PARAM.in file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BATSRUSConfig
|
Frozen dataclass with extracted configuration. |
Source code in src/pypic/readers/batsrus/_config.py
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 223 224 225 226 227 228 229 230 231 | |
to_simulation_config(config, header=None, *, grid=None, sim_dir=None)
¶
Build a SimulationConfig from BATSRUS config and header.
If a simulation.toml exists in sim_dir, its normalization, frame,
transforms, and metadata are merged in via
pypic.readers._config_helpers.merge_simulation_toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BATSRUSConfig
|
Parsed |
required |
header
|
BATSRUSHeader | None
|
Parsed |
None
|
grid
|
GridInfo | None
|
Pre-built GridInfo (overrides header-derived grid). |
None
|
sim_dir
|
Path | None
|
Simulation directory to scan for |
None
|
Returns:
| Type | Description |
|---|---|
SimulationConfig
|
|
Source code in src/pypic/readers/batsrus/_config.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
extract_step_from_filename(name)
¶
Extract the timestep number from a BATSRUS output filename.
Examples:
>>> extract_step_from_filename("3d__mhd_2_t00000010_n00000042.batl")
42
>>> extract_step_from_filename("PARAM.in") is None
True
Source code in src/pypic/readers/batsrus/_header.py
17 18 19 20 21 22 23 24 25 26 27 28 | |
parse_header(path)
¶
Parse a BATSRUS .h header file into a BATSRUSHeader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BATSRUSHeader
|
Frozen dataclass with all extracted metadata. |
Source code in src/pypic/readers/batsrus/_header.py
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 | |
can_read_confidence(path)
¶
Estimate confidence that path contains BATSRUS output.
Detection signals (additive, capped at 1.0):
PARAM.in: +0.3.batlfiles (HDF5 BATL): +0.5*_pe*.idlper-cell files: +0.2.hheader files with BATSRUS timestamp pattern: +0.3.out/.outsmerged files: +0.3 (only if nothing else matched)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory to check. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence in |
Source code in src/pypic/readers/batsrus/_probe.py
21 22 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 | |
open_batsrus(path, *, config_path=None)
¶
Auto-detect BATSRUS output format and return a reader.
Detection order:
1. .batl files → HDF5 BATL format
2. .h + *_pe*.idl files → per-cell IDL binary
3. .out / .outs files → merged IDL
Prefers 3D data over 2D slices when both are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing BATSRUS output files. |
required |
config_path
|
Path | None
|
Explicit path to a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
reader |
SimulationReader
|
A |
config |
SimulationConfig
|
Simulation configuration parsed from |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no recognizable BATSRUS output is found. |
Source code in src/pypic/readers/batsrus/__init__.py
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 | |
config
¶
Load simulation configuration from a TOML file.
The Pydantic validator in pypic.schema is the authoritative
source of the v2.0 schema — this module is a thin translator from a
validated SimulationSchema to the internal
dataclasses (SimulationConfig, GridInfo,
Normalization, SpeciesInfo). All shape validation
happens in the Pydantic layer; this module only maps fields.
apply_physical_extent(config, physical_extent, physical_extent_unit='m')
¶
Auto-compute transform scale factors from physical domain extent.
When a simulation represents a physical domain of known size (e.g.,
46 R_E across), this function computes the scale — the coordinate
conversion factor from code units to target units (e.g., 0.25 R_E/d_i).
For transforms with the default scale=1.0, the computed scale is
applied. For transforms with an explicit scale, consistency is validated.
If the normalization is not identity, also computes the shrink factor — how much the physical domain is compressed relative to what the normalization implies (e.g., 3.5× for reduced mass ratio PIC). A shrink factor of 1.0 means no spatial rescaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SimulationConfig
|
Original simulation configuration. |
required |
physical_extent
|
tuple[float, ...]
|
Domain size per target-frame axis, in physical_extent_unit. |
required |
physical_extent_unit
|
str
|
Length unit name. See |
'm'
|
Returns:
| Type | Description |
|---|---|
SimulationConfig
|
New config with computed scale factors and metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the unit is unknown or the implied scale is not uniform. |
Source code in src/pypic/readers/config.py
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 | |
load_config(path)
¶
Parse a simulation.toml file into a SimulationConfig.
Validates the file against the v2.0 schema
(pypic.schema) and builds the internal SimulationConfig
from the result. The raw TOML text is captured and attached to
metadata["simulation_toml"] so downstream FieldDataset writers
can round-trip it verbatim into attrs.simulation_toml (schema.md
§4.2) — losslessly preserving sections ([bodies], [drivers],
[output], [restart], [probes], ...) that the typed
SimulationConfig drops on the way to FieldDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to a TOML file conforming to the v2.0 schema. |
required |
Returns:
| Type | Description |
|---|---|
SimulationConfig
|
Fully typed configuration with grid, normalization, species, physics, frame, and transforms populated. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the document fails schema validation. Dotted field paths in the error message point to every violation. |
UnsupportedGridError
|
If the document is valid but declares a grid pypic cannot
represent — today, |
Source code in src/pypic/readers/config.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
ipic3d
¶
iPIC3D simulation readers (parallel HDF5, serial HDF5, and H5hut).
IPic3DConfig
dataclass
¶
Native iPIC3D simulation parameters.
Stores the raw values from an .inp file or settings.hdf,
before any conversion to the canonical pypic schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nxc
|
int
|
Number of cells along each axis. |
required |
nyc
|
int
|
Number of cells along each axis. |
required |
nzc
|
int
|
Number of cells along each axis. |
required |
lx
|
float
|
Domain size along each axis (code units). |
required |
ly
|
float
|
Domain size along each axis (code units). |
required |
lz
|
float
|
Domain size along each axis (code units). |
required |
dx
|
float
|
Cell spacing (code units). Computed as |
required |
dy
|
float
|
Cell spacing (code units). Computed as |
required |
dz
|
float
|
Cell spacing (code units). Computed as |
required |
dt
|
float
|
Timestep in code units. |
required |
xlen
|
int
|
MPI topology (processors per axis). |
required |
ylen
|
int
|
MPI topology (processors per axis). |
required |
zlen
|
int
|
MPI topology (processors per axis). |
required |
c
|
float
|
Speed of light in code units. |
required |
th
|
float
|
Implicitness parameter (0.5 = Crank-Nicolson). |
required |
b0
|
tuple[float, float, float]
|
Background magnetic field |
required |
ns
|
int
|
Number of particle species. |
required |
qom
|
tuple[float, ...]
|
Charge-to-mass ratio per species. |
required |
uth
|
tuple[float, ...]
|
Thermal velocities per species (x, y, z components). |
required |
vth
|
tuple[float, ...]
|
Thermal velocities per species (x, y, z components). |
required |
wth
|
tuple[float, ...]
|
Thermal velocities per species (x, y, z components). |
required |
u0
|
tuple[float, ...]
|
Drift velocities per species (x, y, z components). |
required |
v0
|
tuple[float, ...]
|
Drift velocities per species (x, y, z components). |
required |
w0
|
tuple[float, ...]
|
Drift velocities per species (x, y, z components). |
required |
rho_init
|
tuple[float, ...]
|
Initial number density per species (code units). |
required |
npcelx
|
tuple[int, ...]
|
Particles per cell per species (x, y, z). |
required |
npcely
|
tuple[int, ...]
|
Particles per cell per species (x, y, z). |
required |
npcelz
|
tuple[int, ...]
|
Particles per cell per species (x, y, z). |
required |
periodic_x
|
bool
|
Periodicity per axis. |
required |
periodic_y
|
bool
|
Periodicity per axis. |
required |
periodic_z
|
bool
|
Periodicity per axis. |
required |
write_method
|
str
|
Output format ( |
required |
field_output_cycle
|
int
|
Field output frequency (cycles between dumps). |
required |
field_output_tag
|
str
|
Space-separated tags controlling which fields are written. |
required |
particles_output_cycle
|
int
|
Particle output frequency (cycles between dumps; <=0 = disabled). |
required |
case
|
str
|
Simulation case identifier. |
required |
simulation_name
|
str
|
Human-readable simulation name. |
required |
Source code in src/pypic/readers/ipic3d/_config.py
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 | |
ConservedQuantities
dataclass
¶
Time series of conserved quantities from an iPIC3D run.
Two output formats exist:
Format A (Roman numeral header) — single file from phdf5/shdf5 runs. Columns: cycle, electric energy (total, x, y, z), magnetic energy (total, x, y, z), kinetic energy, total energy, energy variation, momentum.
Format B (comment header) — per-restart-segment files from H5hut runs. Columns: cycle, total energy, energy variation, electric energy, local B energy, kinetic energy, momentum, total B energy, internal B energy, KE removed, E removed, then per-species (npart, charge, KE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
FloatArray
|
Cycle numbers (int-valued but stored as float for array uniformity). |
required |
total_energy
|
FloatArray
|
Total energy at each cycle. |
required |
electric_energy
|
FloatArray
|
Total electric field energy. |
required |
magnetic_energy
|
FloatArray
|
Total magnetic field energy. |
required |
kinetic_energy
|
FloatArray
|
Total kinetic energy (all species). |
required |
momentum
|
FloatArray
|
Total momentum magnitude. |
required |
species_npart
|
tuple[FloatArray, ...]
|
Number of particles per species at each cycle. |
required |
species_charge
|
tuple[FloatArray, ...]
|
Total charge per species. |
required |
species_kinetic_energy
|
tuple[FloatArray, ...]
|
Kinetic energy per species. |
required |
Source code in src/pypic/readers/ipic3d/_conserved.py
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 | |
IPic3DH5hutReader
¶
Bases: IPic3DReaderBase
Read iPIC3D H5hut field output.
H5hut files store all fields for a single timestep in one file
named {SimulationName}-Fields_{cycle:06d}.h5. Arrays are stored
in ZYX order ((nzc+1, nyc+1, nxc+1)) and must be transposed.
H5hut stores all moment quantities (density, current, pressure) divided by 4π (Gaussian convention). The reader applies the 4π correction to density, current, and pressure, matching the phdf5/shdf5 readers. Electromagnetic fields are unaffected.
Unique to this reader: the single-file-per-timestep layout, ZYX
transpose, H5hut-specific field naming (uppercase axis letters
in _PRESSURE_COMPONENT_MAP), and passthrough of unknown native
fields. Field-name mapping for everything else, the Gaussian
conversions, pressure-tensor mass correction, and config
translation live in pypic.readers.ipic3d._field_map and
pypic.readers.ipic3d._config, shared with the parallel and
serial readers.
Source code in src/pypic/readers/ipic3d/_h5hut.py
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 | |
available_timesteps(path)
¶
Sorted cycle numbers, from the *-Fields_*.h5 files under path.
Source code in src/pypic/readers/ipic3d/_h5hut.py
76 77 78 79 80 81 82 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Opens the H5hut fields file and inspects Step#0/Block/
keys. Unknown native keys pass through with the same name as
both key and value, matching read_timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep (cycle) index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name, |
Source code in src/pypic/readers/ipic3d/_h5hut.py
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 | |
read_timestep(path, step, *, fields=None)
¶
Read field and moment data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Cycle number (e.g. 202500). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. Dependencies (per-species fields needed for totals) are expanded automatically and excluded from the result. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names. Density, current, and pressure tensor all corrected by 4π (Gaussian→SI-rationalized). |
Source code in src/pypic/readers/ipic3d/_h5hut.py
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 | |
IPic3DParallelReader
¶
Bases: IPic3DReaderBase
Read iPIC3D parallel HDF5 (phdf5) output.
Each timestep is stored in separate Fields_XXXXX/ and
Moments_XXXXX/ directories containing one .h5 file per
field group.
Unique to this reader: scanning timestep directories and the
one-file-per-moment layout. Field-name mapping, Gaussian-CGS unit
conversions, pressure-tensor mass correction, and config
translation live in pypic.readers.ipic3d._field_map and
pypic.readers.ipic3d._config, shared with the serial and
H5hut readers.
Source code in src/pypic/readers/ipic3d/_parallel.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
available_timesteps(path)
¶
Sorted timestep numbers, from the Fields_XXXXX directories.
Source code in src/pypic/readers/ipic3d/_parallel.py
107 108 109 110 111 112 113 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Probes HDF5 files in the Fields_XXXXX/ and
Moments_XXXXX/ directories without loading arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name, |
Source code in src/pypic/readers/ipic3d/_parallel.py
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 | |
read_timestep(path, step, *, fields=None)
¶
Read field and moment data for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index (e.g. 0, 10, 20). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names and 4π corrections applied. |
Source code in src/pypic/readers/ipic3d/_parallel.py
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 | |
available_particle_steps(path)
¶
Return sorted timestep indices that have particle data.
Source code in src/pypic/readers/ipic3d/_parallel.py
221 222 223 | |
read_particles(path, step, species, *, columns=None)
¶
Load particle data for one species at one timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
species
|
int
|
Zero-based species index. |
required |
columns
|
Iterable[str] | None
|
Subset of |
None
|
Returns:
| Type | Description |
|---|---|
ParticleData
|
|
Source code in src/pypic/readers/ipic3d/_parallel.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
IPic3DSerialReader
¶
Bases: IPic3DReaderBase
Read iPIC3D serial HDF5 (shdf5) output.
Each MPI process writes to its own procN.hdf file containing all
timesteps. This reader assembles the global arrays from the per-process
local patches.
Unique to this reader: the per-process patch reassembly. Field-name
mapping, Gaussian-CGS unit conversions, pressure-tensor mass
correction, and config translation live in
pypic.readers.ipic3d._field_map and
pypic.readers.ipic3d._config, shared with the parallel and
H5hut readers.
Source code in src/pypic/readers/ipic3d/_serial.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
available_timesteps(path)
¶
Sorted timestep numbers, from the cycle keys in proc0.hdf.
Source code in src/pypic/readers/ipic3d/_serial.py
48 49 50 51 52 53 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native (on-disk) names at step.
Opens proc0.hdf and inspects HDF5 group keys without
loading array data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Canonical → native name, |
Source code in src/pypic/readers/ipic3d/_serial.py
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 | |
read_timestep(path, step, *, fields=None)
¶
Read field and moment data for a single timestep.
Assembles global arrays from per-process files, applies 4π correction to densities and currents, and computes totals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index (e.g. 0, 10, 20). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names and 4π corrections applied. |
Source code in src/pypic/readers/ipic3d/_serial.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
parse_inp(path)
¶
Parse an iPIC3D .inp configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
IPic3DConfig
|
Parsed configuration. |
Raises:
| Type | Description |
|---|---|
ExceptionGroup
|
If required keys are missing. |
Source code in src/pypic/readers/ipic3d/_config.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
parse_settings_hdf(path)
¶
Parse an iPIC3D settings.hdf file (serial format metadata).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
IPic3DConfig
|
Parsed configuration (equivalent to |
Source code in src/pypic/readers/ipic3d/_config.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
to_simulation_config(cfg, sim_dir=None)
¶
Convert iPIC3D config to the canonical SimulationConfig.
Uses the node-centered origin offset trick: origin = -dx/2 so that
coordinate_arrays() produces exact node positions 0, dx, 2dx, ..., L.
If a simulation.toml exists in sim_dir, its normalization, frame,
transforms, and metadata are merged in via
pypic.readers._config_helpers.merge_simulation_toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
IPic3DConfig
|
Native iPIC3D configuration. |
required |
sim_dir
|
Path | None
|
Simulation directory to scan for |
None
|
Returns:
| Type | Description |
|---|---|
SimulationConfig
|
Canonical simulation configuration. |
Source code in src/pypic/readers/ipic3d/_config.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
conserved_to_tabular(cq)
¶
Convert a ConservedQuantities to a generic TabularData.
Scalar fields map directly. Per-species tuples are flattened to
"npart_s0", "charge_s0", "kinetic_energy_s0", etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cq
|
ConservedQuantities
|
Typed iPIC3D conserved quantities. |
required |
Returns:
| Type | Description |
|---|---|
TabularData
|
Columnar representation with |
Examples:
>>> import numpy as np
>>> cq = ConservedQuantities(
... cycle=np.array([0.0, 1.0]),
... total_energy=np.array([5.0, 5.1]),
... electric_energy=np.array([1.0, 1.1]),
... magnetic_energy=np.array([2.0, 2.0]),
... kinetic_energy=np.array([2.0, 2.0]),
... momentum=np.array([0.1, 0.1]),
... species_npart=(np.array([100.0, 100.0]),),
... species_charge=(np.array([1.0, 1.0]),),
... species_kinetic_energy=(np.array([1.0, 1.0]),),
... )
>>> tab = conserved_to_tabular(cq)
>>> "npart_s0" in tab
True
>>> tab.index_column
'cycle'
Source code in src/pypic/readers/ipic3d/_conserved.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
load_conserved_quantities(path)
¶
Load conserved quantities from an iPIC3D run, auto-detecting format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Either a single |
required |
Returns:
| Type | Description |
|---|---|
ConservedQuantities
|
Parsed time series. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no conserved quantities data is found. |
Source code in src/pypic/readers/ipic3d/_conserved.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
load_species_quantities(path)
¶
Parse iPIC3D SpeciesQuantities.txt into a TabularData.
Format: one row per species per cycle. Columns:
cycle, species, momentum, total_ke, bulk_ke, thermal_ke.
The output pivots per-species data into separate columns:
cycle, momentum_s0, total_ke_s0, bulk_ke_s0, thermal_ke_s0, ..._s1, ...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to |
required |
Returns:
| Type | Description |
|---|---|
TabularData
|
Columnar representation with |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
Source code in src/pypic/readers/ipic3d/_conserved.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
detect_particle_steps(path)
¶
Scan for Particles_XXXXX/ directories and return sorted step list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted timestep indices with particle output. |
Source code in src/pypic/readers/ipic3d/_particles.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
read_phdf5_particles(path, step, species, config, *, columns=None)
¶
Read particle data from a phdf5-format iPIC3D output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
step
|
int
|
Timestep index. |
required |
species
|
int
|
Zero-based species index. |
required |
config
|
IPic3DConfig
|
Parsed iPIC3D configuration. Provides per-species charge/mass via
|
required |
columns
|
Iterable[str] | None
|
Subset of |
None
|
Returns:
| Type | Description |
|---|---|
ParticleData
|
|
Raises:
| Type | Description |
|---|---|
UnknownFieldError
|
If columns names anything outside |
Source code in src/pypic/readers/ipic3d/_particles.py
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 | |
can_read_confidence(path)
¶
Estimate confidence that path contains iPIC3D output.
Detection signals (additive, capped at 1.0):
*.inpconfig file: +0.5settings.hdf: +0.4*-Fields_*.h5(H5hut files): +0.3Fields_*subdirectories (phdf5): +0.2 (fallback only)proc*.hdffiles (shdf5): +0.2 (fallback only)Moments_*subdirectories: +0.15 (reinforcement, only if 0 < score < 0.8)Particles_*subdirectories: +0.1 (reinforcement, only if 0 < score < 0.8)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory to check. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence in |
Source code in src/pypic/readers/ipic3d/_probe.py
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 | |
open_ipic3d(path, *, config_path=None)
¶
Auto-detect iPIC3D format and return the appropriate reader.
Detection priority:
- Parse config from
.inporsettings.hdf. - If
*-Fields_*.h5files exist →IPic3DH5hutReader. - If
WriteMethod == "shdf5"→IPic3DSerialReader. - If
WriteMethod == "h5hut"→IPic3DH5hutReader. - Default →
IPic3DParallelReader.
File-based detection (step 2) takes precedence because
WriteMethod is often commented out in H5hut runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Simulation output directory. |
required |
config_path
|
Path | None
|
Explicit path to an |
None
|
Returns:
| Type | Description |
|---|---|
tuple[SimulationReader, SimulationConfig]
|
A (reader, config) pair ready for
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no |
Source code in src/pypic/readers/ipic3d/__init__.py
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 | |
openggcm
¶
OpenGGCM-UCLA MHD .3df reader.
Reads .3df field output files and grid.*.dat grid definitions
from the OpenGGCM global MHD model. The .3df format uses WRN2
lossy compression (~12.5-bit precision via logarithmic quantization +
run-length encoding).
Quick start::
from pypic.readers.openggcm import open_openggcm
from pathlib import Path
path = Path("tests/data/openggcm-small")
reader, cfg = open_openggcm(path)
ds = reader.read_timestep(path, 6300)
sorted(ds.field_names())
# ['B_1', 'B_2', 'B_3', 'P', 'V_1', 'V_2', 'V_3', 'n_s0', ...]
OpenGGCMGrid
dataclass
¶
Non-uniform grid definition from an OpenGGCM grid file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nx
|
int
|
Number of grid points along each axis. |
required |
ny
|
int
|
Number of grid points along each axis. |
required |
nz
|
int
|
Number of grid points along each axis. |
required |
x
|
FloatArray
|
X-coordinates (non-uniform), shape |
required |
y
|
FloatArray
|
Y-coordinates (non-uniform), shape |
required |
z
|
FloatArray
|
Z-coordinates (non-uniform), shape |
required |
stagger
|
MappingProxyType[str, tuple[FloatArray, FloatArray, FloatArray]]
|
Staggered grid positions keyed by field component ( |
required |
metadata
|
MappingProxyType[str, str]
|
Header metadata ( |
required |
Source code in src/pypic/readers/openggcm/_grid.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
OpenGGCMReader
¶
Bases: ReaderBase
Read OpenGGCM .3df field output on a non-uniform grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
OpenGGCMGrid
|
Parsed grid definition. |
required |
prefix
|
str
|
Filename prefix (e.g. |
required |
sim_config
|
SimulationConfig
|
Merged run configuration. Its normalization converts the SI values on disk to code units; identity leaves them in SI. |
required |
Source code in src/pypic/readers/openggcm/_reader.py
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 | |
grid
property
¶
The OpenGGCM non-uniform grid.
available_timesteps(path)
¶
Return sorted list of available timestep indices.
Scans for {prefix}.3df.* files under path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing .3df files. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted timestep indices. |
Source code in src/pypic/readers/openggcm/_reader.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
available_fields_mapping(path, step)
¶
Map canonical field names to native .3df record names at step.
Scans the file's FIELD-3D-1 markers without decoding any
WRN2 payload.
Source code in src/pypic/readers/openggcm/_reader.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
read_timestep(path, step, *, fields=None)
¶
Read fields for a single timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing .3df files. |
required |
step
|
int
|
Timestep index (e.g. 6300). |
required |
fields
|
Iterable[str] | None
|
When given, only read these canonical field names. Skips WRN2 decompression for unwanted native fields. |
None
|
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Field data with canonical names in SI (or normalized) units.
|
Source code in src/pypic/readers/openggcm/_reader.py
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 | |
parse_grid_file(path)
¶
Parse an OpenGGCM ASCII grid file.
The file contains header metadata followed by 21 FIELD-1D-1
sections: primary grids (gridx, gridy, gridz) then 18
staggered grids for the six field components (B and E, three
directions each).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
OpenGGCMGrid
|
|
Source code in src/pypic/readers/openggcm/_grid.py
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 | |
can_read_confidence(path)
¶
Estimate confidence that path contains OpenGGCM output.
Detection signals (additive, capped at 1.0):
grid.*.datgrid file: +0.5*.3df.*field files: +0.5
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory to check. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Confidence in |
Source code in src/pypic/readers/openggcm/_probe.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
open_openggcm(path, normalization=None, *, config_path=None)
¶
Auto-detect OpenGGCM files and return a reader + config.
Looks for grid.*.dat and *.3df.* files under path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Directory containing OpenGGCM output files. |
required |
normalization
|
Normalization | None
|
If provided, data is normalized from SI to code units. |
None
|
config_path
|
Path | None
|
Explicit path to a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
reader |
OpenGGCMReader
|
Configured reader instance. |
config |
SimulationConfig
|
Simulation metadata. |
Source code in src/pypic/readers/openggcm/__init__.py
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 | |