Example #1
0
File: base.py Project: NCPP/ocgis
 def setUp(self):
     self.current_dir_output = None
     if self.reset_env:
         env.reset()
     if self.create_dir:
         self.current_dir_output = self.get_temporary_output_directory()
         env.DIR_OUTPUT = self.current_dir_output
Example #2
0
 def setUp(self):
     if self._reset_env: env.reset()
     if self._create_dir:
         self._test_dir = tempfile.mkdtemp(prefix='ocgis_test_')
         env.DIR_OUTPUT = self._test_dir
     else:
         self._create_dir = None
Example #3
0
 def test_np_int(self):
     try:
         self.assertEqual(env.NP_INT, env.NP_INT)
         env.NP_INT = np.int16
         self.assertEqual(env.NP_INT, np.int16)
     finally:
         env.reset()
Example #4
0
 def test_np_int(self):
     try:
         self.assertEqual(env.NP_INT, env.NP_INT)
         env.NP_INT = np.int16
         self.assertEqual(env.NP_INT, np.int16)
     finally:
         env.reset()
Example #5
0
 def setUp(self):
     if self._reset_env: env.reset()
     if self._create_dir:
         self._test_dir = tempfile.mkdtemp(prefix='ocgis_test_')
         env.DIR_OUTPUT = self._test_dir
     else:
         self._create_dir = None
Example #6
0
 def _run_():
     ocgis_lh.configure()
     self.assertTrue(ocgis_lh.null)
     env.SUPPRESS_WARNINGS = True
     ocgis_lh(level=logging.WARNING,
              exc=RuntimeWarning('show me'),
              force=True)
     env.reset()
Example #7
0
 def test_reset(self):
     # Test netCDF MPI is reset appropriately.
     if env.USE_NETCDF4_MPI:
         raise SkipTest("requires a non-netcdf4 parallel environment")
     env.USE_NETCDF4_MPI = True
     self.assertTrue(env.USE_NETCDF4_MPI)
     env.reset()
     self.assertFalse(env.USE_NETCDF4_MPI)
Example #8
0
 def test_reference_projection(self):
     self.assertIsInstance(env.REFERENCE_PROJECTION,WGS84)
     
     ## the reference projection must be set at runtime.
     os.environ['OCGIS_REFERENCE_PROJECTION'] = 'foo'
     with self.assertRaises(OcgisEnvironmentError):
         env.reset()
     os.environ.pop('OCGIS_REFERENCE_PROJECTION')
Example #9
0
 def test_np_float(self):
     try:
         self.assertEqual(env.NP_FLOAT, env.NP_FLOAT)
         env.NP_FLOAT = np.int16
         self.assertEqual(env.NP_FLOAT, np.int16)
     finally:
         env.reset()
         self.assertEqual(env.NP_FLOAT, constants.DEFAULT_NP_FLOAT)
Example #10
0
 def test_np_float(self):
     try:
         self.assertEqual(env.NP_FLOAT, env.NP_FLOAT)
         env.NP_FLOAT = np.int16
         self.assertEqual(env.NP_FLOAT, np.int16)
     finally:
         env.reset()
         self.assertEqual(env.NP_FLOAT, constants.DEFAULT_NP_FLOAT)
Example #11
0
    def test_reference_projection(self):
        self.assertIsInstance(env.REFERENCE_PROJECTION, WGS84)

        ## the reference projection must be set at runtime.
        os.environ['OCGIS_REFERENCE_PROJECTION'] = 'foo'
        with self.assertRaises(OcgisEnvironmentError):
            env.reset()
        os.environ.pop('OCGIS_REFERENCE_PROJECTION')
Example #12
0
 def test_reset(self):
     # Test netCDF MPI is reset appropriately.
     if env.USE_NETCDF4_MPI:
         raise SkipTest("requires a non-netcdf4 parallel environment")
     env.USE_NETCDF4_MPI = True
     self.assertTrue(env.USE_NETCDF4_MPI)
     env.reset()
     self.assertFalse(env.USE_NETCDF4_MPI)
