示例#1
0
    def get_range_values(self, kwargs, ranger_name):
        """
        For the ranger given by ranger_name look in kwargs and return
        the array with all the possible values.
        """
        if ranger_name not in kwargs:
            return None
        if str(kwargs[ranger_name]) not in kwargs:
            return None

        range_values = []
        try:
            range_data = json.loads(str(kwargs[str(kwargs[ranger_name])]))
        except Exception:
            try:
                range_data = [x.strip() for x in str(kwargs[str(kwargs[ranger_name])]).split(',') if len(x.strip()) > 0]
                return range_data
            except Exception:
                self.logger.exception("Could not launch operation !")
                raise LaunchException("Could not launch with no data from:" + str(ranger_name))
        if type(range_data) in (list, tuple):
            return range_data

        if (constants.ATT_MINVALUE in range_data) and (constants.ATT_MAXVALUE in range_data):
            lo_val = float(range_data[constants.ATT_MINVALUE])
            hi_val = float(range_data[constants.ATT_MAXVALUE])
            step = float(range_data[constants.ATT_STEP])
            range_values = list(Range(lo=lo_val, hi=hi_val, step=step, mode=Range.MODE_INCLUDE_BOTH))

        else:
            for possible_value in range_data:
                if range_data[possible_value]:
                    range_values.append(possible_value)
        return range_values
示例#2
0
    def configure(self,
                  time_series,
                  mother=None,
                  sample_period=None,
                  normalisation=None,
                  q_ratio=None,
                  frequencies='Range',
                  frequencies_parameters=None):
        """
        Store the input shape to be later used to estimate memory usage. Also
        create the algorithm instance.
        """
        self.input_shape = time_series.read_data_shape()
        log_debug_array(LOG, time_series, "time_series")

        ##-------------------- Fill Algorithm for Analysis -------------------##
        algorithm = ContinuousWaveletTransform()
        if mother is not None:
            algorithm.mother = mother

        if sample_period is not None:
            algorithm.sample_period = sample_period

        if (frequencies_parameters is not None
                and 'lo' in frequencies_parameters
                and 'hi' in frequencies_parameters and
                frequencies_parameters['hi'] != frequencies_parameters['lo']):
            algorithm.frequencies = Range(**frequencies_parameters)

        if normalisation is not None:
            algorithm.normalisation = normalisation

        if q_ratio is not None:
            algorithm.q_ratio = q_ratio

        self.algorithm = algorithm
        self.algorithm.time_series = time_series
示例#3
0
 def test_generates_range_with_challenging_float_point_arithmetics(self):
     floats = list(Range(lo=0.0, hi=2.2, step=0.7))
     self.assertEqual(floats, [0.0, 0.7, 1.4, 2.1])
示例#4
0
 def test_generates_range_with_negative_end_but_excluding_start(self):
     floats = list(
         Range(lo=1.0, hi=-3.0, step=1.0, mode=Range.MODE_INCLUDE_END))
     self.assertEqual(floats, [0.0, -1.0, -2.0, -3.0])
示例#5
0
 def test_generates_range_with_negative_end_including_both(self):
     floats = list(
         Range(lo=1.0, hi=-3.0, step=1.0, mode=Range.MODE_INCLUDE_BOTH))
     self.assertEqual(floats, [1.0, 0.0, -1.0, -2.0, -3.0])
示例#6
0
 def test_generates_range_with_negative_end(self):
     floats = list(Range(lo=1.0, hi=-3.0, step=1.0))
     self.assertEqual(floats, [1.0, 0.0, -1.0, -2.0])
示例#7
0
 def test_generates_range_with_only_end_included(self):
     floats = list(
         Range(lo=0.0, hi=3.0, step=1.0, mode=Range.MODE_INCLUDE_END))
     self.assertEqual(floats, [1.0, 2.0, 3.0])
示例#8
0
 def test_generates_range_with_start_and_end_excluded(self):
     floats = list(
         Range(lo=0.0, hi=3.0, step=1.0, mode=Range.MODE_EXCLUDE_BOTH))
     self.assertEqual(floats, [1.0, 2.0])
示例#9
0
 def test_generates_range_with_start_stop_and_periodic_repeating_step(self):
     floats = list(Range(lo=0.0, hi=1.0, step=1. / 3))
     self.assertEqual(floats,
                      [0.0, 0.333333333333, 0.666666666666, 0.999999999999])
示例#10
0
 def test_generates_range_with_start_stop_and_step_smaller_than_one(self):
     floats = list(Range(lo=0.0, hi=0.5, step=0.1))
     self.assertEqual(floats, [0.0, 0.1, 0.2, 0.3, 0.4])
