The following code should do the trick
def nllabel(filename):
"""
Function for getting a dictionary with the labels associate to each id.
@param filename The filename to be inspect.
"""
# Import needed modules.
from NL.IO.NetCDFFile import NetCDFFile
from NL.IO.NLSaveUtilities import dataDictFromKeys
# Setup return object.
result = {}
# Setup the NetCDF file for reading.
nc = NetCDFFile(filename, 'r', mmap=False)
# Find the ids.
ids = numpy.unique( [ key.split('_')[1] for key in nc.variables.keys() ] )
# Loop over all the ids.
for id in ids:
# Needed keys for object
needed_key = [ key for key in nc.variables.keys() if id == key.split('_')[1] ][0]
if hasattr(nc.variables[needed_key], 'user_label'):
result[id] = nc.variables[needed_key].user_label
# Return the complete list.
return result
print nllabel('analysis.nc')