Example #1
0
 def sanity_check(self):
     """
     Sanity check on the total number of assets
     """
     if self.R == 1:
         arr = self.datastore.sel('damages-rlzs')  # shape (A, 1, L, D)
     else:
         arr = self.datastore.sel('damages-stats', stat='mean')
     avg = arr.sum(axis=(0, 1))  # shape (L, D)
     if not len(self.datastore['dd_data/aid']):
         logging.warning('There is no damage at all!')
     else:
         df = views.portfolio_damage_error(self.datastore, avg[:, 1:])
         rst = views.rst_table(numpy.array(df), list(df.columns))
         logging.info('Portfolio damage\n%s' % rst)
     num_assets = avg.sum(axis=1)  # by loss_type
     expected = self.assetcol['number'].sum()
     nums = set(num_assets) | {expected}
     if len(nums) > 1:
         numdic = dict(expected=expected)
         for lt, num in zip(self.oqparam.loss_names, num_assets):
             numdic[lt] = num
         logging.info(
             'Due to numeric errors the total number of assets'
             ' is imprecise: %s', numdic)
Example #2
0
 def sanity_check(self):
     """
     Sanity check on the total number of assets
     """
     if self.R == 1:
         arr = self.datastore.sel('damages-rlzs')  # shape (A, 1, L, D)
     else:
         arr = self.datastore.sel('damages-stats', stat='mean')
     avg = arr.sum(axis=(0, 1))  # shape (L, D)
     if not len(self.datastore['risk_by_event/agg_id']):
         logging.warning('There is no damage at all!')
     elif 'avg_portfolio_damage' in self.datastore:
         df = views.portfolio_damage_error('avg_portfolio_damage',
                                           self.datastore)
         rst = views.text_table(df, ext='org')
         logging.info('Portfolio damage\n%s' % rst)
     num_assets = avg.sum(axis=1)  # by loss_type
     expected = self.assetcol['value-number'].sum()
     nums = set(num_assets) | {expected}
     if len(nums) > 1:
         numdic = dict(expected=expected)
         for lt, num in zip(self.oqparam.loss_names, num_assets):
             numdic[lt] = num
         logging.info(
             'Due to rounding errors inherent in floating-point arithmetic,'
             ' the total number of assets is not exact: %s', numdic)