returns the deviatoric component of the stress
760440
def deviator_stress(self):
        
        if not self.is_symmetric:
            raise warnings.warn("The stress tensor is not symmetric, "
                                "so deviator stress will not be either")
        return self - self.mean_stress*np.eye(3)
22408
def components(self):
        ''''''
        p = ''
        neg = self.totaldays < 0
        y = self.years
        m = self.months
        w = self.weeks
        d = self.days
        if y:
            p = '%sY' % abs(y)
        if m:
            p = '%s%sM' % (p, abs(m))
        if w:
            p = '%s%sW' % (p, abs(w))
        if d:
            p = '%s%sD' % (p, abs(d))
        return '-'+p if neg else p
578872
def damping(self):
        """"""
        try:
            value = self._damping.value
        except AttributeError:
            value = self._damping
        return value
1168549
def regress_components( data, components, remove_mean=True ):
    
    timepoints = data.shape[0]
    betas = np.linalg.pinv(components).dot(data)
    if remove_mean:
        datahat = components.dot(betas)
    else:  # disregard the first layer of X, which is degree 0
        datahat = components[:, 1:].dot(betas[1:, ...])
    regressed_data = data - datahat
    return regressed_data
857844
def energy_density(self, strain, convert_GPa_to_eV=True):
        
        e_density = np.sum(self.calculate_stress(strain)*strain) / self.order
        if convert_GPa_to_eV:
            e_density *= self.GPa_to_eV_A3  # Conversion factor for GPa to eV/A^3
        return e_density
601917
def symmetry(self):
        
        symmetry, axis, section = inertia.radial_symmetry(self)
        self._cache['symmetry_axis'] = axis
        self._cache['symmetry_section'] = section
        return symmetry
1302413
def get_yield_stress(self, n):
        
        # TODO: root finding could be more robust
        comp = root(self.get_stability_criteria, -1, args=n)
        tens = root(self.get_stability_criteria, 1, args=n)
        return (comp.x, tens.x)
1054237
function(){
        this.constraint.restitution=this.mixRestitution(this.shape1.restitution,this.shape2.restitution);
        this.constraint.friction=this.mixFriction(this.shape1.friction,this.shape2.friction);
        var numBuffers=this.manifold.numPoints;
        var i = numBuffers;
        while(i--){
        //for(var i=0;i<numBuffers;i++){
            var b=this.buffer[i];
            var p=this.points[i];
            b.lp1X=p.localPoint1.x;
            b.lp1Y=p.localPoint1.y;
            b.lp1Z=p.localPoint1.z;
            b.lp2X=p.localPoint2.x;
            b.lp2Y=p.localPoint2.y;
            b.lp2Z=p.localPoint2.z;
            b.impulse=p.normalImpulse;
        }
        this.manifold.numPoints=0;
        this.detector.detectCollision(this.shape1,this.shape2,this.manifold);
        var num=this.manifold.numPoints;
        if(num==0){
            this.touching=false;
            return;
        }
        this.touching=true;
        i = num;
        while(i--){
        //for(i=0; i<num; i++){
            p=this.points[i];
            var lp1x=p.localPoint1.x;
            var lp1y=p.localPoint1.y;
            var lp1z=p.localPoint1.z;
            var lp2x=p.localPoint2.x;
            var lp2y=p.localPoint2.y;
            var lp2z=p.localPoint2.z;
            var index=-1;
            var minDistance=0.0004;
            var j = numBuffers;
            while(j--){
            //for(var j=0;j<numBuffers;j++){
                b=this.buffer[j];
                var dx=b.lp1X-lp1x;
                var dy=b.lp1Y-lp1y;
                var dz=b.lp1Z-lp1z;
                var distance1=dx*dx+dy*dy+dz*dz;
                dx=b.lp2X-lp2x;
                dy=b.lp2Y-lp2y;
                dz=b.lp2Z-lp2z;
                var distance2=dx*dx+dy*dy+dz*dz;
                if(distance1<distance2){
                    if(distance1<minDistance){
                        minDistance=distance1;
                        index=j;
                    }
                }else{
                    if(distance2<minDistance){
                        minDistance=distance2;
                        index=j;
                    }
                }
            }
            if(index!=-1){
                var tmp=this.buffer[index];
                this.buffer[index]=this.buffer[--numBuffers];
                this.buffer[numBuffers]=tmp;
                p.normalImpulse=tmp.impulse;
                p.warmStarted=true;
            }else{
                p.normalImpulse=0;
                p.warmStarted=false;
            }
        }
    }
712672
def _extract_coeffs(self, imt):
        
        C_HR = self.COEFFS_HARD_ROCK[imt]
        C_BC = self.COEFFS_BC[imt]
        C_SR = self.COEFFS_SOIL_RESPONSE[imt]
        SC = self.COEFFS_STRESS[imt]

        return C_HR, C_BC, C_SR, SC
154322
def from_diff_fit(cls, strains, stresses, eq_stress=None,
                      tol=1e-10, order=3):
        
        c_list = diff_fit(strains, stresses, eq_stress, order, tol)
        return cls(c_list)
