Params: depth, duration, slope, t0
970250
def traptransit_lhood(pars, ts, fs, sigs, maxslope=MAXSLOPE):
    
    if pars[0] < 0 or pars[1] < 0 or pars[2] < 2 or pars[2] > maxslope:
        return -np.inf

    fmod = traptransit(ts, pars)
    tot = 0
    for i in range(len(ts)):
        tot += -0.5*(fmod[i] - fs[i])*(fmod[i] - fs[i]) / (sigs[i]*sigs[i])
        #tot += np.log(1./pars[2]) #logflat prior on slope

    return tot
14118
def length(self, t0=0, t1=1, error=LENGTH_ERROR, min_depth=LENGTH_MIN_DEPTH):
        """"""
        if t0 == 0 and t1 == 1:
            if self._length_info['bpoints'] == self.bpoints() \
                    and self._length_info['error'] >= error \
                    and self._length_info['min_depth'] >= min_depth:
                return self._length_info['length']

        # using scipy.integrate.quad is quick
        if _quad_available:
            s = quad(lambda tau: abs(self.derivative(tau)), t0, t1,
                            epsabs=error, limit=1000)[0]
        else:
            s = segment_length(self, t0, t1, self.point(t0), self.point(t1),
                               error, min_depth, 0)

        if t0 == 0 and t1 == 1:
            self._length_info['length'] = s
            self._length_info['bpoints'] = self.bpoints()
            self._length_info['error'] = error
            self._length_info['min_depth'] = min_depth
            return self._length_info['length']
        else:
            return s
1160113
def dM(self, t, param, Mt, tips=None, gaps=None):
        """"""
        assert isinstance(t, float) and t > 0, "Invalid t: {0}".format(t)
        assert (param == 't') or (param in self.freeparams), (
                "Invalid param: {0}".format(param))

        if Mt is None:
            Mt = self.M(t, tips=tips, gaps=gaps)

        if (param == 'mu') or (param == 't'):
            if param == 'mu':
                alpha = t
            else:
                alpha = self.mu
            if tips is None:
                dM_param = broadcastMatrixMultiply(self.Prxy, Mt, alpha=alpha)
            else:
                dM_param = broadcastMatrixVectorMultiply(self.Prxy, Mt, alpha=alpha)
                if gaps is not None:
                    dM_param[gaps] = scipy.zeros(N_CODON, dtype='float')
            return dM_param

        paramval = getattr(self, param)
        if isinstance(paramval, float):
            paramisvec = False
        else:
            assert isinstance(paramval, numpy.ndarray) and paramval.ndim == 1
            paramisvec = True
            paramlength = paramval.shape[0]

        if ('expD', t) not in self._cached:
            self._cached[('expD', t)] = scipy.exp(self.D * self.mu * t)
        expD = self._cached[('expD', t)]

        if ('V', t) not in self._cached:
            if 'Dxx_Dyy' not in self._cached:
                Dyy = scipy.tile(self.D, (1, N_CODON)).reshape(
                        self.nsites, N_CODON, N_CODON)
                Dxx = scipy.array([Dyy[r].transpose() for r in
                        range(self.nsites)])
                self._cached['Dxx_Dyy'] = Dxx - Dyy
            Dxx_Dyy = self._cached['Dxx_Dyy']
            if 'Dxx_Dyy_lt_ALMOST_ZERO' not in self._cached:
                self._cached['Dxx_Dyy_lt_ALMOST_ZERO'] = scipy.fabs(
                        Dxx_Dyy) < ALMOST_ZERO
            Dxx_Dyy_lt_ALMOST_ZERO = self._cached['Dxx_Dyy_lt_ALMOST_ZERO']
            with scipy.errstate(divide='raise', under='ignore',
                    over='raise', invalid='ignore'):
                expDyy = scipy.tile(expD,(1, N_CODON)).reshape(
                        self.nsites, N_CODON, N_CODON)
                expDxx = scipy.array([expDyy[r].transpose() for r in
                        range(self.nsites)])
                V = (expDxx - expDyy) / Dxx_Dyy
            with scipy.errstate(under='ignore'): # OK if some values 0
                scipy.copyto(V, self.mu * t * expDxx, where=
                        Dxx_Dyy_lt_ALMOST_ZERO)
            self._cached[('V', t)] = V
        V = self._cached[('V', t)]

        with scipy.errstate(under='ignore'): # don't worry if some values 0
            if tips is None:
                if not paramisvec:
                    dM_param = broadcastMatrixMultiply(self.A,
                            broadcastMatrixMultiply(self.B[param]
                            * V, self.Ainv))
                else:
                    dM_param = scipy.ndarray((paramlength, self.nsites,
                            N_CODON, N_CODON), dtype='float')
                    for j in range(paramlength):
                        dM_param[j] = broadcastMatrixMultiply(self.A,
                                broadcastMatrixMultiply(self.B[param][j]
                                * V, self.Ainv))
            else:
                if not paramisvec:
                    dM_param = broadcastMatrixVectorMultiply(self.A,
                            broadcastGetCols(broadcastMatrixMultiply(
                            self.B[param] * V, self.Ainv), tips))
                else:
                    dM_param = scipy.ndarray((paramlength, self.nsites,
                            N_CODON), dtype='float')
                    for j in range(paramlength):
                        dM_param[j] = broadcastMatrixVectorMultiply(self.A,
                            broadcastGetCols(broadcastMatrixMultiply(
                            self.B[param][j] * V, self.Ainv), tips))
                if gaps is not None:
                    if not paramisvec:
                        dM_param[gaps] = scipy.zeros(N_CODON, dtype='float')
                    else:
                        dM_param[:, gaps] = scipy.zeros(N_CODON, dtype='float')
        return dM_param
