def calculateFrequency(d11, z):
    colSize = d11.shape[1]
    diff = nzeros([3, colSize], dtype=float)
    diff[0, :] = nabs(nround(
        (d11[int((z - 3.)) - 1] - d11[int((z - 2.)) - 1])))
    diff[1, :] = nabs(nround(
        (d11[int((z - 2.)) - 1] - d11[int((z - 1.)) - 1])))
    diff[2, :] = nabs(nround((d11[int((z - 1.)) - 1] - d11[int(z) - 1])))
    w = scp.stats.mode(diff)
    return w
Esempio n. 2
0
    def _section_fire(self):  # {{{
        fire_origin = self._fire_origin()
        times, hrrs = self._draw_fire_development()
        fire_properties = self._draw_fire_properties(len(times))
        self._fire_obstacle()
        area = nround(npa(hrrs) / (self.hrrpua * 1000) + 0.1, decimals=1)
        fire_origin = self._fire_origin()

        txt = (
            '!! FIRE,compa,x,y,z,fire_number,ignition_type,ignition_criterion,ignition_target,?,?,name',
            fire_origin,
            '',
            '!! CHEMI,?,?,?,?',
            'CHEMI,1,1.8,0.3,0.05,0,0.283,{}'.format(
                fire_properties['heatcom']),
            '',
            'TIME,' + ','.join(str(i) for i in times),
            'HRR,' + ','.join(str(round(i, 3)) for i in hrrs),
            fire_properties['sootyield'],
            fire_properties['coyield'],
            fire_properties['trace'],
            'AREA,' + ','.join(str(i) for i in area),
            fire_properties['heigh'],
        )
        return "\n".join(txt) + "\n"
Esempio n. 3
0
    def is_conversed(cls, vbs, i, th):
        dst = False
        if i >= cls.min_itr:
            vb_prv = nround(vbs[i - 1], decimals=cls.decimals)
            vb_cur = nround(vbs[i], decimals=cls.decimals)
            vb_diff = vb_cur - vb_prv
            dst = True if vb_diff < th else False
        if dst:
            logger.info(' '.join([
                'Conversed.',
                'iteration at %d.' % i,
                'VB diff %f < %f' % (vb_diff, th),
                '%3d: %f' % (i - 1, vbs[i - 1]),
                '%3d: %f' % (i, vbs[i]),
            ]))

        return dst
Esempio n. 4
0
def check_grid_match(reservoir_geom, lon_min, lon_max, lon_inc,
                     lat_min, lat_max, lat_inc):
    """ Check whether queried results grid matches the results
    grid available from the xml file.
    Right now, this only checks if the two grids are identical,
    and does not check whether one grid has same resolution
    but is of a different total dimension.

    :param reservoir_geom: dict keys: [x, y, z] each element contains
        a list of values describing the edges of the forecast areas.
    :param lon_min: minimum longitude of xml result.
    :param lon_max: maximum longitude of xml result.
    :param lat_min: minimum longitude of xml result.
    :param lat_max: maximum longitude of xml result.

    :rtype: Bool describing whether thegrid matches.
    """
    model_lon = nround(arange(lon_min, lon_max + lon_inc, lon_inc), 2).\
        tolist()
    model_lat = nround(arange(lat_min, lat_max + lat_inc, lat_inc), 2).\
        tolist()

    # compare with reservoir geom
    matching_lon = compare_arrays(model_lon, reservoir_geom['x'])
    matching_lat = compare_arrays(model_lat, reservoir_geom['y'])

    # Figure out what to do for non-matching depths
    # where depth within range, allow and scale expected
    # values accordingly
    # where depth values are out of range, return full
    # expected value?
    grid_match = True
    if not matching_lon:
        logger.warn("input longitudes do not match model longitudes "
                    "new grid will be generated")
        grid_match = False
    if not matching_lat:
        logger.warn("input latitudes do not match model latitudes "
                    "new grid will be generated")
        grid_match = False
    return grid_match
Esempio n. 5
0
 def check_vb_increase(cls, vbs, i):
     dst = False
     if i < 1:
         dst = True
     else:
         vb_prv = nround(vbs[i - 1], decimals=cls.decimals)
         vb_cur = nround(vbs[i], decimals=cls.decimals)
         vb_diff = vb_cur - vb_prv
         if vb_diff < 0:
             logger.error(' '.join([
                 'vb decreased.',
                 'diff: %.10f' % vb_diff,
                 'iter %3d: %.10f' % (i, vb_cur),
                 'iter %3d: %.10f' % (i - 1, vb_prv),
             ]))
             dst = False
         if vb_cur == vb_prv:
             dst = True
         else:
             dst = True
     return dst
