Skip to content

Commit 622a9e2

Browse files
committed
Implement polarized property
RE mantidproject#38523
1 parent 454a8e4 commit 622a9e2

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SANS/SANSSave.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
from sans.common.constant_containers import SANSInstrument_string_as_key_NoInstrument
1717
from sans.common.enums import SaveType
1818

19+
FILE_FORMAT_DOC_SUFFIX = (
20+
"Note that if file formats of the same type, e.g. .xml are chosen, then the file format is appended to the file name."
21+
)
22+
1923

2024
class SANSSave(DataProcessorAlgorithm):
2125
def category(self):
@@ -50,54 +54,49 @@ def PyInit(self):
5054
"Nexus",
5155
False,
5256
direction=Direction.Input,
53-
doc="Save as nexus format. "
54-
"Note that if file formats of the same type, e.g. .xml are chosen, then the "
55-
"file format is appended to the file name.",
57+
doc="Save as nexus format. " + FILE_FORMAT_DOC_SUFFIX,
5658
)
5759
self.declareProperty(
5860
"CanSAS",
5961
False,
6062
direction=Direction.Input,
61-
doc="Save as CanSAS xml format."
62-
"Note that if file formats of the same type, e.g. .xml are chosen, then the "
63-
"file format is appended to the file name.",
63+
doc="Save as CanSAS xml format. " + FILE_FORMAT_DOC_SUFFIX,
6464
)
6565
self.declareProperty(
6666
"NXcanSAS",
6767
False,
6868
direction=Direction.Input,
69-
doc="Save as NXcanSAS format."
70-
"Note that if file formats of the same type, e.g. .xml are chosen, then the "
71-
"file format is appended to the file name.",
69+
doc="Save as NXcanSAS format. " + FILE_FORMAT_DOC_SUFFIX,
70+
)
71+
self.declareProperty(
72+
"PolarizedNXcanSAS",
73+
False,
74+
direction=Direction.Input,
75+
doc="Save in PolarizedNXcanSAS format. " + FILE_FORMAT_DOC_SUFFIX,
7276
)
7377
self.declareProperty(
7478
"NistQxy",
7579
False,
7680
direction=Direction.Input,
77-
doc="Save as Nist Qxy format."
78-
"Note that if file formats of the same type, e.g. .xml are chosen, then the "
79-
"file format is appended to the file name.",
81+
doc="Save as Nist Qxy format. " + FILE_FORMAT_DOC_SUFFIX,
8082
)
8183
self.declareProperty(
8284
"RKH",
8385
False,
8486
direction=Direction.Input,
85-
doc="Save as RKH format."
86-
"Note that if file formats of the same type, e.g. .xml are chosen, then the "
87-
"file format is appended to the file name.",
87+
doc="Save as RKH format. " + FILE_FORMAT_DOC_SUFFIX,
8888
)
8989
self.declareProperty(
9090
"CSV",
9191
False,
9292
direction=Direction.Input,
93-
doc="Save as CSV format."
94-
"Note that if file formats of the same type, e.g. .xml are chosen, then the "
95-
"file format is appended to the file name.",
93+
doc="Save as CSV format. " + FILE_FORMAT_DOC_SUFFIX,
9694
)
9795

9896
self.setPropertyGroup("Nexus", "FileFormats")
9997
self.setPropertyGroup("CanSAS", "FileFormats")
10098
self.setPropertyGroup("NXCanSAS", "FileFormats")
99+
self.setPropertyGroup("PolarizedNXcanSAS", "FileFormats")
101100
self.setPropertyGroup("NistQxy", "FileFormats")
102101
self.setPropertyGroup("RKH", "FileFormats")
103102
self.setPropertyGroup("CSV", "FileFormats")
@@ -239,6 +238,7 @@ def validateInputs(self):
239238
errors.update({"Nexus": "At least one data format needs to be specified."})
240239
errors.update({"CanSAS": "At least one data format needs to be specified."})
241240
errors.update({"NXcanSAS": "At least one data format needs to be specified."})
241+
errors.update({"PolarizedNXcanSAS": "At least one data format needs to be specified"})
242242
errors.update({"NistQxy": "At least one data format needs to be specified."})
243243
errors.update({"RKH": "At least one data format needs to be specified."})
244244
errors.update({"CSV": "At least one data format needs to be specified."})
@@ -252,8 +252,8 @@ def validateInputs(self):
252252
" only. This requires all axes to be numeric."
253253
}
254254
)
255-
polarization_props = self.getProperty("PolarizationProps").value
256-
if len(polarization_props) > 0:
255+
if self.getProperty("PolarizedNXcanSAS"):
256+
polarization_props = self.getProperty("PolarizationProps").value
257257
# TODO: Get these directly from the algorithm.
258258
mandatory_props = [
259259
"InputSpinStates",
@@ -275,6 +275,7 @@ def _get_file_formats(self):
275275
self._check_file_types(file_types, "Nexus", SaveType.NEXUS)
276276
self._check_file_types(file_types, "CanSAS", SaveType.CAN_SAS)
277277
self._check_file_types(file_types, "NXcanSAS", SaveType.NX_CAN_SAS)
278+
self._check_file_types(file_types, "PolarizedNXcanSAS", SaveType.POL_NX_CAN_SAS)
278279
self._check_file_types(file_types, "NistQxy", SaveType.NIST_QXY)
279280
self._check_file_types(file_types, "RKH", SaveType.RKH)
280281
self._check_file_types(file_types, "CSV", SaveType.CSV)
@@ -289,6 +290,9 @@ def _get_file_formats(self):
289290
# SaveNXcanSAS clashes with SaveNexusProcessed
290291
self.add_file_format_with_appended_name_requirement(file_formats, SaveType.NX_CAN_SAS, file_types, [])
291292

293+
# SavePolarizedNXcanSAS clashes with SaveNXcanSAS
294+
self.add_file_format_with_appended_name_requirement(file_formats, SaveType.POL_NX_CAN_SAS, file_types, [SaveType.NX_CAN_SAS])
295+
292296
# SaveNISTDAT clashes with SaveRKH, both can save to .dat
293297
self.add_file_format_with_appended_name_requirement(file_formats, SaveType.NIST_QXY, file_types, [SaveType.RKH])
294298

scripts/SANS/sans/algorithm_detail/save_workspace.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def get_save_strategy(file_format_bundle, file_name, save_options, additional_pr
6161
save_name = "SaveNXcanSAS"
6262
save_options.update(additional_properties)
6363
save_options.update(additional_run_numbers)
64+
elif file_format is SaveType.POL_NX_CAN_SAS:
65+
file_name = get_file_name(file_format_bundle, file_name, "_polnxcansas", ".h5")
66+
save_name = "SavePolarizedNXcanSAS"
67+
save_options.update(additional_properties)
68+
save_options.update(additional_run_numbers)
6469
elif file_format is SaveType.NIST_QXY:
6570
file_name = get_file_name(file_format_bundle, file_name, "_nistqxy", ".dat")
6671
save_name = "SaveNISTDAT"

scripts/SANS/sans/common/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class SaveType(Enum):
200200
NIST_QXY = "NistQxy"
201201
NO_TYPE = "NoType"
202202
NX_CAN_SAS = "NXcanSAS"
203+
POL_NX_CAN_SAS = "PolarizedNXcanSAS"
203204
RKH = "RKH"
204205

205206

0 commit comments

Comments
 (0)