Skip to content

Commit

Permalink
Merge pull request #85 from NDF-Poli-USP/changing_parallel_saves
Browse files Browse the repository at this point in the history
added parallel support to custom file names
  • Loading branch information
Olender authored Feb 7, 2023
2 parents 6f14329 + c72d87b commit 282f5e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions spyro/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ def wrapper(*args, **kwargs):
)
)
else:
func(*args, **dict(kwargs, file_name=custom_file_name))

func(
*args,
**dict(
kwargs,
file_name=custom_file_name+"shot_record_" + str(snum + 1) + ".dat"
)
)
return wrapper


Expand All @@ -54,7 +59,13 @@ def wrapper(*args, **kwargs):
)
)
else:
values = func(*args, **dict(kwargs, file_name=custom_file_name))
values = func(
*args,
**dict(
kwargs,
file_name=custom_file_name+"shot_record_" + str(snum + 1) + ".dat"
)
)
return values

return wrapper
Expand All @@ -67,9 +78,13 @@ def wrapper(*args, **kwargs):
acq = args[0].get("acquisition")
num = len(acq["source_pos"])
_comm = args[1]
custom_file_name = kwargs.get("file_name")
for snum in range(num):
if is_owner(_comm, snum) and _comm.comm.rank == 0:
func(*args, **dict(kwargs, file_name=str(snum + 1)))
if custom_file_name is None:
func(*args, **dict(kwargs, file_name="shot_number_" + str(snum + 1)))
else:
func(*args, **dict(kwargs, file_name=custom_file_name + str(snum + 1)))

return wrapper

Expand Down Expand Up @@ -215,7 +230,7 @@ def save_shots(model, comm, array, file_name=None):
Parameters
----------
filename: str, optional by default shot_number_#.dat
file_name: str, optional by default shot_record_#.dat
The filename to save the data as a `pickle`
array: `numpy.ndarray`
The data to save a pickle (e.g., a shot)
Expand Down
2 changes: 1 addition & 1 deletion spyro/plots/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def plot_shots(
plt.xlim(start_index, end_index)
plt.ylim(tf, 0)
plt.subplots_adjust(left=0.18, right=0.95, bottom=0.14, top=0.95)
plt.savefig("shot_number_" + file_name + "." + file_format, format=file_format)
plt.savefig(file_name + "." + file_format, format=file_format)
# plt.axis("image")
if show:
plt.show()
Expand Down

0 comments on commit 282f5e6

Please sign in to comment.