Wiki

Clone wiki

hamx / wrapper / hampyx

hammurabi X python wrapper

The Hampyx python class is desinged for easy access to the hammurabi X routines, where the users only have to modify the XML parameter file and call a few python functions. The simulation outputs will be handled within python, in order to make them available to other routines, e.g., an analyzing pipeline.

function list:

  • __init__

    # input
    xml_path='./params.xml' (path to the XML parameter file)
    exe_path=None (path to the)
    

    It initializes the class object, it requires (but not necessary) a XML parameter file path and the hammurabi executable path. By default, the executable path will be searched in the local environment, i.e., the PATH, while the XML parameter file is assumed to be located at the current working directory, so by default it tries to find a *.xml file. The paramters stored in the XML file is parsed into an internal XML tree.

  • __call__

    # input
    verbose=False (the switch for getting execution and error logs)
    

    It makes a temporary copy of the hammurabi parameter set (with temporary output file names), and starts to execute the hammurabi main routine. Once done, it reads in the outputs from the disk and cleans up all the temporary (output and parameter) files.

  • mod_par

    # input
    keychain=None
    attrib=None
    

    It modifies a parameter value in the XML tree. The first argument is a list/tuple of XML keys to find the parameter entry, and the second argument is the XML attribute that needs modification. For a more detailed understanding of the connection between the XML format and the actual parameters, please turn to the tutorials for practical application examples.

  • add_par

    # input
    keychain=None
    subkey=None
    attrib=None
    

    It adds a new parameter (with its value) to the XML tree. To accomplish that we need not only the location for adding a new entry, but the new entry itself sometimes. For a more detailed understanding of the connection between the XML format and the actual parameters, please turn to the tutorials for practical application examples.

  • print_par

    # input
    keychain=None
    

    It prints out the XML tree branch at the entry instructed by the first argument, and the following first level children level will also be printed.

  • del_par

    # input
    keychain=None
    opt=None
    

    It delete an XML entry instructed by the first argument. If the second argument is set as 'all', then all entries which match the instruction will be removed, not only the first one.

  • _new_xml_copy

    # input
    -
    

    It creates a temporary copy of the XML tree and writes it out to the disk. The temporary XML file has a random name and the same as output file names defined inside.

  • _del_xml_copy

    # input
    -
    

    It deletes the temporary copy of the XML tree written to the disk by function _new_xml_copy.

  • _get_sims

    # input 
    -
    

    It reads in the output files from the hammurabi routine, once read, the temporary output files will be deleted from the disk.

  • _read_fits_file

    # input
    -
    

    It is used by function _get_sims. This function requires the Healpy support.

quick guid:

  • Import class

    In []: import hampyx as hpx
    

  • Initialize object

    In []: object = hpx.Hampyx (<xml file path>, <executable path>)
    

    hammurabiX executable path is by default '/usr/local/hammurabi/bin/hamx' while xml file path is by default './'.

  • Modify parameter value from base xml file to temp xml file

    In []: object.mod_par (keychain=['key1','key2',...], attrib={'tag':'content'})
    

  • Add new parameter with or without attributes

    In []: object.add_par (keychain=['key1','key2',...], subkey='keyfinal', attrib={'tag':'content'})
    

    the new parameter subkey, will be added at the path defined by keychain.

  • Delete parameter

    In []: object.del_par (keychain=['key1','key2',...])
    

    if additional argument opt='all', then all matching parameters will be deleted, the strings 'key1', 'key2', etc represent the path to the desired parameter, going through the xml, the "tag" is the label for the parameter: eg. "Value" or "cue" or "type", the "content" is the content under the tag: eg. the string for the tag "filename".

  • Visualize the parameter tree in python

    In []: object.print_par(keychain=['key1','key2',...])
    

    this will return the current value of the parameter in the XML associated with the path "key1/key2/.../keyfinal/".

  • Run the executable

    In []: object(verbose=True/False)
    

    if additional verbose=True (by default is False) hampyx_run.log and hampyx_err.log will be dumped to disk, notice that dumping logs is not thread safe, use quiet mode in threading.

  • Convection in map entries

    object.sim_map[('sync',str(freq),str(Nside),'I')] # synchrotron intensity map at 'frequency' 
    object.sim_map[('sync',str(freq),str(Nside),'Q')] # synchrotron Q map at 'frequency' 
    object.sim_map[('sync',str(freq),str(Nside),'U')] # synchrotron U map at 'frequency' 
    object.sim_map[('sync',str(freq),str(Nside),'PI')] # synchrotron pol. intensity at 'frequency' 
    object.sim_map[('sync',str(freq),str(Nside),'PA')] # synchrotron pol. angle at 'frequency' (IAU convention)
    object.sim_map[('fd','nan',str(Nside),'nan')] # Faraday depth map
    object.sim_map[('dm','nan',str(Nside),'nan')] # dispersion measure map
    

    after executing the main routine, object.sim_map will be filled with simulation outputs from hammurabiX the structure of object.sim_map contains arrays under entries. (we give up nested dict structure for the convenience of Bayesian analysis)

Updated