430082
def detrend(arr, x=None, deg=5, tol=1e-3, maxloop=10):
    """"""

    xx = numpy.arange(len(arr)) if x is None else x
    base = arr.copy()
    trend = base
    pol = numpy.ones((deg + 1,))
    for _ in range(maxloop):
        pol_new = numpy.polyfit(xx, base, deg)
        pol_norm = numpy.linalg.norm(pol)
        diff_pol_norm = numpy.linalg.norm(pol - pol_new)
        if diff_pol_norm / pol_norm < tol:
            break
        pol = pol_new
        trend = numpy.polyval(pol, xx)
        base = numpy.minimum(base, trend)
    return trend
394589
def get_strain_from_stress(self, stress):
        
        compl_exp = self.get_compliance_expansion()
        strain = 0
        for n, compl in enumerate(compl_exp):
            strain += compl.einsum_sequence([stress]*(n+1)) / factorial(n+1)
        return strain
850323
function elastic(t) {
  return Math.pow(2, -10 * t) * Math.sin((t - 0.075) * (2 * Math.PI) / 0.3) + 1;
}
61079
def _get_style_of_faulting_term(self, C, rake):
        
        f_n, f_r = self._get_fault_type_dummy_variables(rake)
        return C['C6'] * f_n + C['C7'] * f_r
747232
def _deriv_hypot(x, y):
    """"""
    r = np.hypot(x, y)
    df_dx = x / r
    df_dy = y / r
    return np.hstack([df_dx, df_dy])
300078
def gradient_component(self, index1):
        """"""
        result = np.zeros(3, float)
        for index2 in range(self.numc):
            if self.scaling[index1, index2] > 0:
                for (se, ve), (sg, vg) in zip(self.yield_pair_energies(index1, index2), self.yield_pair_gradients(index1, index2)):
                    result += (sg*self.directions[index1, index2]*ve + se*vg)*self.scaling[index1, index2]
        return result
1099140
def _extract_hemispheric_difference(image, mask = slice(None), sigma_active = 7, sigma_reference = 7, cut_plane = 0, voxelspacing = None):
    
    # constants
    INTERPOLATION_RANGE = int(10) # how many neighbouring values to take into account when interpolating the medial longitudinal fissure slice
    
    # check arguments
    if cut_plane >= image.ndim:
        raise ArgumentError('The suppliedc cut-plane ({}) is invalid, the image has only {} dimensions.'.format(cut_plane, image.ndim))
    
    # set voxel spacing
    if voxelspacing is None:
        voxelspacing = [1.] * image.ndim
    
    # compute the (presumed) location of the medial longitudinal fissure, treating also the special of an odd number of slices, in which case a cut into two equal halves is not possible
    medial_longitudinal_fissure = int(image.shape[cut_plane] / 2)
    medial_longitudinal_fissure_excluded = image.shape[cut_plane] % 2
    
    # split the head into a dexter and sinister half along the saggital plane
    # this is assumed to be consistent with a cut of the brain along the medial longitudinal fissure, thus separating it into its hemispheres
    slicer = [slice(None)] * image.ndim
    slicer[cut_plane] = slice(None, medial_longitudinal_fissure)
    left_hemisphere = image[slicer]

    slicer[cut_plane] = slice(medial_longitudinal_fissure + medial_longitudinal_fissure_excluded, None)
    right_hemisphere = image[slicer]
    
    # flip right hemisphere image along cut plane
    slicer[cut_plane] = slice(None, None, -1)
    right_hemisphere = right_hemisphere[slicer]

    # substract once left from right and once right from left hemisphere, including smoothing steps
    right_hemisphere_difference = _substract_hemispheres(right_hemisphere, left_hemisphere, sigma_active, sigma_reference, voxelspacing)
    left_hemisphere_difference = _substract_hemispheres(left_hemisphere, right_hemisphere, sigma_active, sigma_reference, voxelspacing)
    
    # re-flip right hemisphere image to original orientation
    right_hemisphere_difference = right_hemisphere_difference[slicer]
    
    # estimate the medial longitudinal fissure if required
    if 1 == medial_longitudinal_fissure_excluded:
        left_slicer = [slice(None)] * image.ndim
        right_slicer = [slice(None)] * image.ndim
        left_slicer[cut_plane] = slice(-1 * INTERPOLATION_RANGE, None)
        right_slicer[cut_plane] = slice(None, INTERPOLATION_RANGE)
        interp_data_left = left_hemisphere_difference[left_slicer]
        interp_data_right = right_hemisphere_difference[right_slicer]
        interp_indices_left = list(range(-1 * interp_data_left.shape[cut_plane], 0))
        interp_indices_right = list(range(1, interp_data_right.shape[cut_plane] + 1))
        interp_data = numpy.concatenate((left_hemisphere_difference[left_slicer], right_hemisphere_difference[right_slicer]), cut_plane)
        interp_indices = numpy.concatenate((interp_indices_left, interp_indices_right), 0)
        medial_longitudinal_fissure_estimated = interp1d(interp_indices, interp_data, kind='cubic', axis=cut_plane)(0)
        # add singleton dimension
        slicer[cut_plane] = numpy.newaxis
        medial_longitudinal_fissure_estimated = medial_longitudinal_fissure_estimated[slicer]

    # stich images back together
    if 1 == medial_longitudinal_fissure_excluded:
        hemisphere_difference = numpy.concatenate((left_hemisphere_difference, medial_longitudinal_fissure_estimated, right_hemisphere_difference), cut_plane)
    else:
        hemisphere_difference = numpy.concatenate((left_hemisphere_difference, right_hemisphere_difference), cut_plane)

    # extract intensities and return
    return _extract_intensities(hemisphere_difference, mask)