Skip to content

Commit

Permalink
more changes to allow to choose the name for the .csv and .png result…
Browse files Browse the repository at this point in the history
… files (#25)

* plot_timings.py accepts the input csv as a --input option

* allow to choose an output csv file from reproducing-results-notebook.py as well
  • Loading branch information
parmentelat authored Jun 19, 2024
1 parent 515ee78 commit e1c3922
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
18 changes: 14 additions & 4 deletions paper/plot_timings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
running out of memory.
"""

from argparse import ArgumentParser
from pathlib import Path

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import numpy as np
Expand All @@ -36,7 +39,7 @@ def remove_rows_where_all_values_except_time_are_same(df):
---------
df : pd.DataFrame
The input DataFrame.
Returns:
pd.DataFrame: The DataFrame with duplicate rows removed.
"""
Expand Down Expand Up @@ -202,7 +205,13 @@ def plot_timings(


if __name__ == "__main__":
df = pd.read_csv("timings/user_timings.csv")
parser = ArgumentParser()
parser.add_argument("-i", "--input", type=str, default="timings/user_timings.csv",
help="Input file to read timings from.")
args = parser.parse_args()
output = Path(args.input).with_suffix(".png")

df = pd.read_csv(args.input)
df = remove_rows_where_all_values_except_time_are_same(df)

plt.rcParams.update({"font.size": 10})
Expand Down Expand Up @@ -429,7 +438,7 @@ def plot_timings(
bbox_transform=plt.gcf().transFigure,
)
plt.gca().add_artist(first_legend)

ikpls_version_text = f"ikpls version: {ikpls.__version__}"

fig.text(
Expand Down Expand Up @@ -457,4 +466,5 @@ def plot_timings(
fig.patches.extend([rect1, rect2, rect11, rect12, rect21, rect22])
# fig.tight_layout()
plt.subplots_adjust(bottom=0.06, hspace=0.3, wspace=0.2, left=0.1, right=0.95)
plt.savefig(f"timings/user_timings.png")
plt.savefig(str(output))
print(f"output saved to {output}")
23 changes: 22 additions & 1 deletion paper/reproducing-results-notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@
# these are used as a cache - i.e. not re-run if already present; you can simply delete or move this file if you want to re-start from scratch

# %%
# this one must not change
REF_TIMINGS = "timings/timings.csv"

# default - see next cell for how to change it
OUR_TIMINGS = "timings/user_timings.csv"

# %%
# provide a way to choose the output from the command line
# but argparse won't work from Jupyter, so:

try:
# this is defined in a Jupyter / IPython environment
# in this case just change OUR_TIMINGS above
get_ipython()
except:
# not in IPython/notebook - so we run from the command line
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-o", "--output", default=OUR_TIMINGS, help="filename for the csv output")
args = parser.parse_args()
OUR_TIMINGS = args.output

print(f"using {OUR_TIMINGS=}")

# %% [markdown]
# ## loading the paper timings
#
Expand Down Expand Up @@ -109,7 +130,7 @@ def status():
else:
join = pd.merge(focus, previous, on=KEYS, how='left')
missing = join[join.previous.isna()]


# %%
missing
Expand Down

0 comments on commit e1c3922

Please sign in to comment.