API Documentation¶
JGF basic export or import¶
-
class
jgf.core.
NumpyEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Custom encoder for numpy data types
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
jgf.core.
load
(filename='', compressed=None)[source]¶ Loads a JGF(Z) – Json Graph Format (gZipped) – file and converts it to a list of JXNF – Json compleX Network Format – dictionaries.
- filename : str or file handle
- Path to the file or a file handle to be used as input.
- compressed : bool
- If true, the input file will be interpreted as being compressed. If not provided, this will be guessed from the file extension. Use ‘.jgfz’ for compressed files.
- out : List of OrderedDict
- Data readed from the JGF(Z) file formatted as a list of JXNF dictionaries.
-
jgf.core.
save
(graphs, filename='', compressed=None)[source]¶ Writes a list of JXNF – Json compleX Network Format – dictionaries to a JGF(Z) – Json Graph Format (gZipped) – file.
- graphs : list of dict
- List of dictionaries in JXNF.
- filename : str or file handle
- Path to the file or a file handle to be used as output.
- compressed : bool
- If true, the input file will be interpreted as being compressed. If not provided, this will be guessed from the file extension. Use ‘.jgfz’ for compressed files.
igraph¶
-
jgf.igraph.
load
(filename='', compressed=None)[source]¶ Loads a JGF(Z) – Json Graph Format (gZipped) – file and converts it to an igraph.Graph object.
- filename : str or file handle
- Path to the file or a file handle to be used as input.
- compressed : bool
- If true, the input file will be interpreted as being compressed. If not provided, this will be guessed from the file extension. Use ‘.jgfz’ for compressed files.
- out : list of igraph.Graph
- List of igraph network objects.
-
jgf.igraph.
save
(graphs, filename='', compressed=None)[source]¶ Writes a list igraph.Graph networks to a JGF(Z) – Json Graph Format (gZipped) – file.
- graphs : list of igraph.Graph objects or a single Graph object
- Graphs to be saved.
- filename : str or file handle
- Path to the file or a file handle to be used as output.
- compressed : bool
- If true, the input file will be interpreted as being compressed. If not provided, this will be guessed from the file extension. Use ‘.jgfz’ for compressed files.
numpy array¶
-
jgf.conmat.
load
(filename='', compressed=None, weight='weight', getExtraData=False, noneNumericValue=0)[source]¶ Loads a JGF(Z) – Json Graph Format (gZipped) – file and converts it to a connectivity matrix represented by a numpy array.
- filename : str or file handler
- Path to the file or a file handler to be used as input.
- compressed : bool
- If true, the input file will be interpreted as being compressed. If not provided, this will be guessed from the file extension. Use ‘.jgfz’ for compressed files.
- weight: str
- Name of the weight property to be used as weights for the connectivity matrix. By default, attribute weight is used. If this attribute is None or not present in the network, the generated matrix will be binary.
- getExtraData: bool
- If true, this function returns not only the graph but a dictionaries of properties as well.
- noneNumericValue: obj
- Value to be used as placeholder for invalid or none values in edge properties.
- out : list of np.array of dim=2
- List of matrices network objects.
-
jgf.conmat.
save
(matrices, filename='', weight='weight', compressed=None, mantainAllEdges=False, label=None, directed=None, networkProperties=None, nodeProperties=None, edgeProperties=None)[source]¶ Writes a list matrices as networks to a JGF(Z) – Json Graph Format (gZipped) – file.
- graphs : list of numpy matrices or a single connectivity matrix object
- Connectivity matrix to be saved.
- filename : str or file handler
- Path to the file or a file handler to be used as output.
- compressed : bool
- If true, the input file will be interpreted as being compressed. If not provided, this will be guessed from the file extension. Use ‘.jgfz’ for compressed files.
mantainAllEdges : bool label : list or str
Labels used for the networks in order. If a single value is provided, it will be replicated to all networks.- directed : list or bool
- Set if the networks are directed or not. If a single value is provided, it will be replicated to all networks.
- networkProperties : list or dict
- Dictionary containing the network properties. If a single dictionary is provided, it will be replicated to all the networks.
- nodeProperties : list or dict
- Dictionary containing the node properties. If a single dictionary is provided, it will be replicated to all the networks. Each entry in the dictionaries must be arrays of properties indexed according to the order of columns/rows in the matrix.
- edgeProperties : list or bool
- Dictionary containing the edge properties. If a single dictionary is provided, it will be replicated to all the networks. Each entry must contain a matrix of values assigned to each edge (nodes pair).