File: adios2-doc-read-filereader.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 (35 lines) | stat: -rw-r--r-- 1,346 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
32
33
34
35
import numpy as np
from adios2 import FileReader

with FileReader("cfd.bp") as s:
    # inspect variables
    vars = s.available_variables()
    for name, info in vars.items():
        print("variable_name: " + name, end=" ")
        for key, value in info.items():
            print("\t" + key + ": " + value, end=" ")
        print()
    print()

    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
    steps = int(vars["physical_time"]["AvailableStepsCount"])
    physical_time = s.read("physical_time", step_selection=[0, steps])
    print(
        f"physical_time is {physical_time} of type {type(physical_time)} with "
        f"ndim {physical_time.ndim} shape = {physical_time.shape}"
    )

    steps = int(vars["temperature"]["AvailableStepsCount"])
    temperature = s.read("temperature", step_selection=[0, steps])
    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)}")

    steps = int(vars["pressure"]["AvailableStepsCount"])
    pressure = s.read("pressure", step_selection=[0, steps])
    press_unit = s.read_attribute("pressure/unit")

    print()