188347
def set_parameters(self):
        
        for key in dir(self):
            if key.startswith('REQUIRES_'):
                setattr(self, key, getattr(self.gmpe, key))
            if key.startswith('DEFINED_'):
                if not key.endswith('FOR_INTENSITY_MEASURE_TYPES'):
                    setattr(self, key, getattr(self.gmpe, key))
741976
def _get_basin_depth_term(self, C, sites, period):
        
        return np.zeros(len(sites.vs30), dtype=float)
852681
def order_param(dts, axis=2):
    """"""
    return np.abs(np.exp(1.0j * dts).mean(axis=axis))
712382
def slope (self):
    
    return (self.p.y - self.q.y) / (self.p.x - self.q.x)
33543
def get_depth_term(self, C, rup):
        
        if rup.ztor > 100.0:
            return C["bSLH"] * 100.0
        else:
            return C["bSLH"] * rup.ztor
695386
def _set_params(self):
        
        deriv0 = np.poly1d(self.eos_params)
        deriv1 = np.polyder(deriv0, 1)
        deriv2 = np.polyder(deriv1, 1)
        deriv3 = np.polyder(deriv2, 1)

        for x in np.roots(deriv1):
            if x > 0 and deriv2(x) > 0:
                v0 = x**(-3./2.)
                break
        else:
            raise EOSError("No minimum could be found")

        derivV2 = 4./9. * x**5. * deriv2(x)
        derivV3 = (-20./9. * x**(13./2.) * deriv2(x) - 8./27. *
                   x**(15./2.) * deriv3(x))
        b0 = derivV2 / x**(3./2.)
        b1 = -1 - x**(-3./2.) * derivV3 / derivV2

        # e0, b0, b1, v0
        self._params = [deriv0(v0**(-2./3.)), b0, b1, v0]
837779
def depth(self, value):
        
        for command in self.subcommands.values():
            command.depth = value + 1
            del command.argparser._defaults[self.arg_label_fmt % self._depth]
            command.argparser._defaults[self.arg_label_fmt % value] = command
        self._depth = value