Example #13
0
 def test_netcdf_file_format(self):
     try:
         self.assertEqual(env.NETCDF_FILE_FORMAT, constants.NETCDF_DEFAULT_DATA_MODEL)
         self.assertEqual(env.NP_INT, env.NP_INT)
         actual = 'NETCDF3_CLASSIC'
         env.NETCDF_FILE_FORMAT = actual
     finally:
         env.reset()
Example #14
0
 def test_netcdf_file_format(self):
     try:
         self.assertEqual(env.NETCDF_FILE_FORMAT,
                          constants.NETCDF_DEFAULT_DATA_MODEL)
         self.assertEqual(env.NP_INT, env.NP_INT)
         actual = 'NETCDF3_CLASSIC'
         env.NETCDF_FILE_FORMAT = actual
     finally:
         env.reset()
Example #15
0
File: base.py Project: NCPP/ocgis
 def tearDown(self):
     try:
         if self.create_dir:
             shutil.rmtree(self.current_dir_output)
     finally:
         if self.reset_env:
             env.reset()
         if self.shutdown_logging:
             ocgis_lh.shutdown()
Example #16
0
 def test_import_attributes(self):
     ## with both modules installed, these are expected to be true
     self.assertEqual(env.USE_CFUNITS,self.get_is_available('cfunits'))
     self.assertEqual(env.USE_SPATIAL_INDEX,self.get_is_available('rtree'))
     
     ## turn off the spatial index
     env.USE_SPATIAL_INDEX = False
     self.assertEqual(env.USE_SPATIAL_INDEX,False)
     env.reset()
     self.assertEqual(env.USE_SPATIAL_INDEX,self.get_is_available('rtree'))
Example #17
0
    def test_init(self):
        self.assertIsNone(env.MELTED)
        self.assertEqual(env.DEFAULT_GEOM_UID, constants.OCGIS_UNIQUE_GEOMETRY_IDENTIFIER)
        self.assertEqual(env.NETCDF_FILE_FORMAT, constants.NETCDF_DEFAULT_DATA_MODEL)
        self.assertEqual(env.NP_INT, env.NP_INT)
        self.assertEqual(env.NP_FLOAT, env.NP_FLOAT)

        self.assertIsInstance(env.USE_NETCDF4_MPI, bool)
        env.reset()
        self.assertIsInstance(env.USE_NETCDF4_MPI, bool)
Example #18
0
    def test_init(self):
        self.assertIsNone(env.MELTED)
        self.assertEqual(env.DEFAULT_GEOM_UID,
                         constants.OCGIS_UNIQUE_GEOMETRY_IDENTIFIER)
        self.assertEqual(env.NETCDF_FILE_FORMAT,
                         constants.NETCDF_DEFAULT_DATA_MODEL)
        self.assertEqual(env.NP_INT, env.NP_INT)
        self.assertEqual(env.NP_FLOAT, env.NP_FLOAT)

        self.assertIsInstance(env.USE_NETCDF4_MPI, bool)
        env.reset()
        self.assertIsInstance(env.USE_NETCDF4_MPI, bool)
Example #19
0
 def test_env_overload(self):
     # check env overload
     out = tempfile.mkdtemp()
     try:
         env.DIR_OUTPUT = out
         env.PREFIX = 'my_prefix'
         rd = self.test_data.get_rd('daymet_tmax')
         ops = OcgOperations(dataset=rd, snippet=True)
         self.assertEqual(env.DIR_OUTPUT, ops.dir_output)
         self.assertEqual(env.PREFIX, ops.prefix)
     finally:
         os.rmdir(out)
         env.reset()
Example #20
0
 def test_env_overload(self):
     # check env overload
     out = tempfile.mkdtemp()
     try:
         env.DIR_OUTPUT = out
         env.PREFIX = 'my_prefix'
         rd = self.test_data.get_rd('daymet_tmax')
         ops = OcgOperations(dataset=rd, snippet=True)
         self.assertEqual(env.DIR_OUTPUT, ops.dir_output)
         self.assertEqual(env.PREFIX, ops.prefix)
     finally:
         os.rmdir(out)
         env.reset()
