OasisLMF / OpenDataTransform

An open-source Python-based catastrophe data transformation - converts exposure data between OED and other data formats.
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

Peril code grouping #20

Open stufraser1 opened 3 years ago

stufraser1 commented 3 years ago

Explore whether adjustment to mapping file can address problems found in testing, with handling grouped peril codes in one model format (AIR) and separate peril codes in another (OED). Documentation should highlight this as a known issue for this translation.

stufraser1 commented 3 years ago

@tristanlloyd @benhayes21 Please could you add an example of the codes and the transformation direction requiring code splitting / direction requiring combination for this issue, to assist understanding the logic required to implement it in the mapping file. Thanks

stufraser1 commented 3 years ago

Previous feedback from Tristan: (This example is closely related to, but not exactly the same as, splitting a grouped peril code to a string of peril codes, so I may be conflating two issues)

Trying to implement something like; transformation: 1 when: search(LayerPeril,‘PWH’) to split an AIR peril string like ‘PWH+PSH+PPH’ etc., to create separate peril columns with 1 or blanks (as required in our Sequel Impact Import). The string manipulation functions implemented in the converter ONLY work for the transformation: part, and can’t be used in the when: clauses. Can only put the search() function in the transformation: part, to return TRUE / FALSE. Then needed to post-process the resulting file to convert to 1 / ’’, [Couldn’t nest the search() within a replace(), i.e., replace(search(LayerPeril,‘PWH’),’TRUE’, 1,’FALSE’,’’) ].

stufraser1 commented 3 years ago

The best reference is https://docs.air-worldwide.com/Database/CEDE/9.0/topic137.html Grouped peril code: PWS equates to PWH+PSH Windstorm PEQ equates to PES+PFF+PTS+PLS+PSL All Earthquake perils PFH equates to TS PFL+PSH Inland and Coastal Flood

Is the best way to deal with this, to include the original and destination in the peril code listing, i.e. transform the grouped code to string in the same way as we transform a single code to a single code (is any other logic actually needed?

OmegaDroid commented 3 years ago

Spliting these into multiple transformations is the way to go here, something like

transformation: 1 
when: search(LayerPeril,‘PWH’) 

is correct, is this not working?

The reason this wouldn't work

replace(search(LayerPeril,‘PWH’),’TRUE’, 1,’FALSE’,’’)

is that the first argument to replace must be a string and search returns a boolean.

stufraser1 commented 3 years ago

Running this on a basic test does not appear to work as expected. Requires tests to confirm correct structuring of transformation using multiple where clauses, and documentation of how to perform these types of conditional statements with clear examples. Per https://github.com/OasisLMF/OpenDataTransform/issues/27

Issues found in running tests using the one-way-transformation:

Running the following, the transformation succeeds with no error, but only the 1st transformation is completed; second one is blank.

Running the following, the transformation succeeds with no error, but all values in d return 99