def __init__(self, studyName = "resultKL.xml"): self.resultKL = ot.KarhunenLoeveResult() study = ot.Study(studyName) study.load() study.fillObject("resultKL", self.resultKL) mean = ot.Point() study.fillObject("mean", mean) self.meanMax = mean[-1] super(StationaryPressure, self).__init__(self.resultKL.getEigenValues().getSize(), 1)
def _export_xml(self): """ Export the OpenTurns function as xml. Parameters ---------- """ study = ot.Study() study.setStorageManager(ot.XMLStorageManager(self._xml_path)) study.add('function', self.function_) study.save()
#! /usr/bin/env python from __future__ import print_function import openturns as ot import openturns.testing import os import sys import math as m ot.TESTPREAMBLE() try: fileName = 'myStudy.xml' # Create a Study Object by name myStudy = ot.Study(fileName) point = ot.Point(2, 1.0) myStudy.add("point", point) myStudy.save() myStudy2 = ot.Study(fileName) myStudy2.load() point2 = ot.Point() myStudy2.fillObject("point", point2) # cleanup os.remove(fileName) # Create a Study Object with compression myStudy = ot.Study() compressionLevel = 5 myStudy.setStorageManager( ot.XMLStorageManager(fileName + ".gz", compressionLevel))
#! /usr/bin/env python from __future__ import print_function import openturns as ot import os ot.TESTPREAMBLE() f = ot.Function() # load study = ot.Study() study.setStorageManager(ot.XMLStorageManager('pyf.xml')) study.load() study.fillObject('f', f) x = [4, 5] print(f(x)) os.remove('pyf.xml')
#! /usr/bin/env python from __future__ import print_function import openturns as ot import openturns.testing import os ot.TESTPREAMBLE() try: fileName = 'myStudy.xml' # Create a Study Object by name myStudy = ot.Study(fileName) point = ot.Point(2, 1.0) myStudy.add("point", point) myStudy.save() myStudy2 = ot.Study(fileName) myStudy2.load() point2 = ot.Point() myStudy2.fillObject("point", point2) # cleanup os.remove(fileName) # Create a Study Object with compression myStudy = ot.Study() compressionLevel = 5 myStudy.setStorageManager(ot.XMLStorageManager(fileName, compressionLevel)) point = ot.Point(2, 1.0) myStudy.add("point", point) myStudy.save()
def getParameterDescription(self): paramDesc = ['a_' + str(i) for i in range(len(self.a))] paramDesc.extend(['b_' + str(i) for i in range(len(self.a))]) return paramDesc def setParameter(self, parameter): dim = len(self.a) for i in range(dim): self.a[i] = parameter[i] self.b[i] = parameter[dim + i] myDist = ot.Distribution(UniformNdPy([0.0] * 2, [2.0] * 2)) st = ot.Study() fileName = 'PyDIST.xml' st.setStorageManager(ot.XMLStorageManager(fileName)) st.add("myDist", myDist) st.save() print('saved dist=', myDist) dist = ot.Distribution() st = ot.Study() st.setStorageManager(ot.XMLStorageManager(fileName)) st.load()
# **With OpenTURNS' Study** # # In order to be able to manipulate the objects contained in a Study, it is necessary to: # # - create the same empty structure in the new study, # - fill this new empty structure with the content of the loaded structure, identified with its name or its id. # # Each object is identified whether with: # # - its name: it is useful to give names to the objects we want to save. If no name has been given by the user, we can use the default name. The name of each saved object can be checked in the output XML file or with the python `print` command (applied to the `Study` object). # - its id number: this id number is unique to each object. It distinguishes objects with identical type and name (like the default name "Unnamed"). This id number may be checked by printing the study **after** it has been loaded in the python interface (with the `print` command). It can differ from the id number indicated in the XML file the study was loaded from. # - for HDF5 storage (see below): the id serves both as xml id and hdf5 dataset name. Id uniqueness forbids any misleading in reading/writing hdf5 datasets. # %% # Create a Study Object study = ot.Study() # %% # Associate it to an XML file fileName = 'study.xml' study.setStorageManager(ot.XMLStorageManager(fileName)) # %% # Alternatively, large amounts of data can be stored in binary HDF5 file. An XML file (`study_h5.xml`) serves as header for binary data, which are stored in the automatically created `study_h5.h5` file. study_h5 = ot.Study() fileName_h5 = 'study_h5.xml' study_h5.setStorageManager(ot.XMLH5StorageManager(fileName_h5)) # %% # Add an object to the study; at this point it is not written to disk yet study.add('distribution', distribution)
#! /usr/bin/env python from __future__ import print_function import openturns as ot import os ot.TESTPREAMBLE() fileName = 'myStudy.xml' # Create a Study Object myStudy = ot.Study() myStudy.setStorageManager(ot.XMLStorageManager(fileName)) # Add a PersistentObject to the Study (here a NumericalPoint) p1 = ot.NumericalPoint(3, 0.) p1.setName("Good") p1[0] = 10. p1[1] = 11. p1[2] = 12. myStudy.add(p1) # Add another PersistentObject to the Study (here a NumericalSample) s1 = ot.NumericalSample(3, 2) s1.setName("mySample") p2 = ot.NumericalPoint(2, 0.) p2.setName("One") p2[0] = 100. p2[1] = 200. s1[0] = p2 p3 = ot.NumericalPoint(2, 0.)
#! /usr/bin/env python import openturns as ot import openturns.testing import os import sys import math as m 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)