Last active
April 4, 2019 21:18
-
-
Save SuborbitalPigeon/329645b953fc6f3b598d202078ab96f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Probe: | |
required_string = ['type'] | |
string = ['probe_manufacturer', 'probe_serial_number', 'probe_tag', | |
'wedge_manufacturer', 'wedge_serial_number', 'wedge_tag'] | |
required_other = ['element_position', 'element_minor', 'element_major', | |
'element_shape', 'centre_frequency'] | |
other = ['element_radius_of_curvature', 'element_axis_of_curvature', | |
'wedge_surface_point', 'wedge_surface_normal', 'dead_element', | |
'bandwidth'] | |
def __init__(self, probe_dataset): | |
self._probe = probe_dataset | |
def __getattr__(self, name): | |
if name in Probe.required_string: | |
return self._probe[name].decode('ascii') | |
elif name in Probe.required_other: | |
return self._probe[name] | |
try: | |
if name in Probe.string: | |
return self._probe[name].decode('ascii') | |
elif name in Probe.other: | |
return self._probe[name] | |
except KeyError: | |
raise OptionalKey("Optional key") | |
raise AttributeError("No such data field") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some of these are attributes, so need accessed using probe.attrs.