本文整理汇总了Python中tests.utils.helpers.create_job函数的典型用法代码示例。如果您正苦于以下问题:Python create_job函数的具体用法?Python create_job怎么用?Python create_job使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_job函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_risk_mandatory_parameters
def test_risk_mandatory_parameters(self):
sections = [config.RISK_SECTION,
config.HAZARD_SECTION, config.GENERAL_SECTION]
params = {}
engine = helpers.create_job(params, sections=sections)
self.assertFalse(engine.is_valid()[0])
params = {config.EXPOSURE: "/a/path/to/exposure"}
engine = helpers.create_job(params, sections=sections)
self.assertFalse(engine.is_valid()[0])
params = {config.EXPOSURE: "/a/path/to/exposure",
config.REGION_GRID_SPACING: 0.5}
engine = helpers.create_job(params, sections=sections)
self.assertFalse(engine.is_valid()[0])
params = {config.EXPOSURE: "/a/path/to/exposure",
config.INPUT_REGION: "a, polygon",
config.REGION_GRID_SPACING: 0.5}
engine = helpers.create_job(params, sections=sections)
self.assertTrue(engine.is_valid()[0])
示例2: test_with_risk_processing_the_exposure_must_be_specified
def test_with_risk_processing_the_exposure_must_be_specified(self):
sections = [config.RISK_SECTION, "HAZARD", "general"]
params = {}
engine = helpers.create_job(params, sections=sections)
self.assertFalse(engine.is_valid()[0])
params = {config.EXPOSURE: "/a/path/to/exposure"}
engine = helpers.create_job(params, sections=sections)
self.assertTrue(engine.is_valid()[0])
示例3: setUpClass
def setUpClass(cls):
cls.job = engine.prepare_job()
jp, _, _ = engine.import_job_profile(RISK_DEMO_CONFIG_FILE, cls.job)
calc_proxy = helpers.create_job({}, job_id=cls.job.id,
oq_job_profile=jp, oq_job=cls.job)
# storing the basic exposure model
ClassicalRiskCalculator(calc_proxy).store_exposure_assets()
[em_input] = models.inputs4job(cls.job.id, input_type="exposure")
[model] = em_input.exposuremodel_set.all()
site = shapes.Site(1.0, 2.0)
# more assets at same location
models.ExposureData(
exposure_model=model, taxonomy="NOT_USED",
asset_ref="ASSET_1", stco=1,
site=geos.GEOSGeometry(site.point.to_wkt()), reco=1).save()
models.ExposureData(
exposure_model=model, taxonomy="NOT_USED",
asset_ref="ASSET_2", stco=1,
site=geos.GEOSGeometry(site.point.to_wkt()), reco=1).save()
site = shapes.Site(2.0, 2.0)
# just one asset at location
models.ExposureData(
exposure_model=model, taxonomy="NOT_USED",
asset_ref="ASSET_3", stco=1,
site=geos.GEOSGeometry(site.point.to_wkt()), reco=1).save()
示例4: setUp
def setUp(self):
self.params = dict(
CALCULATION_MODE='Hazard',
REFERENCE_VS30_VALUE=500,
SOURCE_MODEL_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_SRC_MODEL_LT,
GMPE_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_GMPE_LT,
BASE_PATH=SIMPLE_FAULT_BASE_PATH)
self.imls = [5.0000e-03, 7.0000e-03,
1.3700e-02, 1.9200e-02, 2.6900e-02, 3.7600e-02, 5.2700e-02,
7.3800e-02, 9.8000e-02, 1.0300e-01, 1.4500e-01, 2.0300e-01,
2.8400e-01, 3.9700e-01, 5.5600e-01, 7.7800e-01, 1.0900e+00,
1.5200e+00, 2.1300e+00]
self.job_ctxt = helpers.create_job(self.params)
self.calculator = classical.ClassicalHazardCalculator(self.job_ctxt)
self.job_id = self.job_ctxt.job_id
self.empty_mean_curve = []
# deleting server side cached data
kvs.get_client().flushall()
mean_curve = [9.8728e-01, 9.8266e-01, 9.4957e-01,
9.0326e-01, 8.1956e-01, 6.9192e-01, 5.2866e-01, 3.6143e-01,
2.4231e-01, 2.2452e-01, 1.2831e-01, 7.0352e-02, 3.6060e-02,
1.6579e-02, 6.4213e-03, 2.0244e-03, 4.8605e-04, 8.1752e-05,
7.3425e-06]
self.site = shapes.Site(2.0, 5.0)
self._store_curve_at(self.site, mean_curve)
示例5: test_prepares_blocks_using_the_exposure
def test_prepares_blocks_using_the_exposure(self):
"""The base risk calculator is able to read the exposure file,
split the sites into blocks and store them in KVS.
"""
params = {
config.EXPOSURE: os.path.join(helpers.SCHEMA_EXAMPLES_DIR,
EXPOSURE_TEST_FILE),
"BASE_PATH": "."
}
a_job = helpers.create_job(params)
calculator = general.BaseRiskCalculator(a_job)
calculator.partition()
sites = [shapes.Site(9.15000, 45.16667),
shapes.Site(9.15333, 45.12200),
shapes.Site(9.14777, 45.17999)]
expected = general.Block(a_job.job_id, 0, sites)
self.assertEqual(1, len(a_job.blocks_keys))
self.assertEqual(
expected, general.Block.from_kvs(a_job.job_id,
a_job.blocks_keys[0]))
示例6: test_with_risk_jobs_we_can_trigger_hazard_only_on_exposure_sites
def test_with_risk_jobs_we_can_trigger_hazard_only_on_exposure_sites(self):
"""When we have hazard and risk jobs, we can ask to trigger
the hazard computation only on the sites specified
in the exposure file."""
sections = [config.HAZARD_SECTION, config.GENERAL_SECTION, config.RISK_SECTION]
input_region = "46.0, 9.0, 46.0, 10.0, 45.0, 10.0, 45.0, 9.0"
exposure = "exposure-portfolio.xml"
exposure_path = os.path.join(helpers.SCHEMA_EXAMPLES_DIR, exposure)
params = {
config.INPUT_REGION: input_region,
config.REGION_GRID_SPACING: 0.1,
config.EXPOSURE: exposure_path,
config.COMPUTE_HAZARD_AT_ASSETS: True,
}
engine = helpers.create_job(params, sections=sections, base_path=".")
expected_sites = [
shapes.Site(9.15000, 45.16667),
shapes.Site(9.15333, 45.12200),
shapes.Site(9.14777, 45.17999),
]
self.assertEquals(expected_sites, engine.sites_to_compute())
示例7: setUpClass
def setUpClass(cls):
cls.job = engine.prepare_job()
jp, _, _ = engine.import_job_profile(RISK_DEMO_CONFIG_FILE, cls.job)
cls.job_ctxt = helpers.create_job({}, job_id=cls.job.id,
oq_job_profile=jp, oq_job=cls.job)
calc = ClassicalRiskCalculator(cls.job_ctxt)
calc.store_exposure_assets()
[input] = models.inputs4job(cls.job.id, input_type="exposure")
model = input.model()
assets = model.exposuredata_set.filter(taxonomy="af/ctc-D/LR")
# Add some more assets.
coos = [(10.000155392289116, 46.546194318563),
(10.222034128255, 46.0071299176413),
(10.520376165581, 46.247463385278)]
for lat, lon in coos:
site = shapes.Site(lat, lon)
cls.sites.append(site)
if assets:
continue
location = geos.GEOSGeometry(site.point.to_wkt())
asset = models.ExposureData(
exposure_model=model, taxonomy="af/ctc-D/LR",
asset_ref=helpers.random_string(6), stco=lat * 2,
site=location, reco=1.1 * lon)
asset.save()
示例8: test_read_gmfs
def test_read_gmfs(self):
"""Verify _get_db_gmfs."""
params = {
'REGION_VERTEX': '40,-117, 42,-117, 42,-116, 40,-116',
'REGION_GRID_SPACING': '1.0'}
the_job = helpers.create_job(params, job_id=self.job.id)
calculator = EventBasedRiskCalculator(the_job)
self.assertEqual(3, len(calculator._gmf_db_list(self.job.id)))
# only the keys in gmfs are used
gmfs = calculator._get_db_gmfs([], self.job.id)
self.assertEqual({}, gmfs)
# only the keys in gmfs are used
sites = [Site(lon, lat)
for lon in xrange(-117, -115)
for lat in xrange(40, 43)]
gmfs = calculator._get_db_gmfs(sites, self.job.id)
# avoid rounding errors
for k, v in gmfs.items():
gmfs[k] = [round(i, 1) for i in v]
self.assertEqual({
'0!0': [0.1, 0.5, 0.0],
'0!1': [0.2, 0.6, 0.0],
'1!0': [0.4, 0.8, 1.3],
'1!1': [0.3, 0.7, 1.2],
'2!0': [0.0, 0.0, 1.0],
'2!1': [0.0, 0.0, 1.1],
}, gmfs)
示例9: test_prepares_blocks_using_the_exposure_and_filtering
def test_prepares_blocks_using_the_exposure_and_filtering(self):
"""When reading the exposure file, the mixin also provides filtering
on the region specified in the REGION_VERTEX and REGION_GRID_SPACING
paramaters."""
region_vertex = \
"46.0, 9.14, 46.0, 9.15, 45.0, 9.15, 45.0, 9.14"
params = {config.EXPOSURE: os.path.join(
helpers.SCHEMA_EXAMPLES_DIR, EXPOSURE_TEST_FILE),
config.INPUT_REGION: region_vertex,
config.REGION_GRID_SPACING: 0.1,
# the calculation mode is filled to let the mixin runs
config.CALCULATION_MODE: "Event Based"}
a_job = helpers.create_job(params)
expected_block = general.Block(
(shapes.Site(9.15, 45.16667), shapes.Site(9.14777, 45.17999)))
with Mixin(a_job, general.RiskJobMixin):
a_job.partition()
self.assertEqual(1, len(a_job.blocks_keys))
self.assertEqual(
expected_block, general.Block.from_kvs(a_job.blocks_keys[0]))
示例10: setUp
def setUp(self):
params = dict(
CALCULATION_MODE='Hazard',
SOURCE_MODEL_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_SRC_MODEL_LT,
GMPE_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_GMPE_LT,
BASE_PATH=SIMPLE_FAULT_BASE_PATH)
self.job_ctxt = create_job(params)
self.calculator = classical.ClassicalHazardCalculator(self.job_ctxt)
示例11: setUp
def setUp(self):
params = dict(
CALCULATION_MODE='Hazard',
COMPUTE_MEAN_HAZARD_CURVE='true',
SOURCE_MODEL_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_SRC_MODEL_LT,
GMPE_LOGIC_TREE_FILE_PATH=SIMPLE_FAULT_GMPE_LT,
BASE_PATH=SIMPLE_FAULT_BASE_PATH)
self.calc_proxy = create_job(params)
self.calculator = classical.ClassicalHazardCalculator(self.calc_proxy)
示例12: test_site_keys
def test_site_keys(self):
"""Verify _sites_to_gmf_keys"""
params = {
'REGION_VERTEX': '40,-117, 42,-117, 42,-116, 40,-116',
'REGION_GRID_SPACING': '1.0'}
with Mixin(helpers.create_job(params, job_id=self.job.id),
ProbabilisticEventMixin) as mixin:
keys = mixin._sites_to_gmf_keys([Site(-117, 40), Site(-116, 42)])
self.assertEquals(["0!0", "2!1"], keys)
示例13: test_site_keys
def test_site_keys(self):
"""Verify _sites_to_gmf_keys"""
params = {
'REGION_VERTEX': '40,-117, 42,-117, 42,-116, 40,-116',
'REGION_GRID_SPACING': '1.0'}
the_job = helpers.create_job(params, job_id=self.job.id)
calculator = EventBasedRiskCalculator(the_job)
keys = calculator._sites_to_gmf_keys([Site(-117, 40), Site(-116, 42)])
self.assertEqual(["0!0", "2!1"], keys)
示例14: test_computes_sites_in_region_with_risk_jobs
def test_computes_sites_in_region_with_risk_jobs(self):
"""When we have hazard and risk jobs, we always use the region."""
sections = [config.HAZARD_SECTION, config.GENERAL_SECTION, config.RISK_SECTION]
input_region = "2.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 1.0"
params = {config.INPUT_REGION: input_region, config.REGION_GRID_SPACING: 1.0}
engine = helpers.create_job(params, sections=sections)
expected_sites = [shapes.Site(1.0, 1.0), shapes.Site(2.0, 1.0), shapes.Site(1.0, 2.0), shapes.Site(2.0, 2.0)]
self.assertEquals(expected_sites, engine.sites_to_compute())
示例15: test_hazard_computation_type
def test_hazard_computation_type(self):
"""Region (REGION_VERTEX) and specific sites (SITES)
are not supported at the same time."""
params = {config.SITES: "some, sites"}
validator = config.ComputationTypeValidator(params)
engine = helpers.create_job(params, validator=validator)
self.assertTrue(engine.is_valid()[0])
params = {config.INPUT_REGION: "a, polygon"}
validator = config.ComputationTypeValidator(params)
engine = helpers.create_job(params, validator=validator)
self.assertTrue(engine.is_valid()[0])
params = {config.SITES: "some, sites",
config.INPUT_REGION: "a, polygon"}
validator = config.ComputationTypeValidator(params)
engine = helpers.create_job(params, validator=validator)
self.assertFalse(engine.is_valid()[0])