Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vasudevan, Rama K
pycroscopy
Commits
f51d0b25
Commit
f51d0b25
authored
Oct 04, 2017
by
Unknown
Browse files
Fixed recursive imports from PycroDataset
parent
87564e3f
Changes
2
Hide whitespace changes
Inline
Side-by-side
pycroscopy/io/hdf_utils.py
View file @
f51d0b25
...
...
@@ -6,13 +6,11 @@ Created on Tue Nov 3 21:14:25 2015
"""
from
__future__
import
division
,
print_function
,
absolute_import
,
unicode_literals
import
os
import
sys
import
h5py
from
warnings
import
warn
import
numpy
as
np
from
.microdata
import
MicroDataset
from
.pycro_data
import
PycroDataset
__all__
=
[
'get_attr'
,
'getDataSet'
,
'getH5DsetRefs'
,
'getH5RegRefIndices'
,
'get_dimensionality'
,
'get_sort_order'
,
'getAuxData'
,
'get_attributes'
,
'getH5GroupRefs'
,
'checkIfMain'
,
'checkAndLinkAncillary'
,
...
...
@@ -60,6 +58,8 @@ def get_all_main(parent, verbose=False):
The datasets found in the file that meet the 'Main Data' criteria.
"""
from
.pycro_data
import
PycroDataset
main_list
=
list
()
def
__check
(
name
,
obj
):
...
...
@@ -98,12 +98,19 @@ def getDataSet(h5_parent, data_name):
-------
list of h5py.Reference of the dataset.
"""
from
.pycro_data
import
PycroDataset
if
isinstance
(
h5_parent
,
h5py
.
File
)
or
isinstance
(
h5_parent
,
h5py
.
Group
):
data_list
=
[]
def
findData
(
name
,
obj
):
if
name
.
endswith
(
data_name
)
and
isinstance
(
obj
,
h5py
.
Dataset
):
data_list
.
append
(
PycroDataset
(
obj
))
try
:
data_list
.
append
(
PycroDataset
(
obj
))
except
TypeError
:
data_list
.
append
(
obj
)
except
:
raise
h5_parent
.
visititems
(
findData
)
return
data_list
...
...
@@ -136,7 +143,7 @@ def getAuxData(parent_data, auxDataName=None):
for
auxName
in
auxDataName
:
ref
=
parent_data
.
attrs
[
auxName
]
if
isinstance
(
ref
,
h5py
.
Reference
)
and
isinstance
(
file_ref
[
ref
],
h5py
.
Dataset
):
data_list
.
append
(
PycroDataset
(
file_ref
[
ref
])
)
data_list
.
append
(
file_ref
[
ref
])
except
KeyError
:
warn
(
'%s is not an attribute of %s'
%
(
str
(
auxName
),
parent_data
.
name
))
...
...
@@ -228,6 +235,8 @@ def getH5DsetRefs(ds_names, h5_refs):
aux_dset : List of HDF5 dataset references
Corresponding references
"""
from
.pycro_data
import
PycroDataset
aux_dset
=
[]
for
ds_name
in
ds_names
:
for
dset
in
h5_refs
:
...
...
@@ -265,6 +274,8 @@ def findDataset(h5_group, ds_name):
"""
Uses visit() to find all datasets with the desired name
"""
from
.pycro_data
import
PycroDataset
# print 'Finding all instances of', ds_name
ds
=
[]
...
...
@@ -963,6 +974,8 @@ def create_empty_dataset(source_dset, dtype, dset_name, new_attrs=dict(), skip_r
h5_new_dset : h5py.Dataset object
Newly created dataset
"""
from
.pycro_data
import
PycroDataset
h5_group
=
source_dset
.
parent
try
:
# Check if the dataset already exists
...
...
@@ -1629,6 +1642,8 @@ def get_source_dataset(h5_group):
h5_source : h5py.Dataset
"""
from
.pycro_data
import
PycroDataset
h5_parent_group
=
h5_group
.
parent
h5_source
=
h5_parent_group
[
h5_group
.
name
.
split
(
'/'
)[
-
1
].
split
(
'-'
)[
0
]]
return
PycroDataset
(
h5_source
)
pycroscopy/io/pycro_data.py
View file @
f51d0b25
...
...
@@ -10,7 +10,7 @@ import h5py
import
six
from
warnings
import
warn
import
numpy
as
np
from
.hdf_utils
import
checkIfMain
,
getAuxData
,
get_attr
,
get_data_descriptor
,
get_formatted_labels
,
\
from
.hdf_utils
import
checkIfMain
,
get_attr
,
get_data_descriptor
,
get_formatted_labels
,
\
get_dimensionality
,
get_sort_order
,
get_unit_values
,
reshape_to_Ndims
...
...
@@ -73,10 +73,14 @@ class PycroDataset(h5py.Dataset):
# User accessible properties
# The required Position and Spectroscopic datasets
self
.
h5_spec_vals
=
getAuxData
(
h5_ref
,
'Spectroscopic_Values'
)[
-
1
]
self
.
h5_spec_inds
=
getAuxData
(
h5_ref
,
'Spectroscopic_Indices'
)[
-
1
]
self
.
h5_pos_vals
=
getAuxData
(
h5_ref
,
'Position_Values'
)[
-
1
]
self
.
h5_pos_inds
=
getAuxData
(
h5_ref
,
'Position_Indices'
)[
-
1
]
# self.h5_spec_vals = getAuxData(h5_ref, 'Spectroscopic_Values')[-1]
# self.h5_spec_inds = getAuxData(h5_ref, 'Spectroscopic_Indices')[-1]
# self.h5_pos_vals = getAuxData(h5_ref, 'Position_Values')[-1]
# self.h5_pos_inds = getAuxData(h5_ref, 'Position_Indices')[-1]
self
.
h5_spec_vals
=
self
.
file
[
self
.
attrs
[
'Spectroscopic_Indices'
]]
self
.
h5_spec_inds
=
self
.
file
[
self
.
attrs
[
'Spectroscopic_Indices'
]]
self
.
h5_pos_vals
=
self
.
file
[
self
.
attrs
[
'Position_Values'
]]
self
.
h5_pos_inds
=
self
.
file
[
self
.
attrs
[
'Position_Indices'
]]
# The dimension labels
self
.
__pos_dim_labels
=
get_attr
(
self
.
h5_pos_inds
,
'labels'
)
...
...
@@ -152,18 +156,18 @@ class PycroDataset(h5py.Dataset):
if
self
.
__sort_dims
:
self
.
pos_dim_labels
=
self
.
__pos_dim_labels
[
self
.
__pos_sort_order
].
tolist
()
self
.
spec_dim_labels
=
self
.
__spec_dim_labels
[
self
.
__spec_sort_order
].
tolist
()
self
.
pos_dim_sizes
=
self
.
__pos_dim_sizes
[
self
.
__pos_sort_order
]
.
tolist
()
self
.
spec_dim_sizes
=
self
.
__spec_dim_sizes
[
self
.
__spec_sort_order
]
.
tolist
()
self
.
pos_dim_sizes
=
self
.
__pos_dim_sizes
[
self
.
__pos_sort_order
]
self
.
spec_dim_sizes
=
self
.
__spec_dim_sizes
[
self
.
__spec_sort_order
]
self
.
n_dim_labels
=
self
.
__n_dim_labs
[
self
.
__n_dim_sort_order
].
tolist
()
self
.
n_dim_sizes
=
self
.
__n_dim_sizes
[
self
.
__n_dim_sort_order
]
.
tolist
()
self
.
n_dim_sizes
=
self
.
__n_dim_sizes
[
self
.
__n_dim_sort_order
]
else
:
self
.
pos_dim_labels
=
self
.
__pos_dim_labels
.
tolist
()
self
.
spec_dim_labels
=
self
.
__spec_dim_labels
.
tolist
()
self
.
pos_dim_sizes
=
self
.
__pos_dim_sizes
.
tolist
()
self
.
spec_dim_sizes
=
self
.
__spec_dim_sizes
.
tolist
()
self
.
pos_dim_sizes
=
self
.
__pos_dim_sizes
self
.
spec_dim_sizes
=
self
.
__spec_dim_sizes
self
.
n_dim_labels
=
self
.
__n_dim_labs
.
tolist
()
self
.
n_dim_sizes
=
self
.
__n_dim_sizes
.
tolist
()
self
.
n_dim_sizes
=
self
.
__n_dim_sizes
def
get_pos_values
(
self
,
dim_name
):
"""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment