Coverage for teaser/examples/e4_save.py: 83%

12 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-04-29 16:01 +0000

1# # Example 4: Save information 

2# This module contains an example how to save buildings from a TEASER 

3# project to json and pickle in order to save information. 

4# You can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks) 

5 

6 

7import teaser.examples.e1_generate_archetype as e1 

8import teaser.logic.utilities as utilities 

9import os 

10 

11 

12def example_save(): 

13 """This function demonstrates different saving options of TEASER""" 

14 

15 # In e1_generate_archetype we created a Project with three archetype 

16 # buildings to get this Project we rerun this example 

17 

18 prj = e1.example_generate_archetype() 

19 

20 # First option is to use TEASERs own json format to save all relevant 

21 # data into a more or less human readable format. The corresponding 

22 # function is called Project().save_project() you can specify a file name 

23 # and a save path. If both are non (as in this case) it will use the 

24 # projects name and default path in your home folder. 

25 

26 prj.save_project(file_name=None, path=None) 

27 

28 # Second option is to use pickle from Python Standard Library , 

29 # which will save the whole Python classes and all attributes into a 

30 # binary file. There is no specific API function for this, but you can 

31 # simply create an empty file with open() and then use pickle.dump(). 

32 # Make sure you specify your path correctly. In this case we want to use 

33 # the default path of TEASERs output. 

34 

35 import pickle 

36 

37 pickle_file = os.path.join(utilities.get_default_path(), "teaser_pickle.p") 

38 

39 pickle.dump(prj, open(pickle_file, "wb")) 

40 

41 

42if __name__ == "__main__": 

43 example_save() 

44 

45 print("Example 4: That's it! :)")