-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
30 lines (22 loc) · 847 Bytes
/
utilities.py
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
# Pranav Minasandra
# pminasandra.github.io
# December 09, 2024
import inspect
import os
import os.path
import config
def saveimg(obj, name, directory=config.FIGURES):
"""
Saves given object to directory (default the FIGURES directory in config.py), with file formats chosen in config.py.
Args:
obj: a matplotlib object with a savefig method (plt or plt.Figure)
name (str): the name to be given to the file, *without* extensions.
"""
dirs = [os.path.join(directory, f) for f in config.formats]
for dir in dirs:
os.makedirs(dir, exist_ok=True)
for f in config.formats:
obj.savefig(os.path.join(directory, f, name+f".{f}"), dpi=500.0, format=f)
def sprint(*args, **kwargs):
filename = str(inspect.stack()[1].filename)
print(os.path.basename(filename)+":", *args, **kwargs)