Skip to content

Commit

Permalink
String compatibility (#66)
Browse files Browse the repository at this point in the history
* remove np.string_ and just use regular python strings.

* remove np.string_. Just use str

* remove decodes. Assume strings

* update setup.py with version information

---------

Co-authored-by: Peter Ercius ncem-gauss jupyter <percius.lbl.gov>
  • Loading branch information
ercius authored Aug 8, 2024
1 parent 30fa4ab commit 6d0b5b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
28 changes: 14 additions & 14 deletions ncempy/eval/ring_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_settings( parent ):
except:
raise TypeError('Something wrong with the input.')

if not parent.attrs['type'] == np.string_(cur_set_vers):
if not parent.attrs['type'] == cur_set_vers:
print('Don\'t know the format of these settings.')
return None

Expand All @@ -102,11 +102,11 @@ def get_settings( parent ):
in_funcs = parent.attrs['fit_funcs'][0]
else:
in_funcs = parent.attrs['fit_funcs']
in_funcs = in_funcs.split(b',')
in_funcs = in_funcs.split(',')

out_funcs = []
for i in range(len(in_funcs)):
out_funcs.append(in_funcs[i].decode('utf-8').strip())
out_funcs.append(in_funcs[i].strip())
settings['fit_funcs'] = tuple(out_funcs)

if 'plt_imgminmax' in parent.attrs:
Expand Down Expand Up @@ -175,7 +175,7 @@ def put_settings( parent, settings ):


# set version information
grp_set.attrs['type'] = np.string_(cur_set_vers)
grp_set.attrs['type'] = cur_set_vers

# hardcoding the written settings to keep control
grp_set.attrs['lmax_r'] = settings['lmax_r']
Expand All @@ -192,7 +192,7 @@ def put_settings( parent, settings ):
fit_funcs = []
for i in range(len(settings['fit_funcs'])):
fit_funcs.append(settings['fit_funcs'][i])
grp_set.attrs['fit_funcs'] = np.string_(', '.join(fit_funcs))
grp_set.attrs['fit_funcs'] = ', '.join(fit_funcs)

if not settings['plt_imgminmax'] is None:
grp_set.attrs['plt_imgminmax'] = settings['plt_imgminmax']
Expand Down Expand Up @@ -240,11 +240,11 @@ def put_sglgroup(parent, label, data_grp):

# create the evaluation group
grp = parent.create_group(label)
grp.attrs['type'] = np.string_(cur_eva_vers)
grp.attrs['type'] = cur_eva_vers

# put a link to the data
grp.attrs['filename'] = np.string_(data_grp.file.filename)
grp.attrs['internal_path'] = np.string_(data_grp.name)
grp.attrs['filename'] = data_grp.file.filename
grp.attrs['internal_path'] = data_grp.name
#grp['emdgroup'] = h5py.ExternalLink(data_grp.file.filename, data_grp.name)

return grp
Expand All @@ -270,7 +270,7 @@ def run_sglgroup(group, outfile, overwrite=False, verbose=False, showplots=False

try:
assert(isinstance(group, h5py._hl.group.Group))
assert( group.attrs['type'] == np.string_(cur_eva_vers) )
assert( group.attrs['type'] == cur_eva_vers)

assert(isinstance(outfile, ncempy.io.emd.fileEMD))
except:
Expand All @@ -281,9 +281,9 @@ def run_sglgroup(group, outfile, overwrite=False, verbose=False, showplots=False

# get the emdgroup
if verbose:
print('.. getting data from {}:{}'.format(group.attrs['filename'].decode('utf-8'), group.attrs['internal_path'].decode('utf-8')))
readfile = ncempy.io.emd.fileEMD( group.attrs['filename'].decode('utf-8'), readonly=True )
data, dims = readfile.get_emdgroup(readfile.file_hdl[group.attrs['internal_path'].decode('utf-8')])
print('.. getting data from {}:{}'.format(group.attrs['filename'], group.attrs['internal_path']))
readfile = ncempy.io.emd.fileEMD( group.attrs['filename'], readonly=True )
data, dims = readfile.get_emdgroup(readfile.file_hdl[group.attrs['internal_path']])

# find the settings moving upwards in hierarchy
if verbose:
Expand All @@ -292,7 +292,7 @@ def proc_group(grp):
#print('scanning group {}'.format(grp))
if 'settings_ringdiffraction' in grp:
stt = grp['settings_ringdiffraction']
if stt.attrs['type'] == np.string_(cur_set_vers):
if stt.attrs['type'] == cur_set_vers:
return stt
else:
if not grp == grp.file:
Expand Down Expand Up @@ -394,7 +394,7 @@ def proc_group(grp, todo):
if grp.get(item, getclass=True) == h5py._hl.group.Group:
item = grp.get(item)
if 'type' in item.attrs:
if item.attrs['type'] == np.string_(cur_eva_vers):
if item.attrs['type'] == cur_eva_vers:
todo.append(item)
if verbose:
print('Found evaluation group at "{}".'.format(item.name) )
Expand Down
8 changes: 4 additions & 4 deletions ncempy/io/emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def write_dim(self, label, dim, parent):

try:
dset = parent.create_dataset(label, data=dim[0])
dset.attrs['name'] = np.string_(dim[1])
dset.attrs['units'] = np.string_(dim[2])
dset.attrs['name'] = dim[1]
dset.attrs['units'] = dim[2]
except:
raise RuntimeError('Error during writing dim dataset')

Expand Down Expand Up @@ -522,11 +522,11 @@ def put_comment(self, msg, timestamp=None):
# write comment
if timestamp in self.comments.attrs:
# append to existing
self.comments.attrs[timestamp] += np.string_('\n' + msg)
self.comments.attrs[timestamp] += '\n' + msg

else:
# create new entry
self.comments.attrs[timestamp] = np.string_(msg)
self.comments.attrs[timestamp] = msg


def defaultDims(data, pixel_size=None, pixel_unit=None):
Expand Down
4 changes: 2 additions & 2 deletions ncempy/io/ser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ def read_emi(filename):


def _parseEntry_emi(value):
"""Auxiliary function to parse string entry to int, float or np.string_().
"""Auxiliary function to parse string entry to int, float or str.
Parameters
----------
Expand All @@ -1039,7 +1039,7 @@ def _parseEntry_emi(value):
p = float(value)
except ValueError:
# if neither int nor float, stay with string
p = np.string_(str(value))
p = str(value)

return p

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.11.2',
version='1.12',

description='openNCEM\'s Python Package',
long_description=long_description,
Expand Down Expand Up @@ -55,9 +55,9 @@

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],

# What does your project relate to?
Expand All @@ -75,7 +75,8 @@
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=['numpy<2', 'scipy', 'matplotlib', 'h5py<3'],

install_requires=['numpy>=2', 'scipy', 'matplotlib', 'h5py>=3'],

# List additional groups of dependencies here (e.g. development
# dependencies). You can install these using the following syntax,
Expand Down

0 comments on commit 6d0b5b2

Please sign in to comment.