Esempio n. 1
0
    def test_environment(self):
        if self.test_only and inspect.stack()[0][3] not in self.test_only:
            return

        e = cf.environment(display=False)
        ep = cf.environment(display=False, paths=False)
        self.assertIsInstance(e, str)
        self.assertIsInstance(ep, str)

        components = ["Platform: ", "udunits2 library: ", "numpy: ", "cfdm: "]
        for component in components:
            self.assertIn(component, e)
            self.assertIn(component, ep)
        for component in [
                "cf: {} {}".format(cf.__version__,
                                   os.path.abspath(cf.__file__)),
                "Python: {} {}".format(platform.python_version(),
                                       sys.executable),
        ]:
            self.assertIn(component, e)
            self.assertNotIn(component, ep)  # paths shouldn't be present here
        for component in [
                "cf: {}".format(cf.__version__),
                "Python: {}".format(platform.python_version()),
        ]:
            self.assertIn(component, ep)
Esempio n. 2
0
    def test_environment(self):
        e = cf.environment(display=False)
        ep = cf.environment(display=False, paths=False)
        self.assertIsInstance(e, str)
        self.assertIsInstance(ep, str)

        components = ["Platform: ", "udunits2 library: ", "numpy: ", "cfdm: "]
        for component in components:
            self.assertIn(component, e)
            self.assertIn(component, ep)
        for component in [
                f"cf: {cf.__version__} {os.path.abspath(cf.__file__)}",
                f"Python: {platform.python_version()} {sys.executable}",
        ]:
            self.assertIn(component, e)
            self.assertNotIn(component, ep)  # paths shouldn't be present here
        for component in [
                f"cf: {cf.__version__}",
                f"Python: {platform.python_version()}",
        ]:
            self.assertIn(component, ep)
        f0 = f.copy()
        f0.del_construct(measure_name)
        self.assertEqual(g[0], f0)

        # Also check aggregation did not remove the measure from the inputs
        for part in f_lon_thirds:
            cell_measure = part.constructs.filter_by_identity(
                "measure:area").value()
            self.assertTrue(cell_measure.nc_get_external())

        # Now try aggregating when one part doesn't have the cell measure,
        # expecting all of the parts to still aggregate back to one field
        # without the external measure (rather than  2->1 => 1 + 1 = 2 fields).
        f_lon_thirds[1].del_construct(measure_name)
        g = cf.aggregate(f_lon_thirds)
        self.assertEqual(len(g), 1)
        self.assertFalse(g[0].cell_measures())

        # Also check measure was not removed from, or added to, any input
        for part in [f_lon_thirds[0], f_lon_thirds[2]]:
            cm = part.constructs.filter_by_identity("measure:area").value()
            self.assertTrue(cm.nc_get_external())
        self.assertFalse(f_lon_thirds[1].cell_measures())


if __name__ == "__main__":
    print("Run date:", datetime.datetime.now())
    cf.environment()
    print()
    unittest.main(verbosity=2)
Esempio n. 4
0
            cf.chunksize(chunksize)
            message = 'chunksize=' + str(chunksize)

            # Set the data for the field
            tas.set_data(cf.Data(array), axes=[T, Y, X])

            self.assertTrue((tas.data.array == uncompressed_array).all(),
                            message)

            self.assertEqual(tas.data.get_compression_type(), 'gathered',
                             message)

            self.assertTrue(
                (tas.data.compressed_array == numpy.array(
                    [[280., 282.5, 281.], [279., 278., 277.5]],
                    dtype='float32')).all(), message)

            self.assertTrue(
                (tas.data.get_list().data.array == numpy.array([1, 4,
                                                                5])).all(),
                message)


# --- End: class

if __name__ == '__main__':
    print('Run date:', datetime.datetime.now())
    print(cf.environment())
    print()
    unittest.main(verbosity=2)