1066820
function timeParamToSeconds(param) {
	var componentValue = function (si) {
		var regex = new RegExp('(\\d+)' + si);
		return param.match(regex) ? parseInt(RegExp.$1, 10) : 0;
	};

	return componentValue('h') * 3600
		+ componentValue('m') * 60
		+ componentValue('s');
}
711063
def export_event_params(filename, params, count=None, density=None):
    """"""
    heading_row_1 = ['Segment index',
                   'Start time',
                   'End time',
                   'Stitches',
                   'Stage',
                   'Cycle',
                   'Event type',
                   'Channel']
    spacer = [''] * (len(heading_row_1) - 1)

    param_headings_1 = ['Min. amplitude (uV)',
                        'Max. amplitude (uV)',
                        'Peak-to-peak amplitude (uV)',
                        'RMS (uV)']
    param_headings_2 = ['Power (uV^2)',
                        'Peak power frequency (Hz)',
                        'Energy (uV^2s)',
                        'Peak energy frequency (Hz)']
    slope_headings =   ['Q1 average slope (uV/s)',
                        'Q2 average slope (uV/s)',
                        'Q3 average slope (uV/s)',
                        'Q4 average slope (uV/s)',
                        'Q23 average slope (uV/s)',
                        'Q1 max. slope (uV/s^2)',
                        'Q2 max. slope (uV/s^2)',
                        'Q3 max. slope (uV/s^2)',
                        'Q4 max. slope (uV/s^2)',
                        'Q23 max. slope (uV/s^2)']
    ordered_params_1 = ['minamp', 'maxamp', 'ptp', 'rms']
    ordered_params_2 = ['power', 'peakpf', 'energy', 'peakef']

    idx_params_1 = in1d(ordered_params_1, list(params[0].keys()))
    sel_params_1 = list(compress(ordered_params_1, idx_params_1))
    heading_row_2 = list(compress(param_headings_1, idx_params_1))

    if 'dur' in params[0].keys():
        heading_row_2 = ['Duration (s)'] + heading_row_2

    idx_params_2 = in1d(ordered_params_2, list(params[0].keys()))
    sel_params_2 = list(compress(ordered_params_2, idx_params_2))
    heading_row_3 = list(compress(param_headings_2, idx_params_2))

    heading_row_4 = []
    if 'slope' in params[0].keys():
        if next(iter(params[0]['slope']))[0]:
            heading_row_4.extend(slope_headings[:5])
        if next(iter(params[0]['slope']))[1]:
            heading_row_4.extend(slope_headings[5:])

    # Get data as matrix and compute descriptives
    dat = []
    if 'dur' in params[0].keys():
        one_mat = asarray([seg['dur'] for seg in params \
                           for chan in seg['data'].axis['chan'][0]])
        one_mat = reshape(one_mat, (len(one_mat), 1))
        dat.append(one_mat)

    if sel_params_1:
        one_mat = asarray([[seg[x](chan=chan)[0] for x in sel_params_1] \
                for seg in params for chan in seg['data'].axis['chan'][0]])
        dat.append(one_mat)

    if sel_params_2:
        one_mat = asarray([[seg[x][chan] for x in sel_params_2] \
                for seg in params for chan in seg['data'].axis['chan'][0]])
        dat.append(one_mat)

    if 'slope' in params[0].keys():
        one_mat = asarray([[x for y in seg['slope'][chan] for x in y] \
                for seg in params for chan in seg['data'].axis['chan'][0]])
        dat.append(one_mat)

    if dat:
        dat = concatenate(dat, axis=1)
        desc = get_descriptives(dat)

    with open(filename, 'w', newline='') as f:
        lg.info('Writing to ' + str(filename))
        csv_file = writer(f)
        csv_file.writerow(['Wonambi v{}'.format(__version__)])

        if count:
            csv_file.writerow(['Count', count])
        if density:
            csv_file.writerow(['Density', density])

        if dat == []:
            return

        csv_file.writerow(heading_row_1 + heading_row_2 + heading_row_3 \
                          + heading_row_4)
        csv_file.writerow(['Mean'] + spacer + list(desc['mean']))
        csv_file.writerow(['SD'] + spacer + list(desc['sd']))
        csv_file.writerow(['Mean of ln'] + spacer + list(desc['mean_log']))
        csv_file.writerow(['SD of ln'] + spacer + list(desc['sd_log']))
        idx = 0

        for seg in params:
            if seg['cycle'] is not None:
                seg['cycle'] = seg['cycle'][2]

            for chan in seg['data'].axis['chan'][0]:
                idx += 1
                data_row_1 = [seg[x](chan=chan)[0] for x in sel_params_1]
                data_row_2 = [seg[x][chan] for x in sel_params_2]

                if 'dur' in seg.keys():
                    data_row_1 = [seg['dur']] + data_row_1

                if 'slope' in seg.keys():
                    data_row_3 = [x for y in seg['slope'][chan] for x in y]
                    data_row_2 = data_row_2 + data_row_3

                csv_file.writerow([idx,
                                   seg['start'],
                                   seg['end'],
                                   seg['n_stitch'],
                                   seg['stage'],
                                   seg['cycle'],
                                   seg['name'],
                                   chan,
                                   ] + data_row_1 + data_row_2)
1220427
def length(self, t0=0, t1=1, error=LENGTH_ERROR, min_depth=LENGTH_MIN_DEPTH):
        """"""
        assert 0 <= t0 <= 1 and 0 <= t1 <= 1
        if _quad_available:
            return quad(lambda tau: abs(self.derivative(tau)), t0, t1,
                        epsabs=error, limit=1000)[0]
        else:
            return segment_length(self, t0, t1, self.point(t0), self.point(t1),
                                  error, min_depth, 0)
638141
def params(self):
        """"""
        par = {"radius": self.radius,
               "sphere_index": self.sphere_index,
               "pha_offset": self.pha_offset,
               "center": [self.posx_offset, self.posy_offset]
               }
        return par
1069250
def get_parameters(self, params, graph=None):
        
        g = graph if graph is not None else self.tf_graph

        with g.as_default():
            with tf.Session() as self.tf_session:
                self.tf_saver.restore(self.tf_session, self.model_path)
                out = {}
                for par in params:
                    if type(params[par]) == list:
                        for i, p in enumerate(params[par]):
                            out[par + '-' + str(i+1)] = p.eval()
                    else:
                        out[par] = params[par].eval()
                return out
860824
def add_rup_params(self, rupture):
        
        for param in self.REQUIRES_RUPTURE_PARAMETERS:
            if param == 'mag':
                value = rupture.mag
            elif param == 'strike':
                value = rupture.surface.get_strike()
            elif param == 'dip':
                value = rupture.surface.get_dip()
            elif param == 'rake':
                value = rupture.rake
            elif param == 'ztor':
                value = rupture.surface.get_top_edge_depth()
            elif param == 'hypo_lon':
                value = rupture.hypocenter.longitude
            elif param == 'hypo_lat':
                value = rupture.hypocenter.latitude
            elif param == 'hypo_depth':
                value = rupture.hypocenter.depth
            elif param == 'width':
                value = rupture.surface.get_width()
            else:
                raise ValueError('%s requires unknown rupture parameter %r' %
                                 (type(self).__name__, param))
            setattr(rupture, param, value)
1306813
def click_estimate_slope():
    

    c1 = _pylab.ginput()
    if len(c1)==0:
        return None

    c2 = _pylab.ginput()
    if len(c2)==0:
        return None

    return (c1[0][1]-c2[0][1])/(c1[0][0]-c2[0][0])