Example #1
0
 def testSetReadConsole(self):
     yes = "yes\n"
     def sayyes(prompt):
         return yes
     rinterface.set_readconsole(sayyes)
     self.assertEqual(rinterface.get_readconsole(), sayyes)
     res = rinterface.baseenv["readline"]()
     self.assertEqual(yes.strip(), res[0])
     rinterface.set_readconsole(rinterface.consoleRead)
Example #2
0
    def testSetReadConsole(self):
        yes = "yes\n"

        def sayyes(prompt):
            return yes

        rinterface.set_readconsole(sayyes)
        self.assertEqual(rinterface.get_readconsole(), sayyes)
        res = rinterface.baseenv["readline"]()
        self.assertEqual(yes.strip(), res[0])
        rinterface.set_readconsole(rinterface.consoleRead)
    def testReadConsoleWithError(self):
        def f(prompt):
            raise Exception("Doesn't work.")
        rinterface.set_readconsole(f)

        tmp_file = tempfile.NamedTemporaryFile()

        stderr = sys.stderr
        sys.stderr = tmp_file
        try:
            res = rinterface.baseenv["readline"]()
        except Exception, e:
            sys.stderr = stderr
            raise e
Example #4
0
    def testReadConsoleWithError(self):
        def f(prompt):
            raise Exception("Doesn't work.")

        rinterface.set_readconsole(f)

        tmp_file = tempfile.NamedTemporaryFile()

        stderr = sys.stderr
        sys.stderr = tmp_file
        try:
            res = rinterface.baseenv["readline"]()
        except Exception, e:
            sys.stderr = stderr
            raise e
Example #5
0
    def testReadConsoleWithError(self):
        def f(prompt):
            raise Exception("Doesn't work.")
        rinterface.set_readconsole(f)

        tmp_file = tempfile.NamedTemporaryFile()

        stderr = sys.stderr
        sys.stderr = tmp_file
        try:
            res = rinterface.baseenv["readline"]()
        except Exception as e:
            sys.stderr = stderr
            raise e
        sys.stderr = stderr
        tmp_file.flush()
        tmp_file.seek(0)
        self.assertEqual("Doesn't work.", str(sys.last_value))
    def testReadConsoleWithError(self):
        def f(prompt):
            raise Exception("Doesn't work.")

        rinterface.set_readconsole(f)

        tmp_file = tempfile.NamedTemporaryFile()

        stderr = sys.stderr
        sys.stderr = tmp_file
        try:
            res = rinterface.baseenv["readline"]()
        except Exception as e:
            sys.stderr = stderr
            raise e
        sys.stderr = stderr
        tmp_file.flush()
        tmp_file.seek(0)
        self.assertEqual("Doesn't work.", str(sys.last_value))
Example #7
0
 def tearDown(self):
     rinterface.set_writeconsole(rinterface.consolePrint)
     rinterface.set_readconsole(rinterface.consoleRead)
     rinterface.set_readconsole(rinterface.consoleFlush)
     rinterface.set_choosefile(rinterface.chooseFile)
     sys.last_value = None
Example #8
0
import sys
from rpy2.rinterface import set_readconsole
set_readconsole(None)

import rpy2.robjects as robjects  # R is instantiated upon load module

class Rcolgem ():
    def __init__ (self, ncores, nreps, t0=0, fgy_resolution=500., integration_method='rk4'):
        # load Rcolgem package
        robjects.r("require(rcolgem, quietly=TRUE)")

        # default settings
        robjects.r('n.cores=%d; nreps=%d; fgyResolution=%d; integrationMethod="%s"; t0=%f' % (
            ncores, nreps, fgy_resolution, integration_method, t0))

        # set up parallelization environment
        robjects.r("require(parallel, quietly=TRUE)")
        robjects.r("cl <- makeCluster(%d, 'FORK')" % (ncores,))

    def init_SI_model (self):
        """
        Defines a susceptible-infected-recovered model in rcolgem.
        :return:
        """

        # define ODE system - as strings, these will be evaluated with new parameters
        robjects.r('demes <- c("I")')

        robjects.r('births <- rbind(c("parms$beta*S*I / (S+I)"))')
        robjects.r('rownames(births) <- colnames(births) <- demes')
Example #9
0
 def tearDown(self):
     rinterface.set_writeconsole(rinterface.consolePrint)
     rinterface.set_readconsole(rinterface.consoleRead)
     rinterface.set_readconsole(rinterface.consoleFlush)
     rinterface.set_choosefile(rinterface.chooseFile)
     sys.last_value = None
Example #10
0
import sys
from rpy2.rinterface import set_readconsole
set_readconsole(None)

import rpy2.robjects as robjects  # R is instantiated upon load module

class Rcolgem ():
    def __init__ (self, ncores, nreps, t0=0, fgy_resolution=500., integration_method='rk4', seed=None):
        # load Rcolgem package
        robjects.r("require(rcolgem, quietly=TRUE)")

        # default settings
        robjects.r('n.cores=%d; nreps=%d; fgyResolution=%d; integrationMethod="%s"; t0=%f' % (
            ncores, nreps, fgy_resolution, integration_method, t0))

        # set up parallelization environment
        robjects.r("require(parallel, quietly=TRUE)")

        if (ncores > 1):
            robjects.r("cl <- makeCluster(%d, 'FORK')" % (ncores,))
            if seed is not None:
                robjects.r("clusterSetRNGStream(cl, {})".format(seed))
        else:
            robjects.r("cl <- NULL")
            if seed is not None:
                robjects.r("set.seed({})".format(seed))

    def init_SI_model (self):
        """
        Defines a susceptible-infected-recovered model in rcolgem.
        :return: