__all__=['csv_validity_test',]importosimportloggingimportsubprocessfrom..utils.exceptionsimportOasisException# Model files to testINPUT_FILES={'damage_bin_dict':{'name':'damage_bin_dict','validation_tool':'validatedamagebin','flag':'-d'},'footprint':{'name':'footprint','validation_tool':'validatefootprint','flag':'-f'},'vulnerability':{'name':'vulnerability','validation_tool':'validatevulnerability','flag':'-s'}}
[docs]defcsv_validity_test(model_data_fp):""" Assess validity of model data. :param model_data_fp: directory containing csv files :type model_data_fp: str :raises OasisException: if one of the tests fail """logger=logging.getLogger(__name__)logger.setLevel(logging.INFO)model_data_dir=os.path.abspath(model_data_fp)# Check individual filesforinput_fileinINPUT_FILES.values():validation_tool=input_file['validation_tool']input_file_path=os.path.join(model_data_dir,'{}.csv'.format(input_file['name']))logger.info("Testing {}.csv".format(input_file['name']))cmd_str="{} < {}".format(validation_tool,input_file_path)try:subprocess.check_call(cmd_str,stderr=subprocess.STDOUT,shell=True)exceptsubprocess.CalledProcessErrorase:raiseOasisException("Exception raised in 'csv_validity_test'",e)# Execute cross checkslogger.info("Executing cross checks")cmd_str="crossvalidation"forinput_fileinINPUT_FILES.values():flag=input_file['flag']input_file_path=os.path.join(model_data_dir,'{}.csv'.format(input_file['name']))cmd_str+=" {}{}".format(flag,input_file_path)try:subprocess.check_call(cmd_str,stderr=subprocess.STDOUT,shell=True)exceptsubprocess.CalledProcessErrorase:raiseOasisException("Exception raised in 'csv_validity_test'",e)