# Path: tellurium/utils/omex.py
# MANIFEST_PATTERN = "manifest.xml"
# METADAT_PATTERN = "metadata.*"
# class Entry(object):
# class Creator(object):
#     def __init__(self, location, format=None, formatKey=None, master=False, description=None, creators=None):
#     def __str__(self):
#     def __init__(self, givenName, familyName, organization, email):
# def combineArchiveFromDirectory(directory, omexPath, creators=None, creators_for_all=False):
# def combineArchiveFromEntries(omexPath, entries, workingDir):
# def addEntriesToCombineArchive(omexPath, entries, workingDir):
# def _addEntriesToArchive(omexPath, entries, workingDir, add_entries):
# def extractCombineArchive(omexPath, directory, method="zip"):
# def getLocationsByFormat(omexPath, formatKey=None, method="omex"):
# def listContents(omexPath, method="omex"):
# def printContents(omexPath):
# 
# Path: tellurium/sedml/mathml.py
# def evaluableMathML(astnode, variables={}, array=False):
#     """ Create evaluable python string.
# 
#     """
#     # replace variables with provided values
#     for key, value in variables.items():
#         astnode.replaceArgument(key, libsbml.parseFormula(str(value)))
# 
#     # get formula
#     formula = libsbml.formulaToL3String(astnode)
# 
#     # <replacements>
#     # FIXME: these are not exhaustive, but are improved with examples
#     if array is False:
#         # scalar
#         formula = formula.replace("&&", 'and')
#         formula = formula.replace("||", 'or')
#     else:
#         # np.array
#         formula = formula.replace("max", 'np.nanmax')
#         formula = formula.replace("min", 'np.nanmin')
#         formula = formula.replace("sum", 'np.nansum')
#         formula = formula.replace("product", 'np.prod')
# 
#     return formula


import sys
import platform
import tempfile
import shutil
import traceback
import os.path
import warnings
import datetime
import zipfile
import re
import numpy as np
import jinja2
    import libsedml
    import tesedml as libsedml
import tellurium as te
    import pandas
    import matplotlib.pyplot as plt
    import mpl_toolkits.mplot3d
                    import os
    import os
    import matplotlib
from collections import namedtuple
from tellurium.utils import omex
from .mathml import evaluableMathML
        from tellurium.sedml.data import DataDescriptionParser
                from xml.etree import ElementTree
    from tellurium.tests.testdata import SEDML_TEST_DIR, OMEX_TEST_DIR
                if resetModel is True:
                    # If each entry in the task consists of a single point (e.g. steady state scan)
                    # , concatenate the points. Otherwise, plot as separate curves.
                    if 'PROCESS_TRACE' in os.environ and os.environ['PROCESS_TRACE']:
                        lines.append("__var__{} = np.concatenate([process_trace(sim['{}']) for sim in {}])".format(varId, sid, taskId))
                    else:
                        lines.append("__var__{} = np.column_stack([sim['{}'] for sim in {}])".format(varId, sid, taskId))
                else:
                    # One curve via time adjusted concatenate
                    if isTime is True:
                        lines.append("__offsets__{} = np.cumsum(np.array([sim['{}'][-1] for sim in {}]))".format(taskId, sid, taskId))
                        lines.append("__offsets__{} = np.insert(__offsets__{}, 0, 0)".format(taskId, taskId))
                        lines.append("__var__{} = np.transpose(np.array([sim['{}']+__offsets__{}[k] for k, sim in enumerate({})]))".format(varId, sid, taskId, taskId))
                        lines.append("__var__{} = np.concatenate(np.transpose(__var__{}))".format(varId, varId))
                    else:
                        lines.append("__var__{} = np.transpose(np.array([sim['{}'] for sim in {}]))".format(varId, sid, taskId))
                        lines.append("__var__{} = np.concatenate(np.transpose(__var__{}))".format(varId, varId))
                lines.append("if len(__var__{}.shape) == 1:".format(varId))
                lines.append("     __var__{}.shape += (1,)".format(varId))

            # check for data sources
            else:
                target = var.getTarget()
                if target.startswith('#'):
                    sid = target[1:]
                    lines.append("__var__{} = {}".format(varId, sid))
                else:
                    warnings.warn("Unknown target in variable, no reference to SId: {}".format(target))

        # calculate data generator

