Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions abel/classes/stage/impl/stage_hipace.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,20 @@ def __extract_initial_and_final_step(self, tmpfolder, beam0, runnable):
def _make_ramp_profile(self, tmpfolder):
"""Prepare the ramps (local to HiPACE)."""

# check that there is not already a plasma density profile set
assert self.plasma_density_from_file is None
# If there is already a density file open and make the plasma profile
if self.plasma_density_from_file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that self.plasma_density_from_file is type str.
Also catch non-existent file, e.g. raise ValueError with meaningful error message

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe here explicitly check that it is None, otherwise e.g. False (a bool) or 0 (an int) would have the same meaning as None here but maybe not everywhere else.

ss, ns = [], []
with open(self.plasma_density_from_file, 'r') as f:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch errors when reading / parsing file

for line in f:
s, n = line.strip().split()
ss.append(float(s))
ns.append(float(n))

ss = np.array(ss)
ns = np.array(ns)
self.plasma_profile.ss = ss
self.plasma_profile.ns = ns
return

# make the plasma ramp profile
if self.has_ramp():
Expand Down