Skip to content

Commit

Permalink
Merge 48ae501 into 5a9d0fe
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellerstedt committed May 1, 2019
2 parents 5a9d0fe + 48ae501 commit 24d9474
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions nanonispy/read.py
Expand Up @@ -115,6 +115,9 @@ def start_byte(self):

for line in f:
# Convert from bytes to str
#entry = line.strip().decode()
entry = line.strip().decode('utf-8', 'ignore')

try:
entry = line.strip().decode()
except UnicodeDecodeError:
Expand Down Expand Up @@ -225,9 +228,15 @@ def _load_data(self):

# pixel size in bytes
exp_size_per_pix = num_param + num_sweep*num_chan

## pad griddata if incomplete
if len(griddata) < nx * ny * exp_size_per_pix:
paddiff = nx * ny * exp_size_per_pix - len(griddata)
griddata = np.pad(griddata, (0, paddiff), 'constant')

# reshape from 1d to 3d
griddata_shaped = griddata.reshape((nx, ny, exp_size_per_pix))
# griddata_shaped = griddata.reshape((nx, ny, exp_size_per_pix))
griddata_shaped = griddata.reshape((ny, nx, exp_size_per_pix))

# experimental parameters are first num_param of every pixel
params = griddata_shaped[:, :, :num_param]
Expand Down Expand Up @@ -357,7 +366,8 @@ def _load_data(self):
f.close()

# reshape
scandata_shaped = scandata.reshape(nchanns, ndir, nx, ny)
# scandata_shaped = scandata.reshape(nchanns, ndir, nx, ny)
scandata_shaped = scandata.reshape(nchanns, ndir, ny, nx)

# extract data for each channel
for i, chann in enumerate(channs):
Expand Down Expand Up @@ -418,9 +428,11 @@ def _load_data(self):

column_names = f.readline().strip('\n').split('\t')
f.close()

num_lines = self._num_header_lines()
specdata = np.genfromtxt(self.fname, delimiter='\t', skip_header=num_lines)


for i, name in enumerate(column_names):
data_dict[name] = specdata[:, i]

Expand Down Expand Up @@ -473,6 +485,7 @@ def _parse_3ds_header(header_raw, header_override):
header_entries = header_raw.split('\r\n')
header_entries = header_entries[:-2]


# Convert the strings to a dictionary.
raw_dict = dict()
for entry in header_entries:
Expand Down Expand Up @@ -679,6 +692,7 @@ def _split_header_entry(entry):
those by ';' character.
"""


key_str, val_str = entry.split("=", 1)

if ';' in val_str:
Expand All @@ -687,6 +701,7 @@ def _split_header_entry(entry):
return key_str, val_str.strip('"')



def save_array(file, arr, allow_pickle=True):
"""
Wrapper to numpy.save method for arrays.
Expand Down

0 comments on commit 24d9474

Please sign in to comment.