1
0
Fork 0
mirror of https://github.com/Findus23/halo_comparison.git synced 2024-09-19 16:03:50 +02:00
halo_comparison/utils.py

41 lines
1 KiB
Python
Raw Normal View History

2022-06-14 10:53:19 +02:00
from pathlib import Path
from typing import Tuple
2022-05-06 09:51:43 +02:00
import pandas as pd
2022-06-14 10:53:19 +02:00
import yaml
from matplotlib import pyplot as plt
2022-06-01 12:12:45 +02:00
from matplotlib.axes import Axes
from matplotlib.figure import Figure
2022-05-06 09:51:43 +02:00
def print_progress(i, total, extra_data=""):
print(f"{i} of {total} ({extra_data})" + " " * 20, end="\r" if i != total else "\n", flush=True)
def memory_usage(df: pd.DataFrame):
bytes_used = df.memory_usage(index=True).sum()
return bytes_used / 1024 / 1024
2022-06-14 10:53:19 +02:00
def create_figure() -> Tuple[Figure, Axes]:
"""
helper function for matplotlib OOP interface with proper typing
"""
fig: Figure = plt.figure()
ax: Axes = fig.gca()
return fig, ax
2022-06-14 10:53:19 +02:00
def read_swift_config(dir: Path):
with (dir / "used_parameters.yml").open() as f:
return yaml.safe_load(f)
2022-07-05 15:41:01 +02:00
def print_wall_time(dir: Path):
with(dir / "swift.log").open() as f:
last_line = f.readlines()[-1]
print(last_line)
assert "main: done. Bye." in last_line
seconds = float(last_line[1:].split("]")[0])
print(f"Runtime: {seconds / 60 / 60:.2f} hours")