Skip to content

Commit

Permalink
feat: add skip cloud save
Browse files Browse the repository at this point in the history
cloud saves were previously required, which meant you needed to
setup the kachery-cloud connection (setting up account and registering
your machine) and so this allows for skipping this step for anyone
who wants to pickle their plots to have for reference, but doesn't
want to have to setup kachery-cloud.

resolves #11
  • Loading branch information
joey-kilgore committed Feb 1, 2025
1 parent a7b6433 commit 0184921
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/SimLogger/FigLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def createPlot(
title="Plot",
labels={"x": "x", "y": "y", "z": "z"},
makeNote=True,
cloudSave=True,
**kwargs,
):
"""Generate a plot that will automatically be saved (using SimLogger)
Expand All @@ -35,10 +36,12 @@ def createPlot(
labels ({str:str}): Key value pairs for the keys "x", "y", ("z") that go to
the values corresponding to the axis labels
makeNote (bool): Whether the log should be noted with the saved files
cloudSave (bool): optionally save to the cloud (default True)
**kwargs: Additional args for the plotly express graph
Returns:
url (str): The figurl link to access the graph
url (str): The figurl link to access the graph.
Returns None if cloud save not chosen
"""
data = {"x": x, "y": y}
if z is not None:
Expand All @@ -59,13 +62,25 @@ def createPlot(
raise ValueError("Unsupported plotType. Supported types: 'scatter', 'line'.")

url = savePlotly(
simTag, objTag, fig, label=title, objFolder=objFolder, makeNote=makeNote
simTag,
objTag,
fig,
label=title,
objFolder=objFolder,
makeNote=makeNote,
cloudSave=cloudSave,
)
return url


def savePlotly(
simTag, objTag, ff, label="", objFolder=os.path.join("data", "obj"), makeNote=True
simTag,
objTag,
ff,
label="",
objFolder=os.path.join("data", "obj"),
makeNote=True,
cloudSave=True,
):
"""Save a previously created plotly graph to the cloud for remote access
and pickle the graph for access later
Expand All @@ -77,14 +92,19 @@ def savePlotly(
label (str): Optional label for the figurl cloud saved graph
objFolder (str): location where the pickled objects should go
makeNote (str): Note in the log that the pickled file was saved
cloudSave (bool): save the figure to cloud
Returns:
url (str): The figurl link to access the graph
url (str): The figurl link to access the graph.
Returns None if not saving to the cloud
"""
if label == "":
label = objTag
url = fig.Plotly(ff).url(label=label)
SimLogger.logNotes(f"{label} GRAPH AVAILABLE AT: {url}")

url = None
if cloudSave:
url = fig.Plotly(ff).url(label=label)
SimLogger.logNotes(f"{label} GRAPH AVAILABLE AT: {url}")
SimLogger.saveObj(simTag, objTag, ff, objFolder=objFolder, makeNote=makeNote)

return url
12 changes: 12 additions & 0 deletions tests/test_FigLogger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from SimLogger import SimLogger, FigLogger


def test_graph_save():
x = [0, 1, 2, 3]
y = [1, 2, 3, 4]
simTag = "testing-simTag"
objTag = "testing-graph"
FigLogger.createPlot(simTag, objTag, x, y, cloudSave=False)
loadedFig = SimLogger.getObj(simTag, objTag)
assert list(loadedFig["data"][0]["x"]) == x
assert list(loadedFig["data"][0]["y"]) == y

0 comments on commit 0184921

Please sign in to comment.