diff --git a/data.py b/data.py index a9486c8ec7cce2740cfec46519084880f27697a5..46bfc8128b287ac4744f112632756985cbd9a288 100644 --- a/data.py +++ b/data.py @@ -326,12 +326,13 @@ class NWAData(Trace): p_unit: str = 'a.u.' @classmethod - def from_file(cls, magfile, phasefile=None, unwrap=False, verbose=0): + def from_file(cls, magfile, phasefile=None, *, isdeg=True, unwrap=False, verbose=0): """Read in data from CSV file for magnitude and phase :param magfile: path to filename with magnitude trace data :param phasefile: path to filename with phase trace data. If None, phase data is assumed to be the second column in magfile. :param unwrap: if true, relative phase is unwraped to absolute phase centered around zero + :param isdeg: if phase data is in degree (True) or radians (False) """ f, m, *other = np.loadtxt(magfile, skiprows=3, delimiter=',').T if phasefile is None: @@ -342,8 +343,10 @@ class NWAData(Trace): raise ValueError('Files provided do not have equal frequency components.') if unwrap: + if isdeg: p = np.deg2rad(p) p = np.unwrap(p) p -= np.mean(p) + if isdeg: p = np.rad2deg(p) - return NWAData(f, m, p) + return NWAData(f, m, p, p_unit='deg' if isdeg else 'rad')