Example #21
0
    def test_import_attributes_overloaded(self):
        try:
            import rtree

            av = True
        except ImportError:
            av = False
        self.assertEqual(env.USE_SPATIAL_INDEX, av)

        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'False'
        env.reset()
        self.assertFalse(env.USE_SPATIAL_INDEX)

        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 't'
        env.reset()
        self.assertTrue(env.USE_SPATIAL_INDEX)

        # this cannot be transformed into a boolean value, and it is also not a realistic module name, so it will
        # evaluate to false
        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'False'
        env.reset()
        self.assertFalse(env.USE_SPATIAL_INDEX)

        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'f'
        env.reset()
        self.assertFalse(env.USE_SPATIAL_INDEX)
Example #22
0
    def test_import_attributes_overloaded(self):
        try:
            import rtree

            av = True
        except ImportError:
            av = False
        self.assertEqual(env.USE_SPATIAL_INDEX, av)

        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'False'
        env.reset()
        self.assertFalse(env.USE_SPATIAL_INDEX)

        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 't'
        env.reset()
        self.assertTrue(env.USE_SPATIAL_INDEX)

        # this cannot be transformed into a boolean value, and it is also not a realistic module name, so it will
        # evaluate to false
        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'False'
        env.reset()
        self.assertFalse(env.USE_SPATIAL_INDEX)

        os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'f'
        env.reset()
        self.assertFalse(env.USE_SPATIAL_INDEX)
Example #23
0
    def test_simple(self):
        self.assertEqual(env.OVERWRITE, False)
        env.reset()
        os.environ['OCGIS_OVERWRITE'] = 't'
        self.assertEqual(env.OVERWRITE, True)
        env.OVERWRITE = False
        self.assertEqual(env.OVERWRITE, False)
        with self.assertRaises(AttributeError):
            env.FOO = 1

        env.OVERWRITE = True
        self.assertEqual(env.OVERWRITE, True)
        env.reset()
        os.environ.pop('OCGIS_OVERWRITE')
        self.assertEqual(env.OVERWRITE, False)
Example #24
0
    def test_import_attributes(self):
        try:
            # With both modules installed, these are expected to be true.
            self.assertEqual(env.USE_CFUNITS, self.get_is_available('cf_units'))
        except AssertionError:
            # Try the other unit conversion library.
            self.assertEqual(env.USE_CFUNITS, self.get_is_available('cfunits'))

        self.assertEqual(env.USE_SPATIAL_INDEX, self.get_is_available('rtree'))

        # Turn off the spatial index.
        env.USE_SPATIAL_INDEX = False
        self.assertEqual(env.USE_SPATIAL_INDEX, False)
        env.reset()
        self.assertEqual(env.USE_SPATIAL_INDEX, self.get_is_available('rtree'))
Example #25
0
    def test_simple(self):
        self.assertEqual(env.OVERWRITE, False)
        env.reset()
        os.environ['OCGIS_OVERWRITE'] = 't'
        self.assertEqual(env.OVERWRITE, True)
        env.OVERWRITE = False
        self.assertEqual(env.OVERWRITE, False)
        with self.assertRaises(AttributeError):
            env.FOO = 1

        env.OVERWRITE = True
        self.assertEqual(env.OVERWRITE, True)
        env.reset()
        os.environ.pop('OCGIS_OVERWRITE')
        self.assertEqual(env.OVERWRITE, False)
Example #26
0
    def test_import_attributes(self):
        try:
            # With both modules installed, these are expected to be true.
            self.assertEqual(env.USE_CFUNITS,
                             self.get_is_available('cf_units'))
        except AssertionError:
            # Try the other unit conversion library.
            self.assertEqual(env.USE_CFUNITS, self.get_is_available('cfunits'))

        self.assertEqual(env.USE_SPATIAL_INDEX, self.get_is_available('rtree'))

        # Turn off the spatial index.
        env.USE_SPATIAL_INDEX = False
        self.assertEqual(env.USE_SPATIAL_INDEX, False)
        env.reset()
        self.assertEqual(env.USE_SPATIAL_INDEX, self.get_is_available('rtree'))
