本文整理汇总了Python中gnome.spill_container.SpillContainer.release_elements方法的典型用法代码示例。如果您正苦于以下问题:Python SpillContainer.release_elements方法的具体用法?Python SpillContainer.release_elements怎么用?Python SpillContainer.release_elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnome.spill_container.SpillContainer
的用法示例。
在下文中一共展示了SpillContainer.release_elements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_eq_allclose_spill_container
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_eq_allclose_spill_container():
"""
test if two spill containers are equal within 1e-5 tolerance
adjust the spill_container._array_allclose_atol = 1e-5
and vary start_positions by 1e-8
"""
(sp1, sp2) = get_eq_spills()
# just move one data array a bit
sp2.start_position = sp2.release.start_position + (1e-8, 1e-8, 0)
sc1 = SpillContainer()
sc2 = SpillContainer()
sc1.spills.add(sp1)
sc2.spills.add(sp2)
sc1.prepare_for_model_run(windage_at)
sc1.release_elements(360, sp1.release.release_time)
sc2.prepare_for_model_run(windage_at)
sc2.release_elements(360, sp2.release.release_time)
# need to change both atol
sc1._array_allclose_atol = 1e-5
sc2._array_allclose_atol = 1e-5
assert sc1 == sc2
assert sc2 == sc1
assert not (sc1 != sc2)
assert not (sc2 != sc1)
示例2: test_ne_spill_container
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_ne_spill_container():
""" test two spill containers are not equal """
(sp1, sp2) = get_eq_spills()
# just move one data array a bit
sp2.release.start_position = sp2.release.start_position + (1e-8, 1e-8, 0)
sc1 = SpillContainer()
sc2 = SpillContainer()
sc1.spills.add(sp1)
sc2.spills.add(sp2)
sc1.prepare_for_model_run(windage_at)
sc1.release_elements(360, sp1.release.release_time)
sc2.prepare_for_model_run(windage_at)
sc2.release_elements(360, sp2.release.release_time)
assert sc1 != sc2
assert sc2 != sc1
assert not (sc1 == sc2)
assert not (sc2 == sc1)
示例3: test_rewind
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_rewind():
"""
Test rewinding spill containter rewinds the spills.
- SpillContainer should reset its the data_arrays to empty and num_released
to 0
- it should reset num_released = 0 for all spills and reset
start_time_invalid flag to True. Basically all spills are rewound
"""
num_elements = 100
release_time = datetime(2012, 1, 1, 12)
release_time2 = release_time + timedelta(hours=24)
start_position = (23.0, -78.5, 0.0)
sc = SpillContainer()
spills = [point_line_release_spill(num_elements, start_position,
release_time),
point_line_release_spill(num_elements, start_position,
release_time2)]
sc.spills.add(spills)
sc.prepare_for_model_run(windage_at)
for time in [release_time, release_time2]:
sc.release_elements(3600, time)
assert sc.num_released == num_elements * len(spills)
for spill in spills:
assert spill.num_released == spill.release.num_elements
sc.rewind()
assert sc.num_released == 0
assert_dataarray_shape_size(sc)
for spill in spills:
assert spill.num_released == 0
assert spill.release.start_time_invalid is None
示例4: sample_sc_release
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def sample_sc_release(num_elements=10,
start_pos=(0.0, 0.0, 0.0),
release_time=datetime(2000, 1, 1, 1),
uncertain=False,
time_step=360,
spill=None,
element_type=None,
current_time=None,
arr_types=None,
windage_range=None,
units='g',
amount_per_element=1.0):
"""
Initialize a Spill of type 'spill', add it to a SpillContainer.
Invoke release_elements on SpillContainer, then return the spill container
object
If 'spill' is None, define a Spill object with a PointLineRelease type
of release
"""
if current_time is None:
current_time = release_time
if spill is None:
spill = gnome.spill.point_line_release_spill(num_elements,
start_pos,
release_time)
spill.units = units
spill.amount = amount_per_element * num_elements
if element_type is not None:
spill.element_type = element_type
if current_time is None:
current_time = spill.release_time
# fixme -- maybe this is not the place for the default arrays?
always = {'windages', 'windage_range', 'windage_persist'}
if arr_types is None:
# default always has standard windage parameters required by wind_mover
arr_types = always
else:
arr_types.update(always)
if windage_range is not None:
spill.windage_range = windage_range
sc = SpillContainer(uncertain)
sc.spills.add(spill)
# used for testing so just assume there is a Windage array
sc.prepare_for_model_run(arr_types)
sc.release_elements(time_step, current_time)
return sc
示例5: test_split_element
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_split_element():
'''
test split_element() method
'''
sc = SpillContainer()
o_sc = SpillContainer()
reltime = datetime(2015, 1, 1, 12, 0, 0)
num_les = 10
sc.spills += point_line_release_spill(num_les, (1, 1, 1),
reltime,
amount=100,
units='kg',
substance=test_oil)
o_sc.spills += copy.deepcopy(sc.spills[0])
sc.prepare_for_model_run({'fate_status'})
sc.release_elements(900, reltime)
o_sc.prepare_for_model_run({'fate_status'})
o_sc.release_elements(900, reltime)
# now do a split at element - fate data is not being initialized; however
# we want to make sure fate_data arrays are sync'd with sc data arrays so
# test for fate=non_weather
num = 2
l_frac = (.65, .35)
subs = sc.get_substances(complete=False)[0]
data = sc.substancefatedata(subs,
{'fate_status'},
fate='non_weather')
assert 'id' in data
ix = data['id'][0]
sc.split_element(ix, num, l_frac)
for name in sc._data_arrays:
split = sc[name]
d_split = data[name]
idx = np.where(sc['id'] == ix)[0][0]
orig = o_sc[name]
assert len(split) == num_les + num - 1
assert len(d_split) == num_les + num - 1
at = sc.array_types[name]
if isinstance(at, array_types.ArrayTypeDivideOnSplit):
assert np.allclose(split[idx:idx + num].sum(0), orig[idx])
assert np.allclose(split[idx], l_frac[0] * orig[idx])
else:
assert np.all(split[idx:idx + num] == orig[idx])
# fatedata copy of sc data is also updated
assert np.allclose(d_split, split)
示例6: test_windage_index
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_windage_index():
"""
A very simple test to make sure windage is set for the correct sc
if staggered release
"""
sc = SpillContainer()
rel_time = datetime(2013, 1, 1, 0, 0)
timestep = 30
for i in range(2):
spill = point_line_release_spill(num_elements=5,
start_position=(0., 0., 0.),
release_time=rel_time + i * timedelta(hours=1),
element_type=floating(windage_range=(i * .01 +
.01, i * .01 + .01),
windage_persist=900)
)
sc.spills.add(spill)
windage = {'windages': array_types.windages,
'windage_range': array_types.windage_range,
'windage_persist': array_types.windage_persist}
sc.prepare_for_model_run(array_types=windage)
sc.release_elements(timestep, rel_time)
wm = WindMover(environment.ConstantWind(5, 0))
wm.prepare_for_model_step(sc, timestep, rel_time)
wm.model_step_is_done() # need this to toggle _windage_is_set_flag
def _check_index(sc):
'''
internal function for doing the test after windage is set
- called twice so made a function
'''
# only 1st sc is released
for sp in sc.spills:
mask = sc.get_spill_mask(sp)
if np.any(mask):
assert np.all(sc['windages'][mask] ==
(sp.element_type.initializers["windages"].
windage_range[0]))
# only 1st spill is released
_check_index(sc) # 1st ASSERT
sc.release_elements(timestep, rel_time + timedelta(hours=1))
wm.prepare_for_model_step(sc, timestep, rel_time)
_check_index(sc) # 2nd ASSERT
示例7: test_multiple_spills
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_multiple_spills(uncertain):
"""
SpillContainer initializes correct number of elements in data_arrays.
Use Multiple spills with different release times.
Also, deleting a spill shouldn't change data_arrays for particles
already released.
"""
sc = SpillContainer(uncertain)
spills = [point_line_release_spill(num_elements, start_position, release_time),
point_line_release_spill(num_elements,
start_position,
release_time + timedelta(hours=1),
end_position,
end_release_time)
]
sc.spills.add(spills)
assert len(sc.spills) == 2
for spill in spills:
assert sc.spills[spill.id] == spill
assert sc.uncertain == uncertain
time_step = 3600
num_steps = ((spills[-1].release.end_release_time -
spills[-1].release.release_time).seconds / time_step + 1)
sc.prepare_for_model_run(windage_at)
for step in range(num_steps):
current_time = release_time + timedelta(seconds=time_step * step)
sc.release_elements(time_step, current_time)
total_elements = sum(s.num_elements for s in spills)
assert sc.num_released == total_elements
assert_dataarray_shape_size(sc)
sc.spills.remove(spills[0].id)
with raises(KeyError):
# it shouldn't be there anymore.
assert sc.spills[spills[0].id] is None
# however, the data arrays of released particles should be unchanged
assert sc.num_released == spill.release.num_elements * len(spills)
assert_dataarray_shape_size(sc)
示例8: test_eq_spill_container
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_eq_spill_container():
""" test if two spill containers are equal """
(sp1, sp2) = get_eq_spills()
sc1 = SpillContainer()
sc2 = SpillContainer()
sc1.spills.add(sp1)
sc2.spills.add(sp2)
sc1.prepare_for_model_run(windage_at)
sc1.release_elements(360, sp1.release_time)
sc2.prepare_for_model_run(windage_at)
sc2.release_elements(360, sp2.release_time)
assert sc1 == sc2
示例9: test_one_simple_spill
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_one_simple_spill(spill):
""" checks data_arrays correctly populated for a single spill in
SpillContainer """
sc = SpillContainer()
sc.spills.add(spill)
time_step = 3600
sc.prepare_for_model_run(windage_at)
num_steps = ((spill.end_release_time -
spill.release_time).seconds / time_step + 1)
for step in range(num_steps):
current_time = spill.release_time + timedelta(seconds=time_step * step)
sc.release_elements(time_step, current_time)
assert sc.num_released == spill.num_elements
assert_sc_single_spill(sc)
示例10: sample_sc_release
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def sample_sc_release(
num_elements=10,
start_pos=(0.0, 0.0, 0.0),
release_time=datetime(2000, 1, 1, 1),
uncertain=False,
time_step=360,
spill=None,
element_type=None,
current_time=None,
arr_types=None,
):
"""
Initialize a Spill of type 'spill', add it to a SpillContainer.
Invoke release_elements on SpillContainer, then return the spill container
object
If 'spill' is None, define a Spill object with a PointLineRelease type
of release
"""
if current_time is None:
current_time = release_time
if spill is None:
spill = gnome.spill.point_line_release_spill(num_elements, start_pos, release_time)
spill.mass = num_elements
if element_type is not None:
spill.element_type = element_type
if current_time is None:
current_time = spill.release_time
if arr_types is None:
# default always has standard windage parameters required by wind_mover
arr_types = {"windages": windages, "windage_range": windage_range, "windage_persist": windage_persist}
sc = SpillContainer(uncertain)
sc.spills.add(spill)
# used for testing so just assume there is a Windage array
sc.prepare_for_model_run(arr_types)
sc.release_elements(time_step, current_time)
return sc
示例11: test_model_step_is_done
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_model_step_is_done():
"""
tests that correct elements are released when their status_codes is toggled
to basic_types.oil_status.to_be_removed
"""
release_time = datetime(2012, 1, 1, 12)
start_time2 = datetime(2012, 1, 2, 12)
start_position = (23.0, -78.5, 0.0)
num_elements = 10
sc = SpillContainer()
spill = PointLineSource(num_elements, start_position,
release_time)
sp2 = PointLineSource(num_elements, start_position,
start_time2)
sc.spills += [spill, sp2]
sc.prepare_for_model_run(windage_at)
sc.release_elements(100, release_time)
sc.release_elements(100, start_time2)
(sc['status_codes'])[5:8] = oil_status.to_be_removed
(sc['status_codes'])[14:17] = oil_status.to_be_removed
sc['status_codes'][19] = oil_status.to_be_removed
# also make corresponding positions 0 as a way to test
sc['positions'][5:8, :] = (0, 0, 0)
sc['positions'][14:17, :] = (0, 0, 0)
sc['positions'][19, :] = (0, 0, 0)
sc.model_step_is_done()
assert sc.num_released == 2 * num_elements - 7
assert np.all(sc['status_codes'] != oil_status.to_be_removed)
assert np.all(sc['positions'] == start_position)
assert np.count_nonzero(sc['spill_num'] == 0) == num_elements - 3
assert np.count_nonzero(sc['spill_num'] == 1) == num_elements - 4
示例12: test_spills_different_substance_release
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_spills_different_substance_release(self):
'''
Test data structure gets correctly set/updated after release_elements
is invoked
'''
sc = SpillContainer()
rel_time = datetime(2014, 1, 1, 12, 0, 0)
end_time = rel_time + timedelta(hours=1)
time_step = 900
splls0 = [point_line_release_spill(100, (1, 1, 1),
rel_time,
end_release_time=end_time,
element_type=floating(substance=test_oil),
amount=100,
units='kg'),
point_line_release_spill(50, (2, 2, 2),
rel_time + timedelta(seconds=900),
element_type=floating(substance=test_oil),
amount=150,
units='kg'),
]
sc.spills += splls0
splls1 = point_line_release_spill(10, (0, 0, 0),
rel_time,
element_type=floating(substance=None))
sc.spills += splls1
at = {'density', 'mass_components'}
sc.prepare_for_model_run(at)
assert len(sc.get_substances()) == 2
print '\nElements released:'
for ix in range(-1, 8):
time = rel_time + timedelta(seconds=time_step) * ix
num_rel = sc.release_elements(time_step, time)
print num_rel
for substance, data in sc.itersubstancedata(at):
assert substance.name == test_oil
idx = sc._substances_spills.substances.index(substance)
mask = sc['substance'] == idx
for array in at:
assert array in data
assert np.all(data[array] == sc[array][mask])
示例13: test_get_spill_mask
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_get_spill_mask():
"""
Simple tests for get_spill_mask
"""
start_time0 = datetime(2012, 1, 1, 12)
start_time1 = datetime(2012, 1, 2, 12)
start_time2 = start_time1 + timedelta(hours=1)
start_position = (23.0, -78.5, 0.0)
num_elements = 5
sc = SpillContainer()
sp0 = PointLineSource(num_elements, start_position,
start_time0)
sp1 = PointLineSource(num_elements, start_position,
start_time1,
end_position=(start_position[0]
+ 0.2, start_position[1] + 0.2,
0.0), end_release_time=start_time1
+ timedelta(hours=3))
sp2 = PointLineSource(num_elements, start_position,
start_time2)
sc.spills += [sp0, sp1, sp2]
# as we move forward in time, the spills will release LEs in an
# expected way
sc.prepare_for_model_run(windage_at)
sc.release_elements(100, start_time0)
sc.release_elements(100, start_time0 + timedelta(hours=24))
sc.release_elements(100, start_time1 + timedelta(hours=1))
sc.release_elements(100, start_time1 + timedelta(hours=3))
assert all(sc['spill_num'][sc.get_spill_mask(sp2)] == 2)
assert all(sc['spill_num'][sc.get_spill_mask(sp0)] == 0)
assert all(sc['spill_num'][sc.get_spill_mask(sp1)] == 1)
示例14: test_update_intrinsic_props
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_update_intrinsic_props(self):
'''
test multiple spills with same substance
'''
weatherers = [WeatheringData(water), FayGravityViscous(water)]
rel_time = datetime.now().replace(microsecond=0)
end_time = rel_time + timedelta(hours=1)
spills = [point_line_release_spill(10,
(0, 0, 0),
rel_time,
end_release_time=end_time,
amount=100,
units='kg',
substance=test_oil),
point_line_release_spill(5,
(0, 0, 0),
rel_time + timedelta(hours=.25),
substance=test_oil,
amount=100,
units='kg')
]
sc = SpillContainer()
sc.spills += spills
at = set()
for w in weatherers:
at.update(w.array_types)
sc.prepare_for_model_run(at)
# test initialization as well
for w in weatherers:
w.prepare_for_model_run(sc)
for val in sc.mass_balance.values():
assert val == 0.0
# test initialization as well
ts = 900
for i in range(-1, 5):
curr_time = rel_time + timedelta(seconds=i * ts)
num_released = sc.release_elements(ts, curr_time)
if num_released > 0:
for w in weatherers:
w.initialize_data(sc, num_released)
for w in weatherers:
self.step(w, sc, curr_time)
for key, val in sc.mass_balance.iteritems():
if len(sc) > 0 and key not in ('beached',
'non_weathering',
'off_maps'):
assert val > 0
else:
# everything, including avg_density is 0 if nothing is
# released
assert val == 0.0
if len(sc) > 0:
# area arrays initialized correctly
mask = sc['age'] == 0
if np.any(~mask):
# sc['fay_area'][mask] is initial area of blob
# sc['fay_area'][~mask] is area of aged blob
assert (sc['fay_area'][mask].sum() !=
sc['fay_area'][~mask].sum())
assert all(sc['fay_area'] > 0)
assert all(sc['init_mass'] > 0)
# wd props arrays initialized correctly
assert all(sc['density'] > 0)
assert all(sc['viscosity'] > 0)
sc['age'] += ts # model would do this operation
print 'Completed step: ', i
示例15: test_uncertain_copy
# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import release_elements [as 别名]
def test_uncertain_copy():
"""
test whether creating an uncertain copy of a spill_container works
"""
release_time = datetime(2012, 1, 1, 12)
start_time2 = datetime(2012, 1, 2, 12)
start_position = (23.0, -78.5, 0.0)
start_position2 = (45.0, 75.0, 0.0)
num_elements = 100
sc = SpillContainer()
spill = point_line_release_spill(num_elements, start_position,
release_time)
sp2 = point_line_release_spill(num_elements, start_position2,
start_time2)
sc.spills.add(spill)
sc.spills.add(sp2)
u_sc = sc.uncertain_copy()
assert u_sc.uncertain
assert len(sc.spills) == len(u_sc.spills)
# make sure they aren't references to the same spills
assert sc.spills[spill.id] not in u_sc.spills
assert sc.spills[sp2.id] not in u_sc.spills
# make sure they have unique ids:
for id1 in [s.id for s in sc.spills]:
for id2 in [s.id for s in u_sc.spills]:
print id1, id2
assert not id1 == id2
# do the spills work?
sc.prepare_for_model_run(windage_at)
sc.release_elements(100, release_time)
assert sc['positions'].shape == (num_elements, 3)
assert sc['last_water_positions'].shape == (num_elements, 3)
# now release second set:
u_sc.prepare_for_model_run(windage_at)
assert u_sc['positions'].shape[0] == 0 # nothing released yet.
u_sc.release_elements(100, release_time)
# elements should be there.
assert u_sc['positions'].shape == (num_elements, 3)
assert u_sc['last_water_positions'].shape == (num_elements, 3)
# next release:
sc.release_elements(100, release_time + timedelta(hours=24))
assert sc['positions'].shape == (num_elements * 2, 3)
assert sc['last_water_positions'].shape == (num_elements * 2, 3)
# second set should not have changed
assert u_sc['positions'].shape == (num_elements, 3)
assert u_sc['last_water_positions'].shape == (num_elements, 3)
# release second set
u_sc.release_elements(100, release_time + timedelta(hours=24))
assert u_sc['positions'].shape == (num_elements * 2, 3)
assert u_sc['last_water_positions'].shape == (num_elements * 2, 3)