nugridpy.h5T

h5T.py V1.1 created by Will Hillary

email: will.hillary@gmail.com

Date: December 18 2009

Modified to V1.1 by Daniel Conti

Email: hoshi@uvic.ca

Date: December 2010

Modified to V1.2 by Samuel Jones and Luke Siemens

Email: swjones@uvic.ca, lsiemens@uvic.ca

Date: March 2014

Modified by Alexander Heger for some python3 compatibility

Email: alexander.heger@monash.edu

Date May 2016

This is a simple python terminal interface for hdf5 files generated using NuGrid Stellar evolution code. It provides as simple as possible interface by allowing for intuitive, but sparse commands. Refer to the users manual and docstring below for more information.

Classes

Files([path, fName, pattern, rewrite, verbose]) Changes made by Daniel Conti
h5File(filepath, deep_search, new, …)
class nugridpy.h5T.Files(path='.', fName=None, pattern='*', rewrite=False, verbose=False)

Changes made by Daniel Conti

  1. Txtfile preprocessor: When the Files class is run in a directory for the first time, a preprocessor file is written, in the same directory. When loading in a directory of files, this class opens up every file to find the ages and the cycles. This file lets the class work faster, by writing the ages and cycles contained within each file to the preprocessor file. This allows the class to not open every h5 file in the directory. There is one downside to this however, This Files class has a list of h5File threads, if the a prepocessor file is read, these threads do not get started. So to solve this, whenever a method needs some data from one of these h5File threads, it then starts the thread and adds a True boolean to a list of booleans (that correspond to the list of files) of if that particular thread has been called. Currently, to the authors knowledge, this has been taken care of. If in the future someone adds a method that works with any of these threads in self.h5s. For example, if the command:

    >>> table=h5.Table
    

    where h5 is one of these h5File threads, the future author should have this aswell:

    >>> if not self.h5sStarted[self.h5s.index(h5)]
    >>>     h5.start()
    >>>     h5.join()
    >>>     table=h5.Table
    >>>     self.h5sStarted[self.h5s.index(h5)]=True
    >>> else:
    >>>     table=h5.Table
    

    This will run (start) the required thread and adds a True boolean, so we only ever need to start a thread once.

  2. Additional functionality to the get method: The get method can now be called with the name of the isotope, instead of the isotope and ‘iso_massf’. For example if we wanted the abundance of Heleium 3 from cycle 20, we would call:

    >>> get(20,'He-3')
    

    This would yield identical results to

    >>> get(20,'iso_massf','He-3')
    

    Also this author found and solved numerous bugs

  3. Added a pattern argument to the init method, A user can use a Unix, like regular expression to find files in a directory.

  4. Added a findCycle method, that allows the class to find the closest Cycle to what the user inputs, for example if the user imputs a cycle that DNE, it will find the next closest one.

findCycle(cycNum)

Method that looks through the self.cycles and returns the nearest cycle:

Parameters:cycNum (int) – int of the cycle desired cycle.
get(cycle_list, dataitem=None, isotope=None, sparse=1)

Get Data from HDF5 files.

There are three ways to call this function

  1. get(dataitem)

    Fetches the datatiem for all cycles. If dataitem is a header attribute or list of attributes then the data is retured. If detaitem an individulal or list of column attributes, data columns or isotopes/elements the data is returned for all cycles.

  2. get(cycle_list, dataitem)

    Fetches the dataitem or list of dataitems for the cycle or list of cycles. The variable dataitems can contain column attributes, data columns, and isotopes/elemnts.

  3. get(cycle_list, dataitem, isotope)

    Fetches the dataitems like the seccond method except that one of the dataitems must be either “iso_massf” or “yps”, and in the data returned “iso_massf” and “yps” are replaced with the data from the isotopes. The isotopes must be in the form given by se.isotopes or se.elements.

Parameters:
  • cycle_list (list, integer or string) –

    If cycle_list is a list or string and all of the entries are header attributes then the attributes are returned.

    If cycle_list is a list or string of dataitems then the dataitems are fetched for all cycles.

    If cycle_list is a list, integer or string of cycle numbers then data is returned for those cycles.

  • dataitem (list or string, optional) – If dataitem is not None then the data for each item is returned for the cycle or list of cycles. dataitem may be an individual or a mixed list of column attributes, column data or isotopes/elements. If dataitem is None then cycle_list must be a string. The default is None.
  • isotope (list or string, optional) – If one of the dataitems is “iso_massf” or “yps” then it is replaced with the data from the individual isotopes/elements listed in isotope. The default is None.
  • sparse (int) – Implements a sparsity factor on the fetched data i.e. only the i th cycle in cycle_list data is returned, where i = sparse.
red_dim(array)

This function reduces the dimensions of an array until it is no longer of length 1.