11# --- import --------------------------------------------------------------------------------------
22
33
4- import os
54import pathlib
65import warnings
76import time
@@ -46,7 +45,6 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data:
4645 New data object(s).
4746 """
4847 # parse filepath
49- filestr = os .fspath (filepath )
5048 filepath = pathlib .Path (filepath )
5149
5250 if not ".txt" in filepath .suffixes :
@@ -55,7 +53,7 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data:
5553 if not name :
5654 name = filepath .name .split ("." )[0 ]
5755
58- kwargs = {"name" : name , "kind" : "Horiba" , "source" : filestr }
56+ kwargs = {"name" : name , "kind" : "Horiba" , "source" : str ( filepath ) }
5957
6058 # create data
6159 if parent is None :
@@ -64,7 +62,7 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data:
6462 data = parent .create_data (** kwargs )
6563
6664 ds = DataSource (None )
67- f = ds .open (filestr , "rt" , encoding = "ISO-8859-1" )
65+ f = ds .open (str ( filepath ) , "rt" , encoding = "ISO-8859-1" )
6866
6967 # header
7068 header = {}
@@ -110,7 +108,7 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data:
110108 # dimensionality
111109 extra_dims = np .isnan (wm ).sum ()
112110
113- if extra_dims == 0 : # single spectrum; we extracted wm wrong, so go back in file
111+ if not extra_dims : # single spectrum; we extracted wm wrong, so go back in file
114112 f .seek (0 )
115113 wm , arr = np .genfromtxt (f , delimiter = "\t " , unpack = True )
116114 f .close ()
@@ -121,13 +119,13 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data:
121119 arr = np .genfromtxt (f , delimiter = "\t " )
122120 f .close ()
123121 wm = wm [extra_dims :]
122+ x = arr [:, 0 ]
124123
125124 if extra_dims == 1 : # spectrum vs (x or survey)
126125 data .create_variable ("wm" , values = wm [:, None ], units = spectral_units )
127126 data .create_channel (
128127 "signal" , values = arr [:, 1 :].T / acquisition_time , units = channel_units
129128 )
130- x = arr [:, 0 ]
131129 if np .all (x == np .arange (x .size ) + 1 ): # survey
132130 data .create_variable ("index" , values = x [None , :])
133131 data .transform ("wm" , "index" )
@@ -136,9 +134,7 @@ def from_LabRAM(filepath, name=None, parent=None, verbose=True) -> Data:
136134 data .transform ("wm" , "x" )
137135 elif extra_dims == 2 : # spectrum vs x vs y
138136 # fold to 3D
139- x = sorted (
140- set (arr [:, 0 ]), reverse = arr [0 , 0 ] > arr [- 1 , 0 ]
141- ) # 0th column is stepped always (?)
137+ x = sorted (set (x ), reverse = bool (x [0 ] > x [- 1 ])) # 0th column is stepped always (?)
142138 x = np .array (list (x ))
143139 x = x .reshape (1 , - 1 , 1 )
144140 y = arr [:, 1 ].reshape (1 , x .size , - 1 )
0 commit comments