def calculateTripleFrequency(remainder, strobe):
    a = np.array([1., 2., 3.])
    remainder1 = remainder.copy()
    remainder2 = remainder1.copy() - 0.6
    strobeLen = strobe.shape[1]
    aLen = a.shape[1]
    fre_1 = nzeros([strobeLen, aLen], dtype=float)
    for i in narange(1., (strobeLen) + 1):
        for j in narange(1., (aLen) + 1):
            fre_1[int(i) - 1, int(j) - 1] = ndot(strobe[int(i) - 1],
                                                 a[int(j) - 1])

    t = np.shape(fre_1)
    iter = 1.
    remainder2Len = remainder2.shape[1]
    freq_plus = nzeros([t[0, 0] * t[0, 1], remainder2Len])
    freq_minus = nzeros([t[0, 0] * t[0, 1], remainder2Len])
    freq_plus_shift_negative1 = nzeros([t[0, 0] * t[0, 1], remainder2Len])
    freq_plus_shift_negative2 = nzeros([t[0, 0] * t[0, 1], remainder2Len])

    for i in narange(1., (t[0, 0]) + 1):
        for j in narange(1., (t[0, 1]) + 1):
            fre_11 = fre_1[int(i) - 1, int(j) - 1].copy()
            remainder_1 = remainder2[int(i) - 1, :].copy()
            for k in narange(1., remainder2Len + 1):
                if remainder_1[0, int(k) - 1] > 0.:
                    freq_plus[int(iter) - 1, int(k) -
                              1] = fre_11 + remainder_1[0, int(k) - 1]
                    freq_minus[int(iter) - 1, int(k) -
                               1] = fre_11 - remainder_1[0, int(k) - 1]
                    freq_plus_shift_negative1[
                        int(iter) - 1, int(k) -
                        1] = fre_11 + 30. - remainder_1[0, int(k) - 1]
                    freq_plus_shift_negative2[
                        int(iter) - 1, int(k) -
                        1] = fre_11 - 30. - remainder_1[0, int(k) - 1]

            iter = iter + 1.

    est_fre = np.vstack((freq_plus, freq_minus, freq_plus_shift_negative1,
                         freq_plus_shift_negative2))
    frequency1 = nround(est_fre)
    frequency2 = nfloor(est_fre)
    return [frequency1, frequency2]
# grid.
lon_min = 5.55
lon_max = 19.45
lat_min = 35.85
lat_max = 47.85
lon_increment = 0.1
lat_increment = 0.1
z_max = 0.0
z_min = -30000.0

mag_start = 4.95
mag_end = 9.05
mag_increment = 0.1

# avoid precision errors by rounding.
lon_list = nround(arange(lon_min, lon_max, lon_increment), 2).tolist()
lat_list = nround(arange(lat_min, lat_max, lat_increment), 2).tolist()

RAMSIS_WORKER_SFM_DEFAULTS = {
    "reservoir": {
        "geom": {
            "x": lon_list,
            "y": lat_list,
            "z": [z_min, z_max]
        }
    },
    "model_parameters": {
        # If epoch_duration is None, will make single forecast for the whole
        # time between dateime_start and datetime_end
        "epoch_duration": None,
        "model_min_mag": mag_start,
Esempio n. 8
0
    def normalize_response(response,model,fit_name):
        constraints = ro.r('constraints')
        param = constraints(model, fit_name)
        norm_response = response/(param.rx2('norm')[0]/100.)
        fixedP = param.rx2('fixedP')
        return norm_response, fixedP
    R_output = ""
    data_array = asarray(zip(*data))
    dose = data_array[0]; response = data_array[1]; experiment = data_array[2]
    model = model_drm(fit_name,dose,response)
    if isinstance(model,basestring): # error string
        R_output += model
        return None, data, R_output
    if normalize:
        norm_response,fixedP = normalize_response(response,model,fit_name)
        norm_data = zip(dose,nround(norm_response,2),experiment)
        # Re-fit normalized data
        model = model_drm(fit_name,dose,norm_response, fixed=fixedP)
        if isinstance(model,basestring):
            R_output += model
            return None, norm_data, R_output
        return model, norm_data, R_output
    else:
        return model, data, R_output

def get_coeffs(model, fit_name):
    constraints = ro.r('constraints')
    coeff_names = [x.strip('=') for x in constraints(model, fit_name).rx2('KoefName')]
    coeffs = list(model.rx2(2).rx2('par'))
    return zip(coeff_names,coeffs)
Esempio n. 9
0
u_1.dtype = 'int'
u_1 %= 20
u_2.dtype = 'int'
u_2 %= 20
# generate features
#     initial features with N(0, 1)
#     change variance
#     change expectation
#     take first two numbers after decimal point as significant digits
features_1 = random.randn(number_of_each_label, dimension)
features_2 = random.randn(number_of_each_label, dimension)
features_1 *= sigma_1
features_1 += u_1
features_2 *= sigma_2
features_2 += u_2
features_1 = nround(features_1, 2)
features_2 = nround(features_2, 2)
# generate labels
labels_1 = array(1)
labels_2 = array(0)
labels_1 = tile(labels_1, (number_of_each_label, 1))
labels_2 = tile(labels_2, (number_of_each_label, 1))
# merge features and labels
data_1 = concatenate((features_1, labels_1), axis=1)
data_2 = concatenate((features_2, labels_2), axis=1)
data = concatenate((data_1, data_2))
# restore these data into data.csv
save("data.npy", data)
# move the file data.npy into ../data/
try:
    mkdir('../data/')