Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Update nrml fragility parser #761

Merged
merged 7 commits into from May 22, 2012

Conversation

Projects
None yet
2 participants
Contributor

gvallarelli commented May 22, 2012

Updated older tests(refactoring, get rid of try catch finally whatever...), added new ones:

  • noDamageLimit can be defined just for the discrete fragility models.
  • noDamageLimit must be minor than values defined for the IML.

Before reviewing/merging this branch it's necessary that this branch lands first:
https://github.com/gem/nrml/pull/29
After that git submodule update should made these stuff working.

gvallarelli added some commits May 21, 2012

Refactored test code in parser_fragility_model_unittest, removed try/…
…catch

and used the context manager in all tests.
Fragility parser now can read noDamageLimit attribute. Updated older …
…tests,

added new ones:
* noDamageLimit can be defined just for the discrete fragility models.
* noDamageLimit must be minor than values defined for the IMT.
Contributor

larsbutler commented May 22, 2012

We will need to add this attribute to the DB model as well (to riski.fragility_model). Is there a bug for this?

Contributor

gvallarelli commented May 22, 2012

@larsbutler yep I'm going to add new bugs for that.

Contributor

larsbutler commented May 22, 2012

I'm getting test failures.

FAIL: test_parser (tests.parser_fragility_model_unittest.DiscreteFragilityModelParserTestCase)

Traceback (most recent call last):
File "/Users/larsbutler/proj/oq-engine/tests/parser_fragility_model_unittest.py", line 236, in test_parser
self.assertEqual(expected, self.parser.model)
AssertionError: FRAGM(id='ep1', format='discrete', limits=['minor', 'moderate', 'severe', 'collapse'], description='Fragility model for Pavia (discrete)', imls=[7.0, 8.0, 9.0, 10.0, 11.0], imt='MMI', iml_unit='g', max_iml=None, min_iml=None, no_damage_limit=0.2) != FRAGM(id='ep1', format='discrete', limits=['minor', 'moderate', 'severe', 'collapse'], description='Fragility model for Pavia (discrete)', imls=[7.0, 8.0, 9.0, 10.0, 11.0], imt='MMI', iml_unit='g', max_iml=None, min_iml=None, no_damage_limit=None)
-------------------- >> begin captured logging << --------------------
root: DEBUG: Found data at /Users/larsbutler/proj/oq-engine/openquake/nrml/schema/examples/temp.xml
--------------------- >> end captured logging << ---------------------

You need to update the nrml submodule to point to the new commit (which includes your recent changes).

Contributor

gvallarelli commented May 22, 2012

Ok, I've updated the nrml submodule.

Contributor

larsbutler commented May 22, 2012

Better now. There's another issue though:

$ ./run_tests -vx
Failure: AttributeError ('module' object has no attribute 'nrml_schema_file') ... ERROR

ERROR: Failure: AttributeError ('module' object has no attribute 'nrml_schema_file')

Traceback (most recent call last):
File "/Users/larsbutler/.virtualenvs/openquake/lib/python2.7/site-packages/nose/loader.py", line 390, in loadTestsFromName
addr.filename, addr.module)
File "/Users/larsbutler/.virtualenvs/openquake/lib/python2.7/site-packages/nose/importer.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/larsbutler/.virtualenvs/openquake/lib/python2.7/site-packages/nose/importer.py", line 86, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/larsbutler/proj/oq-engine/tests/init.py", line 19, in
from cache_gc_unittest import *
File "/Users/larsbutler/proj/oq-engine/tests/cache_gc_unittest.py", line 24, in
from tests.utils.helpers import patch
File "/Users/larsbutler/proj/oq-engine/tests/utils/helpers.py", line 42, in
from openquake.calculators.hazard.general import store_gmpe_map
File "/Users/larsbutler/proj/oq-engine/openquake/calculators/hazard/init.py", line 19, in
from openquake.calculators.hazard.classical.core import (
File "/Users/larsbutler/proj/oq-engine/openquake/calculators/hazard/classical/core.py", line 33, in
from openquake import xml
File "/Users/larsbutler/proj/oq-engine/openquake/xml.py", line 128, in
schema_path=nrml.nrml_schema_file()):
AttributeError: 'module' object has no attribute 'nrml_schema_file'


Ran 1 test in 0.001s

FAILED (errors=1)

Contributor

gvallarelli commented May 22, 2012

Ok, I'll change that.

@larsbutler larsbutler commented on an outdated diff May 22, 2012

openquake/parser/fragility.py
@@ -107,10 +108,18 @@ def _parse_model(self, element):
assert imls is not None, "IML not set"
mdl["imls"] = [float(iml) for iml in imls.text.split()]
mdl["imt"] = imls.get('IMT')
+ if mdl["no_damage_limit"]:
+ mdl["no_damage_limit"] = float(mdl["no_damage_limit"])
+ assert mdl["no_damage_limit"] < mdl["imls"][0], (
+ "'noDamageLimit' must be minor than values defined for IML")
@larsbutler

larsbutler May 22, 2012

Contributor

s/minor/less/

@larsbutler larsbutler commented on the diff May 22, 2012

tests/parser_fragility_model_unittest.py
@@ -160,16 +220,20 @@ def test_parser(self):
poes=[0.0, 0.0, 0.0, 0.3, 0.89]),
fragility.FFD(taxonomy='RC/DMRF-D/HR', type=None, limit='collapse',
poes=[0.0, 0.0, 0.0, 0.04, 0.64])]
- parser = fragility.FragilityModelParser(DISCRETE_MODEL)
- results = list(parser)
+ shutil.copyfile(DISCRETE_MODEL, TEMP_FILE)
@larsbutler

larsbutler May 22, 2012

Contributor

Why is it necessary to copy the file?

Contributor

gvallarelli commented May 22, 2012

Because we don't want to remove the DISCRETE_MODEL example file (i.e. fragm_d.xml).

Contributor

larsbutler commented May 22, 2012

Ah, I see. We do that because we're creating temporary files for the parser to chew on. It's a shame that the parser wasn't written to accept a file path or a file-like object (because then we could just use StringIO objects in these cases and wouldn't have to mess with cleaning up files).

So that's fine then. LGTM

Contributor

gvallarelli commented May 22, 2012

I made a big refactoring getting rid of the try-except-finally blocks. I agree with the use of StringIO objects so we don't have to use external resources (files).

gvallarelli added a commit that referenced this pull request May 22, 2012

@gvallarelli gvallarelli merged commit 72f139b into gem:master May 22, 2012

micheles added a commit that referenced this pull request May 26, 2016

Merge pull request #761 from gem/epsilon-order
Added a test on the ordering of the epsilons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment