def _save_spill_data(self): """ save the data arrays for current timestep to NetCDF """ nc_out = NetCDFOutput(self._certainspill_data, all_data=True, cache=self.model._cache) nc_out.prepare_for_model_run(model_start_time=self.model.start_time, uncertain=self.model.uncertain, spills=self.model.spills) nc_out.write_output(self.model.current_time_step) self._uncertainspill_data = nc_out._u_netcdf_filename
def test_exceptions(): """ test exceptions """ # Test exceptions raised after object creation t_file = os.path.join(base_dir, 'temp.nc') netcdf = NetCDFOutput(t_file) with pytest.raises(TypeError): netcdf.prepare_for_model_run(num_time_steps=4) with pytest.raises(TypeError): netcdf.prepare_for_model_run() netcdf.prepare_for_model_run(model_start_time=datetime.now(), num_time_steps=4) with pytest.raises(ValueError): netcdf.write_output(0) with pytest.raises(ValueError): # raise error because file 'temp.nc' should already exist netcdf.prepare_for_model_run(model_start_time=datetime.now(), num_time_steps=4) with pytest.raises(ValueError): # all_data is True but spills are not provided so raise an error netcdf.rewind() netcdf.all_data = True netcdf.prepare_for_model_run(model_start_time=datetime.now(), num_time_steps=4) # clean up temporary file if os.path.exists(t_file): print 'remove temporary file {0}'.format(t_file) os.remove(t_file)