# Path: tellurium/utils/omex.py
# MANIFEST_PATTERN = "manifest.xml"
# METADAT_PATTERN = "metadata.*"
# class Entry(object):
# class Creator(object):
#     def __init__(self, location, format=None, formatKey=None, master=False, description=None, creators=None):
#     def __str__(self):
#     def __init__(self, givenName, familyName, organization, email):
# def combineArchiveFromDirectory(directory, omexPath, creators=None, creators_for_all=False):
# def combineArchiveFromEntries(omexPath, entries, workingDir):
# def addEntriesToCombineArchive(omexPath, entries, workingDir):
# def _addEntriesToArchive(omexPath, entries, workingDir, add_entries):
# def extractCombineArchive(omexPath, directory, method="zip"):
# def getLocationsByFormat(omexPath, formatKey=None, method="omex"):
# def listContents(omexPath, method="omex"):
# def printContents(omexPath):
# 
# Path: tellurium/sedml/mathml.py
# def evaluableMathML(astnode, variables={}, array=False):
#     """ Create evaluable python string.
# 
#     """
#     # replace variables with provided values
#     for key, value in variables.items():
#         astnode.replaceArgument(key, libsbml.parseFormula(str(value)))
# 
#     # get formula
#     formula = libsbml.formulaToL3String(astnode)
# 
#     # <replacements>
#     # FIXME: these are not exhaustive, but are improved with examples
#     if array is False:
#         # scalar
#         formula = formula.replace("&&", 'and')
#         formula = formula.replace("||", 'or')
#     else:
#         # np.array
#         formula = formula.replace("max", 'np.nanmax')
#         formula = formula.replace("min", 'np.nanmin')
#         formula = formula.replace("sum", 'np.nansum')
#         formula = formula.replace("product", 'np.prod')
# 
#     return formula


# Path: tellurium/sedml/tesedml.py
import sys
import platform
import tempfile
import shutil
import traceback
import os.path
import warnings
import datetime
import zipfile
import re
import numpy as np
import jinja2
    import libsedml
    import tesedml as libsedml
import tellurium as te
    import pandas
    import matplotlib.pyplot as plt
    import mpl_toolkits.mplot3d
                    import os
    import os
    import matplotlib
from collections import namedtuple
from tellurium.utils import omex
from .mathml import evaluableMathML
        from tellurium.sedml.data import DataDescriptionParser
                from xml.etree import ElementTree
    from tellurium.tests.testdata import SEDML_TEST_DIR, OMEX_TEST_DIR

                if resetModel is True:
                    # If each entry in the task consists of a single point (e.g. steady state scan)
                    # , concatenate the points. Otherwise, plot as separate curves.
                    if 'PROCESS_TRACE' in os.environ and os.environ['PROCESS_TRACE']:
                        lines.append("__var__{} = np.concatenate([process_trace(sim['{}']) for sim in {}])".format(varId, sid, taskId))
                    else:
                        lines.append("__var__{} = np.column_stack([sim['{}'] for sim in {}])".format(varId, sid, taskId))
                else:
                    # One curve via time adjusted concatenate
                    if isTime is True:
                        lines.append("__offsets__{} = np.cumsum(np.array([sim['{}'][-1] for sim in {}]))".format(taskId, sid, taskId))
                        lines.append("__offsets__{} = np.insert(__offsets__{}, 0, 0)".format(taskId, taskId))
                        lines.append("__var__{} = np.transpose(np.array([sim['{}']+__offsets__{}[k] for k, sim in enumerate({})]))".format(varId, sid, taskId, taskId))
                        lines.append("__var__{} = np.concatenate(np.transpose(__var__{}))".format(varId, varId))
                    else:
                        lines.append("__var__{} = np.transpose(np.array([sim['{}'] for sim in {}]))".format(varId, sid, taskId))
                        lines.append("__var__{} = np.concatenate(np.transpose(__var__{}))".format(varId, varId))
                lines.append("if len(__var__{}.shape) == 1:".format(varId))
                lines.append("     __var__{}.shape += (1,)".format(varId))

            # check for data sources
            else:
                target = var.getTarget()
                if target.startswith('#'):
                    sid = target[1:]
                    lines.append("__var__{} = {}".format(varId, sid))
                else:
                    warnings.warn("Unknown target in variable, no reference to SId: {}".format(target))

        # calculate data generator

        value = evaluableMathML(mathml, variables=variables, array=True)