hepi.util

Collection of utility functions for the hepi package.

Module Contents

Classes

DictData

Functions

LD2DL(l[, actual_dict])

Convert a list of objects into a dictionary of lists.

DL2DF(ld)

Convert a dict of list`s to a `pandas.DataFrame.

namehash(n)

Creates a sha256 hash from the objects string representation.

lhapdf_name_to_id(name)

Converts a LHAPDF name to the sets id.

lhapdf_id_to_name(lid)

class hepi.util.DictData[source]
__str__()[source]

Returns attributes as dict as string

hepi.util.LD2DL(l, actual_dict=False)[source]

Convert a list of objects into a dictionary of lists.

The values of each object are first converted to a dict through the __dict__ attribute.

Parameters:
  • l (List) – list of objects.

  • actual_dict (bool) – objects are already dicts

Returns:

dictionary of numpy arrays.

Return type:

dict

Examples

>>> class Param:
...      def __init__(self,a,b,c):
...         self.a = a
...         self.b = b
...         self.c = c
>>> LD2DL([ Param(1,2,3), Param(4,5,6) , Param(7,8,9) ])
{'a': array([1, 4, 7]), 'b': array([2, 5, 8]), 'c': array([3, 6, 9])}
hepi.util.DL2DF(ld)[source]

Convert a dict of list`s to a `pandas.DataFrame.

Parameters:

ld (dict) –

Return type:

pandas.DataFrame

hepi.util.namehash(n)[source]

Creates a sha256 hash from the objects string representation.

Parameters:

n (any) – object.

Returns:

sha256 of object.

Return type:

str

Examples

>>> p = {'a':1,'b':2}
>>> str(p)
"{'a': 1, 'b': 2}"
>>> namehash(str(p))
'3dffaea891e5dbadb390da33bad65f509dd667779330e2720df8165a253462b8'
>>> namehash(p)
'3dffaea891e5dbadb390da33bad65f509dd667779330e2720df8165a253462b8'
hepi.util.lhapdf_name_to_id(name)[source]

Converts a LHAPDF name to the sets id.

Parameters:

name (str) – LHAPDF set name.

Returns:

id of the LHAPDF set.

Return type:

int

Examples

>>> lhapdf_name_to_id("CT14lo")
13200
hepi.util.lhapdf_id_to_name(lid)[source]
Parameters:

lid (int) –

Return type:

str