示例#11
0
 def test_generates_range_with_start_and_stop(self):
     floats = list(Range(lo=1.0, hi=3.0, step=1.0))
     self.assertEqual(floats, [1.0, 2.0])
示例#12
0
 def test_generates_range_with_only_stop_provided(self):
     floats = list(Range(hi=3.0, step=1.0))
     self.assertEqual(floats, [0.0, 1.0, 2.0])
示例#13
0
class MyNewModelNameHere(models.Model):
    """
    .. [REF_2012] Name A and Then B. * Main Reference Title*. 
        Journal of Wonderful Research Vol, start.page-end.page, YYYY.   
     
    .. [REF2_2012] Idem 
   
    See also, http://www.scholarpedia.org/My_Model_is_in_scholarpedia
    
    .. automethod:: __init__
    
    """

    _ui_name = "My model's name that will be displayed in the web user interface(My Model Name)"
    #Define traited attributes for this model

    par_1 = FloatArray(
        label=":math:`\\par_{1}`",
        default=numpy.array([
            "Insert default value as float number. Ex: 0.5",
        ]),
        range=Range(lo="Insert minimum_value here. Ex: 0.0",
                    hi="Insert maximum_value here. Ex: 1.0)"),
        doc=
        """ Description of the physical magnitude or the effect of this parameter [units] """
    )

    par_2 = Integer(
        label=":math:`\\par_{2}`",
        default=numpy.array([
            "default value as integer number. Ex: 5",
        ]),
        range=Range(lo="Insert minimum_value. Ex. 0",
                    hi="Insert maximum_value. Ex: 10"),
        doc=
        """ Description of the physical magnitude or the effect of this parameter [units] """
    )

    # Define the range of possible values that the state variables can have.
    # This will be used to set the initial conditions
    state_variable_range = Dict(
        label="State Variable ranges [lo, hi]",
        default={
            "my_first_state_variable_name":
            numpy.array(
                ["low_value_first_variable", "high_value_first_variable"]),
            "my_second_state_variable_name":
            numpy.array(
                ["low_value_second_variable", "high_value_second_variable"])
        },
        doc="""The values for each state-variable should be set to encompass
            the expected dynamic range of that state-variable for the current 
            parameters, it is used as a mechanism for bounding random inital 
            conditions when the simulation isn't started from an explicit
            history, it is also provides the default range of phase-plane plots."""
    )

    # If the MyNewModel does not have more than 1 mode, then leave this piece of code as it is
    number_of_modes = Integer(label="Number of modes",
                              default=1,
                              doc=""" Number of modes of the model """)

    def __init__(self, **kwargs):
        """
        Initialise parameters
        
        """

        super(MyNewModelNameHere, self).__init__(**kwargs)

        #state variables names
        self._state_variables = [
            "my_first_state_variable_name", "my_second_state_variable_name"
        ]

        # number of state variables
        self._nvar = 2
        self.cvar = numpy.array([0], dtype=numpy.int32)

        # the variable of interest
        self.voi = numpy.array([0], dtype=numpy.int32)

        #If there are derived parameters from the predefined parameters, then initialize them to None
        self.A = None
        self.B = None

    def dfun(self, state_variables, coupling, local_coupling=0.0):
        """
        The equations were taken from [REF_2012]
        cf. Eqns. (00) and (01), page 2
        
        .. math::
            \\dot{my_first_state_variable} &= 
            \\dot{my_second_state_variable} &=
               
        """

        my_first_state_variable_name = state_variables[0, :]
        my_second_state_variable_name = state_variables[1, :]

        # global coupling
        my_first_global_coupling_coefficient = coupling[0, :]

        dmy_first_state_variable_name = "Write the first state variable differential equation"
        dmy_second_state_variable_name = "Write the second state variable differential equation"

        derivative = numpy.array(
            [dmy_first_state_variable_name, dmy_second_state_variable_name])
        return derivative

        def update_derived_parameters(self):
            """
            Calculate coefficients for the neural field model based on [REF_2012].
            cf. Eqns (X.X) and (Y.Y), page aaa
           
            Include equations here
            
            .. math::
                A &= equation
                B &= equation
                
            """

            self.A = "Insert equation here"
            self.B = "Insert equation here"
示例#14
0
 def test_generates_range_with_start_and_end_included(self):
     floats = list(
         Range(lo=0.0, hi=3.0, step=1.0, mode=Range.MODE_INCLUDE_BOTH))
     assert floats == [0.0, 1.0, 2.0, 3.0]
示例#15
0
 def test_generates_range_with_start_and_stop(self):
     floats = list(Range(lo=1.0, hi=3.0, step=1.0))
     assert floats == [1.0, 2.0]