Coverage for teaser/examples/e5_load.py: 88%
17 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-04-29 16:01 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2025-04-29 16:01 +0000
1# # Example 5: Load information
2# This module contains an example how to import TEASER projects from
3# `*.teaserjson` and pickle in order to reuse data.
4# You can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks)
7import teaser.logic.utilities as utilities
8import os
11def example_load():
12 """This function demonstrates different loading options of TEASER"""
14 # In example e4_save we saved two TEASER projects using `*.teaserjson` and
15 # Python package pickle. This example shows how to import these
16 # information into your python environment again.
18 # To load data from `*.teaserjson` we can use a simple API function. So
19 # first we need to instantiate our API (similar to example
20 # e1_generate_archetype). The json file is called
21 # `ArchetypeExample.teaserjson` and saved in the default path. You need to
22 # run e4 first before you can load this example file.
24 from teaser.project import Project
26 prj = Project()
28 load_json = os.path.join(utilities.get_default_path(), "ArchetypeExample.json")
30 prj.load_project(path=load_json)
32 prj = Project()
33 prj.load_project(utilities.get_full_path("examples/examplefiles/unitTest.json"))
34 prj.save_project(file_name="unitTest", path=None)
36 # To reload data from a pickle file, we do not need to instantiate an
37 # API, as pickle will automatically instantiate all classes as they have
38 # been saved. The saved file from example e4 is called ´teaser_pickle.p´
40 import pickle
42 load_pickle = os.path.join(utilities.get_default_path(), "teaser_pickle.p")
44 pickle_prj = pickle.load(open(load_pickle, "rb"))
45 print(pickle_prj)
47 # After you imported your teaser project one or another way into you
48 # python environment you can access variables and functions.
51if __name__ == "__main__":
52 example_load()
54 print("Example 5: That's it! :)")