Example #27
0
 def __iter__(self):
     its = [p().__iter__() for p in self.get_parameters()]
     for ii,values in enumerate(itertools.product(*its)):
         if self.n_only:
             yield(ii)
             continue
         if self.target_combo is not None:
             if self.target_combo > ii:
                 continue
         yield(ii)
         kwds = {}
         for val in values:
             ## check for environmental parameters
             if val.keys()[0].isupper():
                 setattr(env,val.keys()[0],val.values()[0])
             else:
                 kwds.update(val)
         if not self.ops_only:
             kwds.update({'dir_output':tempfile.mkdtemp()})
         try:
             try:
                 ops = OcgOperations(**kwds)
                 try:
                     self.check_blocked(ops)
                 except BlockedCombination:
                     continue
                 if self.verbose: print(ii)
                 if self.ops_only:
                     pass
                 else:
                     ret = ops.execute()
             except Exception as e:
                 raise
                 tb = traceback.format_exc()
                 try:
                     self.check_exception(ii,kwds,e,tb)
                 except:
                     raise
         finally:
             if not self.ops_only and self.remove_output:
                 shutil.rmtree(kwds['dir_output'])
             env.reset()
Example #28
0
File: run.py Project: imclab/ocgis
 def __iter__(self):
     its = [p().__iter__() for p in self.get_parameters()]
     for ii, values in enumerate(itertools.product(*its)):
         if self.n_only:
             yield (ii)
             continue
         if self.target_combo is not None:
             if self.target_combo > ii:
                 continue
         yield (ii)
         kwds = {}
         for val in values:
             ## check for environmental parameters
             if val.keys()[0].isupper():
                 setattr(env, val.keys()[0], val.values()[0])
             else:
                 kwds.update(val)
         if not self.ops_only:
             kwds.update({'dir_output': tempfile.mkdtemp()})
         try:
             try:
                 ops = OcgOperations(**kwds)
                 try:
                     self.check_blocked(ops)
                 except BlockedCombination:
                     continue
                 if self.verbose: print(ii)
                 if self.ops_only:
                     pass
                 else:
                     ret = ops.execute()
             except Exception as e:
                 raise
                 tb = traceback.format_exc()
                 try:
                     self.check_exception(ii, kwds, e, tb)
                 except:
                     raise
         finally:
             if not self.ops_only and self.remove_output:
                 shutil.rmtree(kwds['dir_output'])
             env.reset()
Example #29
0
 def _run_():
     ocgis_lh.configure()
     self.assertTrue(ocgis_lh.null)
     env.SUPPRESS_WARNINGS = True
     ocgis_lh(level=logging.WARNING, exc=RuntimeWarning('show me'), force=True)
     env.reset()
Example #30
0
 def test_reset(self):
     # Test netCDF MPI is reset appropriately.
     env.USE_NETCDF4_MPI = True
     self.assertTrue(env.USE_NETCDF4_MPI)
     env.reset()
     self.assertFalse(env.USE_NETCDF4_MPI)
Example #31
0
 def setUp(self):
     env.reset()
     self._new_dir = tempfile.mkdtemp(prefix='ocgis_test_',dir=env.DIR_OUTPUT)
     env.DIR_OUTPUT = self._new_dir
     env.OVERWRITE = True
Example #32
0
 def tearDown(self):
     try:
         shutil.rmtree(self._new_dir)
     finally:
         env.reset()
Example #33
0
 def setUp(self):
     env.reset()
     self._new_dir = tempfile.mkdtemp(prefix='ocgis_test_',
                                      dir=env.DIR_OUTPUT)
     env.DIR_OUTPUT = self._new_dir
     env.OVERWRITE = True
Example #34
0
 def tearDown(self):
     try:
         shutil.rmtree(self._new_dir)
     finally:
         env.reset()
Example #35
0
 def tearDown(self):
     try:
         if self._create_dir: shutil.rmtree(self._test_dir)
     finally:
         if self._reset_env: env.reset()
Example #36
0
 def tearDown(self):
     try:
         if self._create_dir: shutil.rmtree(self._test_dir)
     finally:
         if self._reset_env: env.reset()