From d5ac9431967fb82defa3cc94f0554e7b1f34dd07 Mon Sep 17 00:00:00 2001 From: Dennis Buecker Date: Mon, 1 Mar 2021 15:08:17 +0100 Subject: [PATCH 01/10] Change argument order in reshape to have correct mapping for 2D data (see dataset) --- deerlab/deerload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index b3dc432e4..8a7ec38c1 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -208,7 +208,7 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): warn("Keyword IKKF not found in .DSC file! Assuming IKKF=REAL.") if nz == 1: - data = data.reshape(nx,ny) + data = data.reshape(ny,nx) # ns -> us converesion abscissa /= 1e3 From 22230d92313d0c2a7cf24e3d2f65f7460854f518 Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 16:53:31 +0100 Subject: [PATCH 02/10] Revert "Change argument order in reshape to have correct mapping for 2D data (see dataset)" This reverts commit d5ac9431967fb82defa3cc94f0554e7b1f34dd07. --- deerlab/deerload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index 8a7ec38c1..b3dc432e4 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -208,7 +208,7 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): warn("Keyword IKKF not found in .DSC file! Assuming IKKF=REAL.") if nz == 1: - data = data.reshape(ny,nx) + data = data.reshape(nx,ny) # ns -> us converesion abscissa /= 1e3 From fd011c176670c3e6531354dc95a9c3ba8b47a0ad Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 17:44:41 +0100 Subject: [PATCH 03/10] deerload: remove line leading to reshaping bug --- deerlab/deerload.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index b3dc432e4..c240aa3e3 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -186,7 +186,6 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): data = np.copy(data) elif parDESC['IKKF'] == 'CPLX': dt_new = np.dtype('complex') - data = np.full((2*nx*ny*nz,1),np.nan) with open(filename_dta,'rb') as fp: data = np.frombuffer(fp.read(),dtype=dt_spc) # Check if there is multiple harmonics (High field ESR quadrature detection) From 96da39f9e18b923810d48891a5a6c5e0ede5de72 Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 17:45:23 +0100 Subject: [PATCH 04/10] deerload: return abscissa as list of arrays instead of matrix --- deerlab/deerload.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index c240aa3e3..5881612ad 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -167,12 +167,9 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): abscissa[:Dimensions[index],index] = np.linspace(minimum,minimum+width,npts) if axistype == 'NTUP': raise ValueError('Cannot read data with NTUP axes.') - - # In case of column filled with NaN, erase the column in the array - abscissa = abscissa[:,~np.isnan(abscissa).all(axis=0)] + dt_data = dt_spc dt_spc = dt_spc.newbyteorder(byteorder) - # Read data matrix and separate complex case from real case. data = np.full((nx,ny,nz),np.nan) # reorganize the data in a "complex" way as the real part and the imaginary part are separated @@ -198,7 +195,7 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): n_harmonics = sum(harmonics)[0] if n_harmonics != 0: ny = int(len(data)/nx/n_harmonics) - + # copy the data to a writable numpy array data = np.copy(data.astype(dtype=dt_data).view(dtype=dt_new).reshape(nx,ny,nz)) else: @@ -208,15 +205,25 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): if nz == 1: data = data.reshape(nx,ny) - - # ns -> us converesion - abscissa /= 1e3 + # Ensue proper numpy formatting - abscissa,data = np.atleast_1d(abscissa,data) - abscissa = np.squeeze(abscissa) + data = np.atleast_1d(data) data = np.squeeze(data) + # Abscissa formatting + abscissa = np.atleast_1d(abscissa) + abscissa = np.squeeze(abscissa) + abscissas = [] + # Convert to list of abscissas + for absc in abscissa.T: + # Do not include abcissas full of NaNs + if not all(np.isnan(absc)): + # ns -> us converesion + absc /= 1e3 + # Remove nan values to ensure proper length of abscissa + abscissas.append(absc[~np.isnan(absc)]) + if plot: plt.plot(abscissa,np.real(data),abscissa,np.imag(data)) plt.xlabel("Time (μs)") @@ -225,9 +232,9 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): plt.show() if full_output: - return abscissa, data, parameters + return abscissas, data, parameters else: - return abscissa, data + return abscissas, data def read_description_file(DSCFileName): From ec2eb851ab42616605c07f39dd29254178c2ff23 Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 18:46:05 +0100 Subject: [PATCH 05/10] deerload: fix splitting of 1D-arrays into 3D-array --- deerlab/deerload.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index 5881612ad..1154947b4 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -63,7 +63,7 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): parameters = read_description_file(filename_dsc) parDESC = parameters["DESC"] parSPL = parameters["SPL"] - + print( int(parDESC['XPTS'])) # XPTS, YPTS, ZPTS specify the number of data points along x, y and z. if 'XPTS' in parDESC: nx = int(parDESC['XPTS']) @@ -197,16 +197,18 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): ny = int(len(data)/nx/n_harmonics) # copy the data to a writable numpy array - data = np.copy(data.astype(dtype=dt_data).view(dtype=dt_new).reshape(nx,ny,nz)) + data = np.copy(data.astype(dtype=dt_data).view(dtype=dt_new)) + + # Split 1D-array according to XPTS/YPTS/ZPTS into 3D-array + data = np.array_split(data,nz) + data = np.array(data).T + data = np.array_split(data,ny) + data = np.array(data).T else: raise ValueError("Unknown value for keyword IKKF in .DSC file!") else: warn("Keyword IKKF not found in .DSC file! Assuming IKKF=REAL.") - if nz == 1: - data = data.reshape(nx,ny) - - # Ensue proper numpy formatting data = np.atleast_1d(data) data = np.squeeze(data) From fd3de7263ac4f6084bb5b6983784b1c409d918bc Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 18:46:52 +0100 Subject: [PATCH 06/10] deerload: refactor code --- deerlab/deerload.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index 1154947b4..ca60b90c8 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -179,7 +179,7 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): if parDESC['IKKF'] == 'REAL': data = np.full((nx,ny,nz),np.nan) with open(filename_dta,'rb') as fp: - data = np.frombuffer(fp.read(),dtype=dt_spc).reshape(nx,ny,nz) + data = np.frombuffer(fp.read(),dtype=dt_spc) data = np.copy(data) elif parDESC['IKKF'] == 'CPLX': dt_new = np.dtype('complex') @@ -198,17 +198,17 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): # copy the data to a writable numpy array data = np.copy(data.astype(dtype=dt_data).view(dtype=dt_new)) - - # Split 1D-array according to XPTS/YPTS/ZPTS into 3D-array - data = np.array_split(data,nz) - data = np.array(data).T - data = np.array_split(data,ny) - data = np.array(data).T else: raise ValueError("Unknown value for keyword IKKF in .DSC file!") else: warn("Keyword IKKF not found in .DSC file! Assuming IKKF=REAL.") + # Split 1D-array according to XPTS/YPTS/ZPTS into 3D-array + data = np.array_split(data,nz) + data = np.array(data).T + data = np.array_split(data,ny) + data = np.array(data).T + # Ensue proper numpy formatting data = np.atleast_1d(data) data = np.squeeze(data) From 1ac2f8e05c73bad5c4189e81b07465b0e7b93c69 Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 18:50:39 +0100 Subject: [PATCH 07/10] deerload: fix identiation error --- deerlab/deerload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index ca60b90c8..69fd6cdd6 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -203,7 +203,7 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): else: warn("Keyword IKKF not found in .DSC file! Assuming IKKF=REAL.") - # Split 1D-array according to XPTS/YPTS/ZPTS into 3D-array + # Split 1D-array into 3D-array according to XPTS/YPTS/ZPTS data = np.array_split(data,nz) data = np.array(data).T data = np.array_split(data,ny) From 3e5b314751d88eb737ade43707db18e085fe819e Mon Sep 17 00:00:00 2001 From: Luis Fabregas Date: Mon, 1 Mar 2021 18:50:54 +0100 Subject: [PATCH 08/10] deerload: return array instead of list for 1D-datasets --- deerlab/deerload.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index 69fd6cdd6..ecf508080 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -204,10 +204,10 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): warn("Keyword IKKF not found in .DSC file! Assuming IKKF=REAL.") # Split 1D-array into 3D-array according to XPTS/YPTS/ZPTS - data = np.array_split(data,nz) - data = np.array(data).T - data = np.array_split(data,ny) - data = np.array(data).T + data = np.array_split(data,nz) + data = np.array(data).T + data = np.array_split(data,ny) + data = np.array(data).T # Ensue proper numpy formatting data = np.atleast_1d(data) @@ -225,6 +225,10 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): absc /= 1e3 # Remove nan values to ensure proper length of abscissa abscissas.append(absc[~np.isnan(absc)]) + # If 1D-dataset, return array instead of single-element list + print(len(abscissas)) + if len(abscissas)==1: + abscissas = abscissas[0] if plot: plt.plot(abscissa,np.real(data),abscissa,np.imag(data)) From 1d7b70c05f212ce95f7dbff4fcd88f4ccbf2ae28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20B=C3=BCcker?= Date: Mon, 1 Mar 2021 22:00:27 +0100 Subject: [PATCH 09/10] deerlab/deerload.py remove print statement1 --- deerlab/deerload.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index ecf508080..47be46f76 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -63,7 +63,6 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): parameters = read_description_file(filename_dsc) parDESC = parameters["DESC"] parSPL = parameters["SPL"] - print( int(parDESC['XPTS'])) # XPTS, YPTS, ZPTS specify the number of data points along x, y and z. if 'XPTS' in parDESC: nx = int(parDESC['XPTS']) From 04014d306a25e7fa2c3b2dd60b3f96ac9e1f4bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20B=C3=BCcker?= Date: Mon, 1 Mar 2021 22:00:38 +0100 Subject: [PATCH 10/10] deerlab/deerload.py remove print statement --- deerlab/deerload.py | 1 - 1 file changed, 1 deletion(-) diff --git a/deerlab/deerload.py b/deerlab/deerload.py index 47be46f76..2e7bd5a67 100644 --- a/deerlab/deerload.py +++ b/deerlab/deerload.py @@ -225,7 +225,6 @@ def deerload(fullbasename, plot=False, full_output=False, *args,**kwargs): # Remove nan values to ensure proper length of abscissa abscissas.append(absc[~np.isnan(absc)]) # If 1D-dataset, return array instead of single-element list - print(len(abscissas)) if len(abscissas)==1: abscissas = abscissas[0]