Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Eva Schiffer
UW-Glance
Commits
791a8d91
Commit
791a8d91
authored
Jan 20, 2022
by
Eva Schiffer
Browse files
hdf and nc files now have more detailed info messages
parent
cb367f68
Changes
2
Hide whitespace changes
Inline
Side-by-side
pyglance/glance/compare.py
View file @
791a8d91
...
...
@@ -1820,7 +1820,7 @@ def main():
var_list
.
sort
()
print
(
""
.
join
([
file_path
+
"
\t
"
+
x
+
"
\n
"
for
x
in
var_list
]),
file
=
toPrintTo
,
)
else
:
display_str
=
file_obj
.
display_string
()
display_str
=
file_obj
.
display_string
(
show_attrs
=
do_verbose
,
)
print
(
display_str
,
file
=
toPrintTo
,
)
#print(file_path + ': ' + ('\n ' + ' ' * len(file_path)).join(var_list), file=toPrintTo, )
except
KeyError
:
...
...
pyglance/glance/io.py
View file @
791a8d91
...
...
@@ -242,7 +242,19 @@ class nc (object):
grp_str
=
group_name
if
prefix
is
None
or
len
(
prefix
)
<=
0
else
prefix
+
"/"
+
group_name
for
more_var_name
,
more_var_obj
in
self
.
_walkgroups
(
start_at
.
groups
[
group_name
],
prefix
=
grp_str
):
yield
more_var_name
,
more_var_obj
# walk down through all groups and get all the dimensions info
def
_walkgroups_for_dims
(
self
,
start_at
,
prefix
=
None
,
):
# look through the dims that are here
for
dim_name
in
start_at
.
dimensions
:
temp_name
=
dim_name
if
prefix
is
None
or
len
(
prefix
)
<=
0
else
prefix
+
"/"
+
dim_name
yield
temp_name
,
start_at
.
dimensions
[
dim_name
]
# look through the groups that are here
for
group_name
in
start_at
.
groups
:
grp_str
=
group_name
if
prefix
is
None
or
len
(
prefix
)
<=
0
else
prefix
+
"/"
+
group_name
for
more_dims_name
,
more_dims_obj
in
self
.
_walkgroups
(
start_at
.
groups
[
group_name
],
prefix
=
grp_str
):
yield
more_dims_name
,
more_dims_obj
def
__init__
(
self
,
filename
,
allowWrite
=
False
):
if
netCDF4
is
None
:
...
...
@@ -260,6 +272,10 @@ class nc (object):
for
var_name
,
var_obj
in
self
.
_walkgroups
(
self
.
_nc
,)
:
self
.
_var_map
[
var_name
]
=
var_obj
self
.
_dims_map
=
{}
for
dim_name
,
dim_obj
in
self
.
_walkgroups_for_dims
(
self
.
_nc
,
):
self
.
_dims_map
[
dim_name
]
=
dim_obj
def
__call__
(
self
):
"""
yield names of variables in this file
...
...
@@ -513,14 +529,14 @@ class nc (object):
returns all the attributes associated with a variable name
"""
#
toReturn =
None
toReturn
=
{
}
if
caseInsensitive
:
toReturn
=
self
.
attributeCache
.
get_variable_attributes
(
variableName
)
else
:
toReturn
=
{
}
tempVarObj
=
self
.
get_variable_object
(
variableName
)
tempAttrKeys
=
tempVarObj
.
ncattrs
()
for
attrKey
in
tempAttrKeys
:
toReturn
[
attrKey
]
=
getattr
(
tempVarObj
,
attrKey
)
...
...
@@ -592,12 +608,41 @@ class nc (object):
returns a string, describing the file in a user readable format.
"""
#
TODO, this is a temporary implementation to be replaced with more details soon
#
identify the file by it's path
to_return
=
"File path: "
+
self
.
_path
+
"
\n
"
# add dimensions info
to_return
+=
"
\t
dimensions:
\n
"
for
dimName
in
self
.
_dims_map
:
to_return
+=
"
\t\t
"
+
dimName
+
" = "
+
str
(
self
.
_dims_map
[
dimName
].
size
)
+
"
\n
"
# add detailed variables info
to_return
+=
"
\t
variables:
\n
"
temp_vars
=
self
()
for
var_name
in
temp_vars
:
to_return
+=
"
\t
"
+
var_name
+
"
\n
"
for
var_name
in
temp_vars
:
v_object
=
self
.
get_variable_object
(
var_name
)
to_return
+=
"
\t\t
"
+
str
(
v_object
.
datatype
)
+
" "
+
var_name
#+ " " + str(v_object.dimensions) + "\n"
temp_v_dims
=
v_object
.
dimensions
if
len
(
temp_v_dims
)
<
1
:
to_return
+=
" (single scalar value) = "
+
str
(
self
[
var_name
])
+
"
\n
"
else
:
temp_shape
=
v_object
.
shape
to_return
+=
" ("
for
dim_name
in
temp_v_dims
:
to_return
+=
dim_name
+
"="
+
str
(
temp_shape
[
0
])
+
", "
temp_shape
=
temp_shape
[
1
:]
to_return
=
to_return
[:
-
1
]
+
")
\n
"
if
show_attrs
:
temp_attrs
=
self
.
get_variable_attributes
(
var_name
,
caseInsensitive
=
False
,)
for
attr_name
in
temp_attrs
:
to_return
+=
"
\t\t\t
"
+
attr_name
+
" = "
+
str
(
temp_attrs
[
attr_name
])
+
"
\n
"
# if appropriate, add global attributes info
if
show_attrs
:
to_return
+=
"
\t
global attributes:
\n
"
temp_g_attrs
=
self
.
get_global_attributes
(
caseInsensitive
=
False
,)
for
g_attr_name
in
temp_g_attrs
:
to_return
+=
"
\t\t
"
+
g_attr_name
+
" = "
+
str
(
temp_g_attrs
[
g_attr_name
])
+
"
\n
"
return
to_return
...
...
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