コード例 #1
0
 def test_write_read_vars(self):
     
     raise unittest.SkipTest('Problem with _test_variables - fails for reasons unknown...')
     ack = dap_tools.write_netcdf_from_dataset(self.ds1, self.testname)
     self.assertEqual(ack,0)
     
     self.ds2 = dap_tools.read_netcdf_from_file(self.testname)
     self._test_variables(self.ds1,self.ds2)
コード例 #2
0
    def test_write_read_vars(self):

        raise unittest.SkipTest(
            'Problem with _test_variables - fails for reasons unknown...')
        ack = dap_tools.write_netcdf_from_dataset(self.ds1, self.testname)
        self.assertEqual(ack, 0)

        self.ds2 = dap_tools.read_netcdf_from_file(self.testname)
        self._test_variables(self.ds1, self.ds2)
コード例 #3
0
ファイル: persister.py プロジェクト: sunetos/ioncore-python
    def _save_dap_dataset(self, dataset, path):
        """
        @brief save the dataset as a netcdf file or append to an existing file
        @param dataset a pydap dataset
        @param fname the name of the file to write the pydap dataset,
        fname must use an absolute path
        """

        fname = dataset.name
        fname = os.path.join(path, fname)

        if "%2Enc" in fname:
            fname = fname.replace("%2Enc", ".nc")

        elif not ".nc" in fname:
            fname = ".".join((fname, "nc"))

        logging.info("running _save_dap_dataset, fname=%s" % fname)
        try:
            os.stat(fname)
        except OSError:
            logging.info("Archive file does not exist")
            # Use return value - or throw an exception?
            return 1

        # Check to see if the file exists but is empty.
        if os.path.getsize(fname) == 0:
            # Write the data to a new file
            logging.info("Archive file exists, but is empty")
            dap_tools.write_netcdf_from_dataset(dataset, fname)
            return 0
        else:
            # The file exists and is not empty, append the contents

            tmp_file_base = os.path.join(path, str(uuid.uuid4())[:8])

            tmp_file_0 = tmp_file_base + "_0.nc"

            shutil.copy(fname, tmp_file_0)

            tmp_file_1 = tmp_file_base + "_1.nc"
            dap_tools.write_netcdf_from_dataset(dataset, tmp_file_1)

            logging.info("Write new dataset to the file")
            configfile = self._create_nca_configfile(tmp_file_base)
            logging.info("Initializing nca handler")
            h = ncaHandler(configfile.name)
            try:
                ds = h.parse_constraints({"pydap.ce": (None, None)})
            except:
                logging.exception("problem using append handler")
                # Use return value or exception?
                os.remove(tmp_file_1)
                os.remove(tmp_file_0)
                return 2

            logging.info("Created new netcdf dataset")
            dap_tools.write_netcdf_from_dataset(ds, tmp_file_base + "agg.nc")
            shutil.move(tmp_file_base + "agg.nc", fname)

            configfile.close()
            os.remove(tmp_file_1)
            os.remove(tmp_file_0)

            return 0
コード例 #4
0
ファイル: persister.py プロジェクト: swarbhanu/ioncore-python
    def _save_dap_dataset(self, dataset, path):
        """
        @brief save the dataset as a netcdf file or append to an existing file
        @param dataset a pydap dataset
        @param fname the name of the file to write the pydap dataset,
        fname must use an absolute path
        """

        fname = dataset.name
        fname = os.path.join(path, fname)

        if '%2Enc' in fname:
            fname = fname.replace('%2Enc', '.nc')

        elif not '.nc' in fname:
            fname = ".".join((fname, "nc"))

        logging.info("running _save_dap_dataset, fname=%s" % fname)
        try:
            os.stat(fname)
        except OSError:
            logging.info("Archive file does not exist")
            # Use return value - or throw an exception?
            return 1

        #Check to see if the file exists but is empty.
        if os.path.getsize(fname) == 0:
            # Write the data to a new file
            logging.info("Archive file exists, but is empty")
            dap_tools.write_netcdf_from_dataset(dataset, fname)
            return 0
        else:
            #The file exists and is not empty, append the contents

            tmp_file_base = os.path.join(path, str(uuid.uuid4())[:8])

            tmp_file_0 = tmp_file_base + '_0.nc'

            shutil.copy(fname, tmp_file_0)

            tmp_file_1 = tmp_file_base + '_1.nc'
            dap_tools.write_netcdf_from_dataset(dataset, tmp_file_1)

            logging.info("Write new dataset to the file")
            configfile = self._create_nca_configfile(tmp_file_base)
            logging.info("Initializing nca handler")
            h = ncaHandler(configfile.name)
            try:
                ds = h.parse_constraints({'pydap.ce': (None, None)})
            except:
                logging.exception("problem using append handler")
                # Use return value or exception?
                os.remove(tmp_file_1)
                os.remove(tmp_file_0)
                return 2

            logging.info("Created new netcdf dataset")
            dap_tools.write_netcdf_from_dataset(ds, tmp_file_base + 'agg.nc')
            shutil.move(tmp_file_base + 'agg.nc', fname)

            configfile.close()
            os.remove(tmp_file_1)
            os.remove(tmp_file_0)

            return 0
コード例 #5
0
    def test_write_read_global_atts(self):
        ack = dap_tools.write_netcdf_from_dataset(self.ds1, self.testname)
        self.assertEqual(ack, 0)

        self.ds2 = dap_tools.read_netcdf_from_file(self.testname)
        self._test_global_atts(self.ds1, self.ds2)
コード例 #6
0
 def test_write_read_global_atts(self):
     ack = dap_tools.write_netcdf_from_dataset(self.ds1, self.testname)
     self.assertEqual(ack,0)
     
     self.ds2 = dap_tools.read_netcdf_from_file(self.testname)
     self._test_global_atts(self.ds1,self.ds2)