def test_wrapup( self ) -> dict(ov='Summary of tests', id='tc900', obj='Provide quick overview', p='SHOULD', tr='tbd', prec='None', i='None', expected=True): Check3(self.test_wrapup)(True, cmt=Check3.review())
def test_fail04( self ) -> dict(ov='Test of making a report', obj='Evaluate wrapping code', p='MUST', expected=True): Check3(self.test_fail04)(False)
def test_fraction( self ) -> dict( ov='Test of Sampler object: looking at area fraction values', id='tc104', obj='Test whether missing values in data are assigned consistently', p='SHOULD', tr='tbd', prec='None', i='None', expected='OK'): rep = self.__class__.fraction_report if rep[0] == 'no report': res = 'OK' cmt = 'no report' elif len(rep[0]) > 1: res = 'ERROR' cmt = 'confused report' else: if rep[1] > rep[4]: res = 'OK' cmt = 'Min unmasked [%s] > max masked [%s]' % (rep[1], rep[4]) else: res = 'Area Fraction Error' cmt = 'Min unmasked [%s] < max masked [%s]' % (rep[1], rep[4]) Check3(self.test_fraction)(res, cmt=cmt)
def test_ranges( self ) -> dict(ov='Test of Sampler object: expected ranges', id='tc102', obj='test Sampler attributes', p='SHOULD', tr='tbd', prec='None', i='None', expected=True): if self.__class__.ranges == None: return 'No ranges set' ranges = self.__class__.ranges print('ranges: ', ranges) ks = sorted(list(self.__class__.vs.sr_dict.keys())) basic = [self.__class__.vs.sr_dict[k]['basic'] for k in ks] drl, nfv = self.__class__.basic data_min, data_max, data_ma_min, data_ma_max = drl[:4] data_min_l0 = data_max_l0 = None if len(drl) == 6: data_min_l0, data_max_l0 = drl[-2:] res = [] if hasattr(ranges, 'min_l0') and ranges.min_l0.status != 'NONE': min_valid = float(ranges.min_l0.value) res.append( ('min', data_min_l0, min_valid, data_min_l0 >= min_valid)) if hasattr(ranges, 'max_l0') and ranges.max_l0.status != 'NONE': max_valid = float(ranges.max_l0.value) res.append( ('max', data_max_l0, max_valid, data_max_l0 <= max_valid)) if ranges.min.status != 'NONE': min_valid = float(ranges.min.value) res.append(('min', data_min, min_valid, data_min >= min_valid)) if ranges.max.status != 'NONE': max_valid = float(ranges.max.value) res.append(('max', data_max, max_valid, data_max <= max_valid)) if ranges.ma_max.status != 'NONE': ma_max_valid = float(ranges.ma_max.value) res.append(('ma_max', data_ma_max, ma_max_valid, data_ma_max <= ma_max_valid)) if ranges.ma_min.status != 'NONE': ma_min_valid = float(ranges.min.value) res.append(('ma_min', data_ma_min, ma_min_valid, data_ma_min >= ma_min_valid)) Check3(self.test_ranges)(all([x[-1] for x in res]), cmt=self.__class__.range_comment)
def test_pass03( self ) -> dict(ov='Test of making a report', obj='Evaluate wrapping code', p='MUST', expected=True): tt = Check3(self.test_pass03) x = 3 y = 4 z = 5 tt(x**2 + y**2 == z**2 + 1)
def test_fail03( self ) -> dict(ov='Test of making a report', id='tc105', obj='Evaluate wrapping code', p='MUST', tr='tbd', prec='None', i='None', expected=True): Check3(self.test_fail03)(False)
def test_masks( self ) -> dict(ov='Test of Sampler object: expected mask extent', id='tc103', obj='test Sampler attributes', p='SHOULD', tr='tbd', prec='None', i='None', expected='OK'): if self.__class__.mask_check in [True, None]: res = 'OK' else: res = 'Mask Error' Check3(self.test_masks)(res, cmt=self.__class__.mask_comment)
def test_file( self ) -> dict(ov='Test of Sampler object: expected attributes', id='tc101', obj='test Sampler attributes', p='SHOULD', tr='tbd', prec='None', i='None', expected=True): this_file = os.environ['CMIP_FILE'].replace('//', '/') ##log = logging.getLogger( LOG_NAME ) ##log.info( 'Starting: %s' % this_file ) print('Starting: %s' % this_file) tt = Check3(self.test_file) self.sampler = Sampler(**self.sample_config) if not os.path.isfile(this_file): tt('File not found: %s' % this_file) try: nc = netCDF4.Dataset(this_file) except: tt('Could not open netCDF4 Dataset') pbase = '/badc/cmip6/data/CMIP6/' if this_file.find(pbase) != 0: tt('DRS not in path: %s' % this_file) try: era = 'CMIP6' activity, inst, model, expt, variant_id, table, var, grid_id, version = this_file[ len(pbase):].split('/')[:9] except: tt('Could not extract DRS') ## http://esgdata.gfdl.noaa.gov/thredds/fileServer/gfdl_dataroot4/OMIP/NOAA-GFDL/GFDL-OM4p5B/omip1/r1i1p1f1/Omon/volcello/gn/v20180701/volcello_Omon_GFDL-OM4p5B_omip1_r1i1p1f1_gn_180801-182712.nc try: tid = nc.tracking_id if "contact" in nc.ncattrs(): contact = nc.contact else: contact = None except: tt('Could not find required attributes') try: fname = this_file.rpartition('/')[-1] vname, table, model, expt, vnt_id, grid = fname.rpartition( '.')[0].split('_')[0:6] # rsdt_Amon_MIROC6_historical_r1i1p1f1_gn_195001-201412.nc this_var = nc.variables[vname] except: tt('Could not find variable in netCDF4 Dataset') if table not in ["fx", "Ofx"]: try: time_var = nc.variables['time'] time_units = time_var.units dt = time_var[1:] - time_var[:-1] dt0 = numpy.mean(dt) dt1 = numpy.max(dt) except: tt('Could not find time axis information') else: dt0 = None try: shp = this_var.shape[:] units = this_var.units dimensions = this_var.dimensions except: tt('Could not find required variable properties') self.__class__.with_mask = False try: if hasattr(this_var, '_FillValue'): fill_value = this_var._FillValue else: fill_value = None kwargs = dict(fill_value=fill_value) tt1 = (model, expt, table, vname, grid) mk = '.'.join([vname, table, model, expt, grid]) mkb = '.'.join([vname, table, model, grid]) if table in mode_by_table: kwargs['mode'] = mode_by_table[table] if mk in mlu: kwargs['ref_mask_file'] = mlu[mk] self.__class__.with_mask = True print('USING MASK') elif mkb in mlu_bb: kwargs['ref_mask_file'] = mlu_bb[mkb] self.__class__.with_mask = True print('USING MASK [different expt]') vs = VariableSampler(this_var[:], self.sampler, **kwargs) except: tt('Could not instantiate scanner') drs = (table, var, inst, model, activity, expt, variant_id, grid_id, version) self.file_info = dict(tid=tid, contact=contact, shape=shp, units=units, dimensions=dimensions, fill_value=fill_value, drs=drs) if dt0 != None: self.file_info['time_units'] = time_units self.file_info['time_intervals'] = (dt0, dt1) try: vs.scan() except: tt('Could not scan variable') try: fstem = fname.rpartition('.')[0] vs.dump_shelve('%s/%s' % (self.shdir, fstem), fname, mode='n', file_info=self.file_info) except: tt('Could not dump variable') self.__class__.vs = vs vid = '%s.%s' % (table, vname) if vid in self.ranges_dict: self.__class__.ranges = self.ranges_dict[vid] self._gather_basic(vs) else: self.__class__.ranges = None tt(True)