def test_Query(self): f = cf.read(self.filename)[0] q = cf.Query('wi', [2, 5]) r = cf.Query('le', 67) s = q | r t = cf.Query('gt', 12, attr='bounds') u = s & t _ = repr(q) _ = repr(s) _ = repr(t) _ = repr(u) _ = str(q) _ = str(s) _ = str(t) _ = str(u) _ = u.dump(display=False) _ = u.attr _ = u.operator _ = q.attr _ = q.operator _ = q.value with self.assertRaises(Exception): _ = u.value self.assertTrue(u.equals(u.copy(), verbose=2)) self.assertFalse(u.equals(t, verbose=0)) _ = copy.deepcopy(u) c = f.dimension_coordinate('X') self.assertTrue(((cf.contains(21.1) == c).array == numpy.array([0, 1, 0, 0, 0, 0, 0, 0, 0], bool)).all()) self.assertTrue(((cf.contains(999) == c).array == numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0], bool)).all()) _ = cf.cellsize(34) _ = cf.cellsize(q) _ = cf.celllt(3) _ = cf.cellle(3) _ = cf.cellge(3) _ = cf.cellgt(3) _ = cf.cellwi(1, 2) _ = cf.cellwo(1, 2)
c == 2 c == 3 upper_bounds_ge_minus4 = cf.Query('ge', -4, attr='upper_bounds') X = t.dimension_coordinate('X') X print(X.bounds.array) print((upper_bounds_ge_minus4 == X).array) cf.contains(4) cf.Query('lt', 4, attr='lower_bounds') & cf.Query('ge', 4, attr='upper_bounds') cf.ge(3) cf.ge(cf.dt('2000-3-23')) cf.year(1999) cf.month(cf.wi(6, 8)) cf.jja() cf.contains(4) cf.cellsize(cf.lt(10, 'degrees')) print("\n**Assignment by condition**\n") t = cf.read('file.nc')[1] print(t.array) u = t.where(cf.lt(273.15), x=cf.masked) print(u.array) u = t.where(cf.lt(273.15), x=0, y=1) print(u.array) print(t.where(u, x=-t, y=-99).array) print(t.where(cf.gt(0.5), x=cf.masked, construct='grid_latitude').array) print("\n**Field creation**\n") print("\n**Stage 1:** The field construct is created without metadata\n")