1313 Process ,
1414)
1515from sasdata .quantities import unit_parser , units
16+ from collections import defaultdict
1617from itertools import groupby
1718import re
1819import numpy as np
@@ -24,7 +25,7 @@ def parse_version(lines: list[str]) -> tuple[str, list[str]]:
2425
2526 if m is None :
2627 raise FileContentsException (
27- "Alleged Sesans file does not contain File Format Version header"
28+ "Sesans file does not contain File Format Version header"
2829 )
2930
3031 return (m .group (0 ), lines [1 :])
@@ -48,12 +49,6 @@ def parse_kvs_quantity(key: str, kvs: dict[str, str]) -> Quantity | None:
4849 return Quantity (value = float (kvs [key ]), units = unit_parser .parse (kvs [key + "_unit" ]))
4950
5051
51- def parse_kvs_text (key : str , kvs : dict [str , str ]) -> str | None :
52- if key not in kvs :
53- return None
54- return kvs [key ]
55-
56-
5752def parse_sample (kvs : dict [str , str ]) -> Sample :
5853 """Get the sample info from the key value store"""
5954
@@ -64,7 +59,7 @@ def parse_sample(kvs: dict[str, str]) -> Sample:
6459 )
6560
6661 return Sample (
67- name = parse_kvs_text ("Sample" , kvs ),
62+ name = kvs . get ("Sample" ),
6863 sample_id = None ,
6964 thickness = thickness ,
7065 transmission = None ,
@@ -78,7 +73,7 @@ def parse_sample(kvs: dict[str, str]) -> Sample:
7873def parse_process (kvs : dict [str , str ]) -> Process :
7974 ymax = parse_kvs_quantity ("Theta_ymax" , kvs )
8075 zmax = parse_kvs_quantity ("Theta_zmax" , kvs )
81- orientation = parse_kvs_text ("Orientation" , kvs )
76+ orientation = kvs . get ("Orientation" )
8277
8378 if ymax is None :
8479 raise FileContentsException ("SES file must specify Theta_ymax" )
@@ -160,7 +155,6 @@ def parse_metadata(lines: list[str]) -> tuple[Metadata, dict[str, str], list[str
160155
161156
162157def parse_data (lines : list [str ], kvs : dict [str , str ]) -> dict [str , Quantity ]:
163- from collections import defaultdict
164158
165159 data_contents : dict [str , Quantity ] = {}
166160 headers = lines [0 ].split ()
@@ -191,12 +185,9 @@ def parse_data(lines: list[str], kvs: dict[str, str]) -> dict[str, Quantity]:
191185 standard_error = error ,
192186 )
193187
194- if "SpinEchoLength" not in data_contents :
195- raise FileContentsException ("SES file missing Spin Echo Length" )
196- if "Depolarisation" not in data_contents :
197- raise FileContentsException ("SES file missing Depolarisation" )
198- if "Wavelength" not in data_contents :
199- raise FileContentsException ("SES file missing Wavelength" )
188+ for required in ["SpinEchoLEngth" , "Depolarisation" , "Wavelength" ]:
189+ if required not in data_contents :
190+ raise FileContentsException (f"SES file missing { required } " )
200191
201192 return data_contents
202193
0 commit comments