File: adios2-doc-read-stream.py

package info (click to toggle)
adios2 2.10.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 33,764 kB
  • sloc: cpp: 175,964; ansic: 160,510; f90: 14,630; yacc: 12,668; python: 7,275; perl: 7,126; sh: 2,825; lisp: 1,106; xml: 1,049; makefile: 579; lex: 557
file content (31 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
from adios2 import Stream

with Stream("cfd.bp", "r") as s:
    # steps comes from the stream
    for _ in s.steps():
        # track current step
        print(f"Current step is {s.current_step()}")

        # inspect variables in current step
        for name, info in s.available_variables().items():
            print("variable_name: " + name, end=" ")
            for key, value in info.items():
                print("\t" + key + ": " + value, end=" ")
            print()

        if s.current_step() == 0:
            nproc = s.read("nproc")
            print(f"nproc is {nproc} of type {type(nproc)} with ndim {nproc.ndim}")

        # read variables return a numpy array with corresponding selection
        physical_time = s.read("physical_time")
        print(f"physical_time is {physical_time} of type {type(physical_time)}")
        temperature = s.read("temperature")
        temp_unit = s.read_attribute("temperature/unit")
        print(f"temperature array size is {temperature.size} of shape {temperature.shape}")
        print(f"temperature unit is {temp_unit} of type {type(temp_unit)}")
        pressure = s.read("pressure")
        press_unit = s.read_attribute("unit", "pressure")
        print(f"pressure unit is {press_unit} of type {type(press_unit)}")
        print()