Author Topic: Vnl 10.8  (Read 3983 times)

0 Members and 1 Guest are viewing this topic.

Offline jdgayles16

  • QuantumATK Guru
  • ****
  • Posts: 108
  • Reputation: 0
    • View Profile
Vnl 10.8
« on: August 12, 2010, 02:30 »
How does one get the labels/names to show on the new atk?

Thanks
Jacob

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Re: Vnl 10.8
« Reply #1 on: August 12, 2010, 11:31 »
Are you talking about the ID or the labels?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Vnl 10.8
« Reply #2 on: August 12, 2010, 11:35 »
Labels cannot be read (yet), so for now we recommend using IDs only. They can be formatted as labels anyway, as long as you remember to make them unique all the time!

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Re: Vnl 10.8
« Reply #3 on: August 12, 2010, 11:56 »
The following code should do the trick
Code: python
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')