Calculate the variable ``variable_name`` for the period ``period``, using the variable formula if it exists.

            :returns: A numpy array containing the result of the calculation
199859
def calculate(self, variable_name, period, **parameters):
        
        population = self.get_variable_population(variable_name)
        holder = population.get_holder(variable_name)
        variable = self.tax_benefit_system.get_variable(variable_name, check_existence = True)

        if period is not None and not isinstance(period, periods.Period):
            period = periods.period(period)

        if self.trace:
            self.tracer.record_calculation_start(variable.name, period, **parameters)

        self._check_period_consistency(period, variable)

        # First look for a value already cached
        cached_array = holder.get_array(period)
        if cached_array is not None:
            if self.trace:
                self.tracer.record_calculation_end(variable.name, period, cached_array, **parameters)
            return cached_array

        array = None

        # First, try to run a formula
        try:
            self._check_for_cycle(variable, period)
            array = self._run_formula(variable, population, period)

            # If no result, use the default value and cache it
            if array is None:
                array = holder.default_array()

            array = self._cast_formula_result(array, variable)

            holder.put_in_cache(array, period)
        except SpiralError:
            array = holder.default_array()
        finally:
            if self.trace:
                self.tracer.record_calculation_end(variable.name, period, array, **parameters)
            self._clean_cycle_detection_data(variable.name)

        self.purge_cache_of_invalid_values()

        return array
138480
def get_local_variable_from_name(self, variable_name):
        
        return next((v for v in self.variables if v.name == variable_name), None)
166535
def VariablesValues(self, variables, t):
        
        # TODO: put interpolation in variables
        if (t < self.te) | (t > 0):
            i = t//self.ts  # time step
            ti = self.ts*i
            if type(variables) == list:
                values = []
                for variable in variables:
                    # interpolation
                    values.append(
                        variables.values[i]*((ti-t)/self.ts+1)+variables.values[i+1]*(t-ti)/self.ts)
                return values

            else:
                # interpolation
                return variables.values[i]*((ti-t)/self.ts+1)+variables.values[i+1]*(t-ti)/self.ts
        else:
            raise ValueError
1274357
def variable(self, name: str, default_value=None):
        
        return self.__variables.get(name, default_value)
982301
def _var(self):
        
        class Variables(object):
            def __getitem__(_self, name):
                return self.getVariable(name)

            def __setitem__(_self, name, value):
                self.getVariable(name).setValue(value)

            def __iter__(_self):
                return self.getVariables()

        return Variables()
878032
def parse_period(self, period_str):
        
        period = period_str.translate(TRANSLATION_MAP)[3:14].strip()
        return float(period) if period else None
576696
def aggregate_periods(self, periods):
        
        try:
            fieldname = self.raster_field.name
        except TypeError:
            raise exceptions.FieldDoesNotExist('Raster field not found')
        arrays = self.arrays(fieldname)
        arr = arrays[0]
        if len(arrays) > 1:
            if getattr(arr, 'ndim', 0) > 2:
                arrays = np.vstack(arrays)
            fill = getattr(arr, 'fill_value', None)
            arr = np.ma.masked_values(arrays, fill, copy=False)
        # Try to reshape using equal sizes first and fall back to unequal
        # splits.
        try:
            means = arr.reshape((periods, -1)).mean(axis=1)
        except ValueError:
            means = np.array([a.mean() for a in np.array_split(arr, periods)])
        obj = self[0]
        setattr(obj, fieldname, means)
        return [obj]
1058809
def period(self):
        
        return timedelta(seconds=2 * np.pi * np.sqrt(self.kep.a ** 3 / self.mu))
1096072
def formulas_iter(self):
        
        for var in it.ifilter(self.has_node, self.variables()):
            yield var, frozenset(self.predecessors(var))
672230
def get_var_name(nc):
    

    non_variable_names = [
        'lat',
        'lat_bnds',
        'lon',
        'lon_bnds',
        'time',
        'latitude',
        'longitude',
        'bnds'
    ]

    _vars = set(nc.variables.keys())
    _vars.difference_update(set(non_variable_names))
    if len(_vars) == 1:
        return _vars.pop()
    return None
1153188
def _get_value(self, var):
        """"""
        return self._problem._p.getVarByName(self._problem._variables[var]).x
886471
def obfn_gvar(self):
        

        if self.opt['gEvalY']:
            return self.Y
        else:
            return self.cnst_A(None, self.Xf) - self.cnst_c()
441686
def _check_period_consistency(self, period, variable):
        
        if variable.definition_period == periods.ETERNITY:
            return  # For variables which values are constant in time, all periods are accepted

        if variable.definition_period == periods.MONTH and period.unit != periods.MONTH:
            raise ValueError("Unable to compute variable '{0}' for period {1}: '{0}' must be computed for a whole month. You can use the ADD option to sum '{0}' over the requested period, or change the requested period to 'period.first_month'.".format(
                variable.name,
                period
                ))

        if variable.definition_period == periods.YEAR and period.unit != periods.YEAR:
            raise ValueError("Unable to compute variable '{0}' for period {1}: '{0}' must be computed for a whole year. You can use the DIVIDE option to get an estimate of {0} by dividing the yearly value by 12, or change the requested period to 'period.this_year'.".format(
                variable.name,
                period
                ))

        if period.size != 1:
            raise ValueError("Unable to compute variable '{0}' for period {1}: '{0}' must be computed for a whole {2}. You can use the ADD option to sum '{0}' over the requested period.".format(
                variable.name,
                period,
                'month' if variable.definition_period == periods.MONTH else 'year'
                ))
909524
def get_longitude_variables(nc):
    '''
    
    '''
    longitude_variables = []
    # standard_name takes precedence
    for variable in nc.get_variables_by_attributes(standard_name="longitude"):
        longitude_variables.append(variable.name)

    # Then axis
    for variable in nc.get_variables_by_attributes(axis='X'):
        if variable.name not in longitude_variables:
            longitude_variables.append(variable.name)

    check_fn = partial(attr_membership, value_set=VALID_LON_UNITS,
                       modifier_fn=lambda s: s.lower())
    for variable in nc.get_variables_by_attributes(units=check_fn):
        if variable.name not in longitude_variables:
            longitude_variables.append(variable.name)

    return longitude_variables
856881
def _get_variable_names(arr):
    """"""
    if VARIABLELABEL in arr.dims:
        return arr.coords[VARIABLELABEL].tolist()
    else:
        return arr.name
1207415
def get_var(self, name):
        
        for var in self.vars:
            if var.name == name:
                return var
        else:
            raise ValueError
1038334
def _get_unique_variable_name(vname, variables):
    '''
    '''
    count = 2
    vname_base = vname
    while vname in variables:
        vname = '{}_{}'.format(vname_base, count)
        count += 1
    return vname