本文整理汇总了Python中scipy.allclose函数的典型用法代码示例。如果您正苦于以下问题:Python allclose函数的具体用法?Python allclose怎么用?Python allclose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了allclose函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: unnfinished_test_quick_convert_csv_to_arrays_lats_longs_file
def unnfinished_test_quick_convert_csv_to_arrays_lats_longs_file(self):
(handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
os.close(handle)
LONGITUDE = [11.5, 11.6, 11.7, 11.8]
LATITUDE = [-3.1, -3.2, -3.3, -3.4]
WALLS = ['Brick veneer', 'Double Brick', 'Fibro', 'Double Brick']
attribute_dic = {'LONGITUDE': LONGITUDE,
'LATITUDE': LATITUDE,
'WALLS': WALLS}
title_index_dic = {'LONGITUDE': 0,
'LATITUDE': 1,
'WALLS': 2}
util.dict2csv(file_name, title_index_dic, attribute_dic)
print "file_name", file_name
lon = csvi.quick_convert_csv_to_arrays(file_name, LONGITUDE=float)
assert lon.keys()[0] == 'LONGITUDE'
assert len(lon.keys()) == 1
assert scipy.allclose(LONGITUDE, lon['LONGITUDE'])
all_conversions = {'LONGITUDE': float,
'LATITUDE': float,
'WALLS': str}
all = csvi.quick_convert_csv_to_arrays(self.dummy_f, **all_conversions)
assert len(all.keys()) == 3
assert scipy.allclose(LATITUDE, all['LATITUDE'])
assert scipy.allclose(LONGITUDE, all['LONGITUDE'])
assert scipy.allclose(self.WALLS == all['WALLS'])
os.remove(file_name)
开发者ID:dynaryu,项目名称:eqrm,代码行数:32,代码来源:test_csv_interface.py
示例2: test_rigged_pointing
def test_rigged_pointing(self) :
Data = self.blocks[0]
Data.calc_freq()
map = self.map
# Set all data = (f + cal_ind)*time_ind
Data.data[:,:,:,:] = (sp.arange(-4.5, 5)
[:,sp.newaxis,sp.newaxis,sp.newaxis]
*(Data.freq/100e6))
Data.data[...] -= sp.mean(Data.data, 0)
Data.data[...] += (sp.arange(6,8).reshape((1,1,2,1)) * (Data.freq/100e6)
* sp.arange(-4.5, 5).reshape((10, 1, 1, 1)))
map[:,:,:] = 0.0
# Set 10 pixels to match data (except for cal_ind part).
map[:, range(10), range(10)] = (sp.arange(-4.5, 5)[None,:]
* map.get_axis('freq')[:,None]/100e6)
# We should be completely insensitive to the map mean. Th following
# should have no effect.
map[...] += 0.352*map.get_axis('freq')[:, None, None]/800.0e7
# Rig the pointing to point to those 10 pixels.
def rigged_pointing() :
Data.ra = map.get_axis('ra')[range(10)]
Data.dec = map.get_axis('dec')[range(10)]
Data.calc_pointing = rigged_pointing
smd.sub_map(Data, map)
# Now data should be just f*time_ind*(cal_ind+6), within 2.0 MHz/2.
Data.data /= sp.arange(-4.5, 5)[:,sp.newaxis,sp.newaxis,sp.newaxis]
Data.data /= Data.freq/100e6
# Relative tol of 1/700, is the frequency bin width.
self.assertTrue(sp.allclose(Data.data[:,:,0,:], 6.0, rtol=1.0/700))
self.assertTrue(sp.allclose(Data.data[:,:,1,:], 7.0, rtol=1.0/700))
开发者ID:OMGitsHongyu,项目名称:analysis_IM,代码行数:30,代码来源:test_subtract_map_data.py
示例3: _LML_covar
def _LML_covar(self,hyperparams,debugging=False):
"""
log marginal likelihood
"""
try:
KV = self.get_covariances(hyperparams,debugging=debugging)
except LA.LinAlgError:
LG.error('linalg exception in _LML_covar')
return 1E6
except ValueError:
LG.error('value error in _LML_covar')
return 1E6
lml_quad = 0.5*(KV['Ytilde']*KV['UYU']).sum()
lml_det = 0.5 * SP.log(KV['S']).sum()
lml_const = 0.5*self.n*self.t*(SP.log(2*SP.pi))
if debugging:
# do calculation without kronecker tricks and compare
_lml_quad = 0.5 * (KV['alpha']*KV['Yvec']).sum()
_lml_det = SP.log(SP.diag(KV['L'])).sum()
assert SP.allclose(_lml_quad,lml_quad), 'ouch, quadratic form is wrong in _LMLcovar'
assert SP.allclose(_lml_det, lml_det), 'ouch, ldet is wrong in _LML_covar'
lml = lml_quad + lml_det + lml_const
return lml
开发者ID:PMBio,项目名称:pygp_kronsum,代码行数:27,代码来源:gp_kronprod.py
示例4: test_wind_v3_template
def test_wind_v3_template(self):
# Test running an end to end cyclone test based
# on a wind config template.
# The output file
f = tempfile.NamedTemporaryFile(
suffix='.npz',
prefix='HAZIMPt_wind_scenarios_test_const',
delete=False)
wind_dir = os.path.join(misc.EXAMPLE_DIR, 'wind')
exp_filename = os.path.join(wind_dir,
'syn_small_exposure_tcrm.csv')
wind_filename = os.path.join(wind_dir, 'gust01.txt')
a_config = [{TEMPLATE: WINDV3},
{LOADCSVEXPOSURE: {'file_name': exp_filename,
'exposure_latitude': 'LATITUDE',
'exposure_longitude': 'LONGITUDE'}},
{LOADWINDTCRM: [wind_filename]},
{CALCSTRUCTLOSS: {REP_VAL_NAME: 'REPLACEMENT_VALUE'}},
{SAVE: f.name}]
context = hazimp.start(config_list=a_config)
self.assertTrue(allclose(
context.exposure_att['structural_loss'],
context.exposure_att['calced-loss']))
# Only the head node writes a file
if parallel.STATE.rank == 0:
exp_dict = numpy.load(f.name)
self.assertTrue(allclose(exp_dict['structural_loss'],
exp_dict['calced-loss']))
os.remove(f.name)
开发者ID:wcarthur,项目名称:hazimp,代码行数:34,代码来源:test_wind_scenarios.py
示例5: test_gets_axes_right
def test_gets_axes_right(self):
Map = tools.set_up_map(self.Data, (0.0, 5.2), (45, 23), (0.4, 0.5))
Map.calc_axes()
self.Data.calc_freq()
self.assertTrue(sp.allclose(Map.freq, self.Data.freq))
self.assertTrue(sp.allclose(Map.long, tools.calc_bins(0.0, 45, 0.4, "middle")))
self.assertTrue(sp.allclose(Map.lat, tools.calc_bins(5.2, 23, 0.5, "middle")))
开发者ID:kiyo-masui,项目名称:analysis_IM,代码行数:7,代码来源:test_tools.py
示例6: test_calc_annloss_deagg_grid
def test_calc_annloss_deagg_grid(self):
# See documentation/annualised_loss_calc.xls
# for the calculations of the expected values.
lat = scipy.array([-25, -24])
lon = scipy.array([130, 132])
total_building_loss = scipy.array([[2000.0, 5.0],
[ 10.0, 2001.0]])
total_building_value = scipy.array([2020.0, 2030.0])
event_activity = scipy.array([0.01, 0.001])
bins = (1,2)
percent_ann_loss, lat_lon, _, _ = ca.calc_annloss_deagg_grid(
lat,
lon,
total_building_loss,
total_building_value,
event_activity,
bins=bins)
expected_loss = scipy.array([[0.049233, 0.491135]])
expected_lat_lon = scipy.array([[-24.5,130.5],[-24.5,131.5]])
#print "percent_ann_loss", percent_ann_loss
#print "expected_loss", expected_loss
self.failUnless(scipy.allclose(percent_ann_loss, expected_loss))
self.failUnless(scipy.allclose(lat_lon, expected_lat_lon))
开发者ID:dynaryu,项目名称:eqrm,代码行数:27,代码来源:test_calc_annloss.py
示例7: intersect
def intersect(self,e,coords=True,actual=True):
#Returns data about the intersection of self and edge e.
#if coords, return the intersection as a point or false if intersection DNE. If not coords, return true/false
#actual is a boolean for whether the intersection must be on both edges or not.
AA = sp.array(e.a-self.a)
proj = sp.dot(self.dir[0],AA)*unit(self.dir[0])
point = sp.array(self.a+proj) #One issue with this method is in case of parallel edges, it returns a rather arbitrary point on self.
if actual:
#Here the parallels are solved because the erroneous intersections won't be on both lines.
if self.containsPoint(point) and e.containsPoint(point):
if coords: return point
return True
return False
else:
#Here we have to check that the point is at least colinear with both.
EAP = sp.array(point-e.a)
EBP = sp.array(point-e.b)
SAP = sp.array(point-self.a)
SBP = sp.array(point-self.b)
s1 = EAP[0]/EBP[0]
s2 = SAP[0]/EBP[0]
if sp.allclose(EAP/EBP,s1,1e-8,0) and sp.allclose(SAP/SBP,s2,1e-8,0):
if coords: return point
return True
return False
开发者ID:nick-parker,项目名称:python3Dplay,代码行数:25,代码来源:Basics.py
示例8: test_calc_activities_Characteristic
def test_calc_activities_Characteristic(self):
## As far as I can tell you can regard this function as generating
## events for testing.
def make_bins(min_mag,max_magnitude,num_bins,
recurrence_model_dist = 'bounded_gutenberg_richter'):
if (recurrence_model_dist == 'characteristic'):
m2=0.5
m_c=max_magnitude-m2
delta_mag = (m_c-min_mag)/(num_bins)
bins = r_[min_mag+delta_mag/2:m_c-delta_mag/2:(num_bins)*1j]
characteristic_bin = array([m_c+(m2/2)])
bins = append(bins,characteristic_bin)
else:
delta_mag = (max_magnitude-min_mag)/num_bins
bins = r_[min_mag+delta_mag/2:max_magnitude-delta_mag/2:num_bins*1j]
#approximate the number of earthquakes in discrete (0.1 unit) bins
return bins
max_magnitude = 7.0
min_magnitude = 4.0
slip_rate_mm = 2.0
area_kms = float(30*10)
b = 1.
prob_number_of_mag_sample_bins = 10
bin_centroids = make_bins(min_magnitude, max_magnitude,
prob_number_of_mag_sample_bins,
'characteristic')
# event_bins = r_[0:10]
# event_bins = sorted(event_bins)
#
A_minCharacteristic = calc_A_min_from_slip_rate_Characteristic(
b, min_magnitude,
max_magnitude,
slip_rate_mm, area_kms)
pdfs = calc_activities_Characteristic(bin_centroids, b,
min_magnitude,
max_magnitude)
# event_activity_source = array(
# [(A_minCharacteristic*pdfs[z]/(sum(where(
# event_bins == z, 1,0)))) for z in event_bins])
event_activity_source = array(A_minCharacteristic*pdfs)
self.assert_(allclose(sum(event_activity_source),A_minCharacteristic))
self.assert_(allclose(event_activity_source,[1.09104980e-02,
6.13542392e-03,
3.45020242e-03,
1.94019140e-03,
1.09104980e-03,
6.13542392e-04,
3.45020242e-04,
1.94019140e-04,
1.09104980e-04,
6.13542392e-05,
4.60091887e-04]))
开发者ID:dynaryu,项目名称:eqrm,代码行数:60,代码来源:test_recurrence_functions.py
示例9: test_small_checkable
def test_small_checkable(self):
# See documentation/annualised_loss_calc.xls
# for the calculations of the expected values.
saved_ecloss = [[2000.0, 5.0],
[ 10.0, 2001.0]]
saved_ecbval2 = [2020.0, 2030.0]
nu = [0.01, 0.001]
expected_ann_loss = scipy.array([19.95996, 0.4928386])
expected_cum_ann_loss = scipy.array([
[1000, 90.909090],
[19.95996, 0.0],
[0.4928386, 0.0]])
# call function
(ann_loss,
cum_ann_loss) = ca.calc_annloss(saved_ecloss, saved_ecbval2, nu)
#print('expected_ann_loss=%s' % str(expected_ann_loss))
#print('ann_loss=%s' % str(ann_loss))
#print('cum_ann_loss=%s' % str(cum_ann_loss))
# test return values
self.failUnless(scipy.allclose(ann_loss, expected_ann_loss))
self.failUnless(scipy.allclose(cum_ann_loss, expected_cum_ann_loss))
开发者ID:dynaryu,项目名称:eqrm,代码行数:28,代码来源:test_calc_annloss.py
示例10: test_lowrank_ard
def test_lowrank_ard(self):
theta = SP.array(SP.random.randn(1+self.n_train)**2)
theta_hat = SP.exp(2*theta)
_K = theta_hat[0]*SP.dot(self.Xtrain,self.Xtrain.T) + SP.diag(theta_hat[1:])
_Kcross = theta_hat[0]*SP.dot(self.Xtrain,self.Xtest.T)
_Kgrad_theta = 2*theta_hat[0]*SP.dot(self.Xtrain,self.Xtrain.T)
cov = lowrank.LowRankArdCF(n_dimensions=self.n_dimensions,n_hyperparameters=self.n_train+1)
cov.X = self.Xtrain
cov.Xcross = self.Xtest
K = cov.K(theta)
Kcross = cov.Kcross(theta)
assert SP.allclose(K,_K), 'ouch, covariance matrix is wrong'
assert SP.allclose(Kcross,_Kcross), 'ouch, cross covariance matrix is wrong'
assert SP.allclose(_Kgrad_theta,cov.Kgrad_theta(theta,0)), 'ouch gradient with respect to theta[0] is wrong'
# gradient with respect to parameters of the diagonal matrix
for i in range(self.n_train):
Kgrad_theta = cov.Kgrad_theta(theta,i+1)
_Kgrad_theta = SP.zeros(Kgrad_theta.shape)
_Kgrad_theta[i,i] = 2*theta_hat[i+1]
assert SP.allclose(Kgrad_theta, _Kgrad_theta), 'ouch gradient with respect to theta[%d] is wrong'%(i+1)
# gradient with respect to latent factors
for i in range(self.n_dimensions):
for j in range(self.n_train):
Xgrad = SP.zeros(self.Xtrain.shape)
Xgrad[j,i] = 1
_Kgrad_x = theta_hat[0]*(SP.dot(Xgrad,self.Xtrain.T) + SP.dot(self.Xtrain,Xgrad.T))
Kgrad_x = cov.Kgrad_x(theta,i,j)
assert SP.allclose(Kgrad_x,_Kgrad_x), 'ouch, gradient with respect to x is wrong for entry [%d,%d]'%(i,j)
开发者ID:PMBio,项目名称:pygp_kronsum,代码行数:34,代码来源:test_covar.py
示例11: test_lowrank_iso
def test_lowrank_iso(self):
theta = SP.array(SP.random.randn(2)**2)
theta_hat = SP.exp(2*theta)
_K = theta_hat[0]*SP.dot(self.Xtrain,self.Xtrain.T) + theta_hat[1]*SP.eye(self.n_train)
_Kcross = theta_hat[0]*SP.dot(self.Xtrain,self.Xtest.T)
_Kgrad_theta = []
_Kgrad_theta.append(2*theta_hat[0]*SP.dot(self.Xtrain,self.Xtrain.T) )
_Kgrad_theta.append(2*theta_hat[1]*SP.eye(self.n_train))
cov = lowrank.LowRankCF(self.n_dimensions)
cov.X = self.Xtrain
cov.Xcross = self.Xtest
K = cov.K(theta)
Kcross = cov.Kcross(theta)
assert SP.allclose(K,_K), 'ouch, covariance matrix is wrong'
assert SP.allclose(Kcross,_Kcross), 'ouch, cross covariance matrix is wrong'
assert SP.allclose(_Kgrad_theta[0],cov.Kgrad_theta(theta,0))
assert SP.allclose(_Kgrad_theta[1],cov.Kgrad_theta(theta,1))
# gradient with respect to latent factors
for i in range(self.n_dimensions):
for j in range(self.n_train):
Xgrad = SP.zeros(self.Xtrain.shape)
Xgrad[j,i] = 1
_Kgrad_x = theta_hat[0]*(SP.dot(Xgrad,self.Xtrain.T) + SP.dot(self.Xtrain,Xgrad.T))
Kgrad_x = cov.Kgrad_x(theta,i,j)
assert SP.allclose(Kgrad_x,_Kgrad_x), 'ouch, gradient with respect to x is wrong for entry [%d,%d]'%(i,j)
开发者ID:PMBio,项目名称:pygp_kronsum,代码行数:30,代码来源:test_covar.py
示例12: test_linear
def test_linear(self):
theta = SP.array([SP.random.randn()**2])
theta_hat = SP.exp(2*theta)
_K = SP.dot(self.Xtrain,self.Xtrain.T)
_Kcross = SP.dot(self.Xtrain,self.Xtest.T)
cov = linear.LinearCF(n_dimensions=self.n_dimensions)
cov.X = self.Xtrain
cov.Xcross = self.Xtest
K = cov.K(theta)
Kcross = cov.Kcross(theta)
Kgrad_x = cov.Kgrad_x(theta,0)
Kgrad_theta = cov.Kgrad_theta(theta,0)
assert SP.allclose(K, theta_hat*_K), 'ouch covariance matrix is wrong'
assert SP.allclose(Kgrad_theta, 2*theta_hat*_K), 'ouch, gradient with respect to theta is wrong'
assert SP.allclose(Kcross, theta_hat*_Kcross), 'ouch, cross covariance is wrong'
# gradient with respect to latent factors
# for each entry
for i in range(self.n_dimensions):
for j in range(self.n_train):
Xgrad = SP.zeros(self.Xtrain.shape)
Xgrad[j,i] = 1
_Kgrad_x = theta_hat*(SP.dot(Xgrad,self.Xtrain.T) + SP.dot(self.Xtrain,Xgrad.T))
Kgrad_x = cov.Kgrad_x(theta,i,j)
assert SP.allclose(Kgrad_x,_Kgrad_x), 'ouch, gradient with respect to x is wrong for entry [%d,%d]'%(i,j)
开发者ID:PMBio,项目名称:pygp_kronsum,代码行数:29,代码来源:test_covar.py
示例13: test_build_replacement_ratios
def test_build_replacement_ratios(self):
#usage_values_per_struct = ['RES1',
# 'RES3', 'COM8', 'GOV1', 'GOV1', 'GOV1']
usage_values_per_struct = [111, 231, 231]
rcp_actual = {'structural':[0.2344, 0.1918, 0.1918],
'nonstructural drift sensitive':[0.5,0.3288, 0.3288],
'nonstructural acceleration sensitive':[0.2656,
0.4795,
0.4795
]}
buildings_usage_classification = 'FCB'
rcp = build_replacement_ratios(usage_values_per_struct,
buildings_usage_classification)
components = ['structural', 'nonstructural drift sensitive',
'nonstructural acceleration sensitive']
for comp in components:
self.assert_ (allclose(rcp[comp], rcp_actual[comp], 0.001))
usage_values_per_struct = ['RES1', 'COM4', 'COM4']
rcp_actual = {'structural':[0.2344, 0.1918, 0.1918],
'nonstructural drift sensitive':[0.5,0.3288, 0.3288],
'nonstructural acceleration sensitive':[0.2656,
0.4795,
0.4795
]}
buildings_usage_classification = 'HAZUS'
rcp = build_replacement_ratios(usage_values_per_struct,
buildings_usage_classification)
components = ['structural', 'nonstructural drift sensitive',
'nonstructural acceleration sensitive']
for comp in components:
self.assert_ (allclose(rcp[comp], rcp_actual[comp], 0.001))
开发者ID:dynaryu,项目名称:eqrm,代码行数:34,代码来源:test_structures.py
示例14: test_gaussian_mixture_generator_replicatability
def test_gaussian_mixture_generator_replicatability():
"Test the GaussianMixtureModel generator"
import tempfile
fname = tempfile.mktemp()
N = 1000
n = 500
D = 10
K = 3
gmm = GaussianMixtureModel.generate(fname, K, D)
gmm.set_seed(100)
gmm.save()
X = gmm.sample(N)
del gmm
gmm = GaussianMixtureModel.from_file(fname)
Y = gmm.sample(N)
assert(sc.allclose(X, Y))
del gmm
gmm = GaussianMixtureModel.from_file(fname)
Y = gmm.sample(N, n)
assert(sc.allclose(X[:n], Y))
开发者ID:sidaw,项目名称:polymom,代码行数:25,代码来源:GaussianMixtures.py
示例15: test_slice_interpolate_linear
def test_slice_interpolate_linear(self):
# Construct a 3D array that is a linear function.
v = self.vect
a = sp.arange(5)
a.shape = (5, 1, 1)
b = sp.arange(2)
b.shape = (1, 2, 1)
c = sp.arange(3)
c.shape = (1, 1, 3)
v[:, :, :] = a + b + c
v.set_axis_info('freq', 2, 1)
v.set_axis_info('a', 1, 1)
v.set_axis_info('b', 1, 1)
#### First test the weights.
# Test input sanitization.
self.assertRaises(ValueError, v.slice_interpolate_weights, [0, 1], 2.5)
# Test bounds.
self.assertRaises(ValueError, v.slice_interpolate_weights, [1, 2],
[2.5, 1.5])
# Test linear interpolations in 1D.
points, weights = v.slice_interpolate_weights(0, 2.5, 'linear')
self.assertTrue(sp.allclose(weights, 0.5))
self.assertTrue(2 in points)
self.assertTrue(3 in points)
# Test linear interpolations in multi D.
points, weights = v.slice_interpolate_weights([0, 1, 2],
[0.5, 0.5, 1.5],
'linear')
self.assertTrue(sp.allclose(weights, 1.0/8))
self.assertTrue(points.shape == (8, 3))
points, weights = v.slice_interpolate_weights([0, 1, 2],
[3, 1, 2],
'linear')
self.assertTrue(sp.allclose(weights % 1, 0))
#### Test linear interpolation on linear function.
# Test on the grid points.
self.assertEqual(v.slice_interpolate([0, 1, 2], [3.0, 1.0, 1.0]),
3.0 + 1.0 + 1.0)
# Test in 1D interpoation.
out = a + c + 0.347
out.shape = (5, 3)
self.assertTrue(sp.allclose(out, v.slice_interpolate(1, 0.347,
'linear')))
# Test in 2D.
out = b + 3.14159 + 1.4112
out.shape = (2,)
self.assertTrue(sp.allclose(out, v.slice_interpolate([0, 2],
[3.14159, 1.4112], 'linear')))
开发者ID:eric-switzer,项目名称:algebra_base,代码行数:60,代码来源:test_algebra.py
示例16: test_outside_polygon
def test_outside_polygon(self):
U = [[0,0], [1,0], [1,1], [0,1]] #Unit square
assert not is_outside_polygon( [0.5, 0.5], U )
#evaluate to False as the point 0.5, 0.5 is inside the unit square
assert is_outside_polygon( [1.5, 0.5], U )
#evaluate to True as the point 1.5, 0.5 is outside the unit square
indices = outside_polygon( [[0.5, 0.5], [1, -0.5], [0.3, 0.2]], U )
assert allclose( indices, [1] )
#One more test of vector formulation returning indices
polygon = [[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]]
points = [ [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]]
res = outside_polygon( points, polygon )
assert allclose( res, [3, 4] )
polygon = [[0,0], [1,0], [0.5,-1], [2, -1], [2,1], [0,1]]
points = [ [0.5, 1.4], [0.5, 0.5], [1, -0.5], [1.5, 0], [0.5, 1.5], [0.5, -0.5]]
res = outside_polygon( points, polygon )
assert allclose( res, [0, 4, 5] )
开发者ID:dynaryu,项目名称:eqrm,代码行数:26,代码来源:test_polygon.py
示例17: test1_read_excel_curve_data
def test1_read_excel_curve_data(self):
dirs = determine_this_file_path()
excel_file = 'synthetic_data_Flood_2012.xls'
excel_file = os.path.join(dirs, excel_file)
temp = create_vuln_xml.read_excel_curve_data(excel_file)
depths, fab, contents = temp
self.assertTrue(allclose(depths, array([0., 1.0])))
actually_fab = {u'FCM1_INSURED': array([0., 0.1]),
u'FCM2_INSURED': array([0., 0.12]),
u'FCM1_UNINSURED': array([0., 0.5]),
u'FCM2_UNINSURED': array([0., 0.52])}
act_cont = {
u'FCM1_INSURED_SAVE': array([0., 0.2]),
u'FCM1_INSURED_NOACTION': array([0., 0.3]),
u'FCM1_INSURED_EXPOSE': array([0., 0.4]),
u'FCM1_UNINSURED_SAVE': array([0., 0.6]),
u'FCM1_UNINSURED_NOACTION': array([0., 0.7]),
u'FCM1_UNINSURED_EXPOSE': array([0., 0.8]),
u'FCM2_INSURED_SAVE': array([0., 0.22]),
u'FCM2_INSURED_NOACTION': array([0., 0.32]),
u'FCM2_INSURED_EXPOSE': array([0., 0.42]),
u'FCM2_UNINSURED_SAVE': array([0., 0.62]),
u'FCM2_UNINSURED_NOACTION': array([0., 0.72]),
u'FCM2_UNINSURED_EXPOSE': array([0., 0.82])
}
for key in actually_fab:
self.assertTrue(allclose(actually_fab[key], fab[key]))
for key in act_cont:
self.assertTrue(allclose(act_cont[key], contents[key]))
开发者ID:wcarthur,项目名称:hazimp,代码行数:33,代码来源:test_create_vuln_xml.py
示例18: test_eps_r_noop_multi
def test_eps_r_noop_multi(self):
r0 = tc.eps_r_noop(tc.eps_r_noop(self.r2, self.A2, self.B2), self.A1, self.B1)
r0_ = tc.eps_r_noop_multi(self.r2, [self.A1, self.A2], [self.B1, self.B2])
self.assertTrue(sp.allclose(r0, r0_))
r0__ = tc.eps_r_noop_multi(self.r2, [self.AA12], [self.BB12])
self.assertTrue(sp.allclose(r0, r0__))
r0C = tc.eps_r_op_2s_C12(self.r2, self.C_A12, self.B1, self.B2)
r0C_ = tc.eps_r_noop_multi(self.r2, [self.C_A12], [self.B1, self.B2])
self.assertTrue(sp.allclose(r0C, r0C_))
r0C2 = tc.eps_r_op_2s_C12_AA34(self.r2, self.C_A12, self.BB12)
r0C2_ = tc.eps_r_noop_multi(self.r2, [self.C_A12], [self.BB12])
self.assertTrue(sp.allclose(r0C2, r0C2_))
r0CA2 = tc.eps_r_op_2s_C12(tc.eps_r_noop(self.r2, self.A2, self.B2),
self.C01, self.A0, self.B1)
r0CA2_ = tc.eps_r_noop_multi(self.r2, [self.C01, self.A2], [self.A0, self.BB12])
self.assertTrue(sp.allclose(r0CA2, r0CA2_))
开发者ID:amilsted,项目名称:evoMPS,代码行数:26,代码来源:tdvp_common_tests.py
示例19: testing
def testing(self):
attributes = {"mo": array(["money", "soup"]), "SITE_CLASS": array(["E", "C"])}
latitude = [10, 20]
longitude = [1, 2]
sites = Sites(latitude, longitude, **attributes)
site_class2Vs30 = {"C": 30, "E": 40}
sites.set_Vs30(site_class2Vs30)
actual = array(latitude)
self.assert_(allclose(sites.latitude, actual, 0.001))
actual = array(longitude)
self.assert_(allclose(sites.longitude, actual, 0.001))
actual = array(["money", "soup"])
for (att, act) in map(None, sites.attributes["mo"], actual):
self.assert_(att == act)
actual = array([40, 30])
self.assert_(allclose(sites.attributes["Vs30"], actual, 0.001))
site_class2Vs30 = {"C": 30}
try:
sites.set_Vs30(site_class2Vs30)
except KeyError:
pass
else:
self.failUnless(False, "KeyError not raised")
开发者ID:vipkolon,项目名称:eqrm,代码行数:25,代码来源:test_sites.py
示例20: test_apply_threshold_distance_partial
def test_apply_threshold_distance_partial(self):
"""
Test apply_threshold_distance function for atten_threshold_distance
scenario where apply_threshold_distance sets some SA figures to zero
"""
# Use the ones array for the initial SA figures
bedrock_SA = self.SA_ones.copy()
soil_SA = self.SA_ones.copy()
# Set a normal threshold distance
# event 0 event 1
# distances [[ 337.69538742 27105.63126916]]
atten_threshold_distance = 400
# Set up SA arrays that match the expected outcome, noting the distances
# in the comment above
site_inds = [0]
event_inds = [1]
bedrock_SA_expected = bedrock_SA.copy()
bedrock_SA_expected[...,site_inds,event_inds,:] = 0
soil_SA_expected = soil_SA.copy()
soil_SA_expected[...,site_inds,event_inds,:] = 0
# Run the threshold distance function
apply_threshold_distance(bedrock_SA,
soil_SA,
self.sites,
atten_threshold_distance,
self.use_amplification,
self.event_set)
assert allclose(bedrock_SA, bedrock_SA_expected)
assert allclose(soil_SA, soil_SA_expected)
开发者ID:dynaryu,项目名称:eqrm,代码行数:33,代码来源:test_filters.py
注:本文中的scipy.allclose函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论