Skip to content

Commit

Permalink
create new function
Browse files Browse the repository at this point in the history
  • Loading branch information
simongravelle committed Nov 18, 2023
1 parent c970576 commit 2d2dba4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"git_path = git_repo.git.rev_parse(\"--show-toplevel\")\n",
"sys.path.append(git_path+\"/docs/inputs/shared-pyplot-files/\")\n",
"from pyplot_parameters import colors, complete_panel, save_figure, set_boundaries, \\\n",
" add_subplotlabels # set_boundaries\n",
" add_subplotlabels, import_ave_time # set_boundaries\n",
"path_in_folder = current_path[len(git_path)+1:]\n",
"level = path_in_folder.split(\"/\")[2][-1]\n",
"tutorial_name = path_in_folder.split(\"/\")[3]\n",
Expand All @@ -42,29 +42,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def import_ave_time(filename):\n",
" assert filename[:6] == \"output\"\n",
" if os.path.exists(filename):\n",
" data = np.loadtxt(filename)\n",
" try:\n",
" time, data = data.T\n",
" except:\n",
" time, data, _ = data.T\n",
" if os.path.exists(\"data_plot/\") is False:\n",
" os.mkdir(\"data_plot/\")\n",
" np.savetxt(\"data_plot/\"+filename[7:], np.vstack([time, data]).T)\n",
" else:\n",
" time, data = np.loadtxt(\"data_plot/\"+filename[7:]).T\n",
" return time, data"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -77,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down
18 changes: 17 additions & 1 deletion docs/inputs/shared-pyplot-files/pyplot_parameters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from matplotlib.ticker import AutoMinorLocator
Expand Down Expand Up @@ -136,4 +137,19 @@ def set_boundaries(plt, x_boundaries=None, x_ticks=None, y_boundaries=None, y_ti
if y_boundaries is not None:
plt.ylim(y_boundaries)
if y_ticks is not None:
plt.yticks(y_ticks)
plt.yticks(y_ticks)

def import_ave_time(filename):
assert filename[:6] == "output"
if os.path.exists(filename):
data = np.loadtxt(filename)
try:
time, data = data.T
except:
time, data, _ = data.T
if os.path.exists("data_plot/") is False:
os.mkdir("data_plot/")
np.savetxt("data_plot/"+filename[7:], np.vstack([time, data]).T)
else:
time, data = np.loadtxt("data_plot/"+filename[7:]).T
return time, data

0 comments on commit 2d2dba4

Please sign in to comment.