Skip to content

Commit

Permalink
Modify parse_frequency function to avoid errors when the SKEAF output…
Browse files Browse the repository at this point in the history
… file is empty (#7)
  • Loading branch information
npaulish committed May 27, 2024
1 parent 63eda66 commit e3d07bb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions aiida_skeaf/parsers/skeaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def parse_frequency(filecontent: ty.List[str]) -> orm.ArrayData:
ndmin=1, # at least 1 dim even if there's single freq in output
)

# in the older numpy versions, e.g. 1.22.4, after reading empty file,
# freq.shape = (0,1), which causes an error when setting arrays, e.g. array.set_array("phi", freq[:, 1])
# to avoid dependency on numpy version, we check if freq is empty and reshape it to (0,6)
if len(freq) == 0 and freq.shape[1] != 6:
freq = freq.reshape(freq.shape[0], 6)

array.set_array("theta", freq[:, 0])
array.set_array("phi", freq[:, 1])
array.set_array("freq", freq[:, 2])
Expand Down

0 comments on commit e3d07bb

Please sign in to comment.