File: t_Study_h5.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (49 lines) | stat: -rwxr-xr-x 1,009 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python

import openturns as ot
import openturns.testing
import os

ot.TESTPREAMBLE()

fileName = "pyxmlh5.xml.gz"
study = ot.Study()
study.setStorageManager(ot.XMLH5StorageManager(fileName, 5))

point = ot.Point([123.456, 125.43, 3975.4567])
point2 = ot.Point(3, 789.123)
point3 = ot.Point(3, 1673.456)
point4 = ot.Point(3, 789.654123)

sample = ot.Sample(1, point)
sample.add(point2)
sample.add(point3)
sample.add(point4)
sample.add(point2)
sample.add(point4)
sample.add(point3)
print(sample)
study.add("sample", sample)


mesh = ot.IntervalMesher([50] * 3).build(ot.Interval(3))
study.add("mesh", mesh)

study.save()

study2 = ot.Study()
study2.setStorageManager(ot.XMLH5StorageManager(fileName))

study2.load()
sample2 = ot.Sample()
study2.fillObject("sample", sample2)
print(sample2)
assert sample == sample2, "wrong sample"

mesh2 = ot.Mesh()
study2.fillObject("mesh", mesh2)
assert mesh == mesh2, "wrong mesh"

# cleanup
os.remove(fileName)
os.remove(fileName.replace(".xml.gz", ".h5"))