Skip to content

Commit 505a31c

Browse files
committed
Move dump_hdf5() into base class
This can be used by Rietveld also Signed-off-by: Patrick Avery <[email protected]>
1 parent 9e21dc4 commit 505a31c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

hexrd/wppf/WPPF.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ def __str__(self):
7070
resstr += self.params.__str__()
7171
return resstr
7272

73+
def dump_hdf5(self, file):
74+
"""
75+
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,
76+
77+
>> @DATE: 01/19/2021 SS 1.0 original
78+
>> @DETAILS: write out the hdf5 file with all the spectrum, parameters
79+
and phases pecified by filename or h5py.File object
80+
"""
81+
if isinstance(file, str):
82+
fexist = path.isfile(file)
83+
if fexist:
84+
fid = h5py.File(file, "r+")
85+
else:
86+
fid = h5py.File(file, "x")
87+
88+
elif isinstance(file, h5py.File):
89+
fid = file
90+
91+
else:
92+
raise RuntimeError(
93+
"Parameters: dump_hdf5 Pass in a filename \
94+
string or h5py.File object"
95+
)
96+
97+
self.phases.dump_hdf5(fid)
98+
self.params.dump_hdf5(fid)
99+
self.spectrum_expt.dump_hdf5(fid, "experimental")
100+
self.spectrum_sim.dump_hdf5(fid, "simulated")
101+
self.background.dump_hdf5(fid, "background")
102+
73103
def params_vary_off(self):
74104
"""
75105
no params are varied
@@ -1019,36 +1049,6 @@ def _get_phase(self, name: str, wavelength_type: str):
10191049
# LeBail just ignores the wavelength type for phases
10201050
return self.phases[name]
10211051

1022-
def dump_hdf5(self, file):
1023-
"""
1024-
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab,
1025-
1026-
>> @DATE: 01/19/2021 SS 1.0 original
1027-
>> @DETAILS: write out the hdf5 file with all the spectrum, parameters
1028-
and phases pecified by filename or h5py.File object
1029-
"""
1030-
if isinstance(file, str):
1031-
fexist = path.isfile(file)
1032-
if fexist:
1033-
fid = h5py.File(file, "r+")
1034-
else:
1035-
fid = h5py.File(file, "x")
1036-
1037-
elif isinstance(file, h5py.File):
1038-
fid = file
1039-
1040-
else:
1041-
raise RuntimeError(
1042-
"Parameters: dump_hdf5 Pass in a filename \
1043-
string or h5py.File object"
1044-
)
1045-
1046-
self.phases.dump_hdf5(fid)
1047-
self.params.dump_hdf5(fid)
1048-
self.spectrum_expt.dump_hdf5(fid, "experimental")
1049-
self.spectrum_sim.dump_hdf5(fid, "simulated")
1050-
self.background.dump_hdf5(fid, "background")
1051-
10521052
def initialize_Icalc(self):
10531053
"""
10541054
@DATE 01/22/2021 SS modified the function so Icalc can be initialized

0 commit comments

Comments
 (0)