def test_mat_write_failing_check_extension(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') with self.assertRaises(ValueError): mat_handler.write( output, 'tests/test_datasets/matlab_output_test_out.vtk')
def write_file(self, filename, infile): """ This method writes out the solution in the proper format. In this way, you can view the results with the viewer you like. :param string filename: name of the output file. :param string infile: name of the input file. For the mat file this is simply necessary for the parse function. for the vtk is necessary for having the correct grid for the new output field. """ __, file_ext = os.path.splitext(filename) if file_ext == '.mat': mat_handler = mh.MatlabHandler() mat_handler.parse(infile, self.output_name) mat_handler.write(self.output, filename) elif file_ext == '.vtk': vtk_handler = vh.VtkHandler() vtk_handler.parse(infile, self.output_name) vtk_handler.write(self.output, filename, output_name=self.output_name) else: raise NotImplementedError( file_ext + " file extension is not implemented yet.")
def __init__(self, output_name, namefile_prefix, file_format): self.output_name = output_name self.namefile_prefix = namefile_prefix self.file_format = file_format self.mu_values = None matlab_handler = mh.MatlabHandler() self.snapshots = matlab_handler.parse(self.namefile_prefix + '0' + self.file_format, self.output_name)
def add_snapshot(self): """ This methos adds the new solution to the database and the new parameter values to the parameter points. This can be done only after the new solution has be computed and placed in the proper directory. """ matlab_handler = mh.MatlabHandler() self.mu_values = self.cvt_handler.mu_values dim_mu = self.mu_values.shape[1] snapshot = matlab_handler.parse(self.namefile_prefix + str(dim_mu-1) + self.file_format, self.output_name) self.snapshots = np.append(self.snapshots, snapshot, 1) self.print_info()
def test_stl_write_comparison(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') output[0] = [1.1] output[1] = [1.1] output[2] = [1.1] output[11] = [1.1] output[12] = [1.1] output[13] = [1.1] output[30] = [1.1] output[31] = [1.1] output[32] = [1.1] outfilename = 'tests/test_datasets/matlab_output_test_out.mat' mat_handler.write(output, outfilename) os.remove(outfilename)
def start(self): """ Compute the starting parameter sample and snapshots. """ mu_1 = np.array([-.5, .5, .5, -.5]) mu_2 = np.array([-.5, -.5, .5, .5]) self.mu_values = np.array([mu_1, mu_2]) dim_set = self.mu_values.shape[1] matlab_handler = mh.MatlabHandler() # TODO: insert an assert if the number of dim_set is different from the number of files for the extraction of the output for i in range(1,dim_set): snapshot = matlab_handler.parse(self.namefile_prefix + str(i) + self.file_format, self.output_name) self.snapshots = np.append(self.snapshots, snapshot, 1) self.print_info()
def __init__(self, output_name, weights_name, namefile_prefix, file_format): self.output_name = output_name self.weights_name = weights_name self.namefile_prefix = namefile_prefix self.file_format = file_format self.mu_values = None self.pod_basis = None self.file_handler = vh.VtkHandler() if self.file_format == '.vtk': self.file_handler = vh.VtkHandler() elif self.file_format == '.mat': self.file_handler = mh.MatlabHandler() aux_snapshot = self.file_handler.parse( self.namefile_prefix + '0' + self.file_format, self.output_name) self.snapshots = aux_snapshot.reshape(aux_snapshot.shape[0], 1) self.weights = None self.cvt_handler = None
def test_mat_parse_coords_2(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') np.testing.assert_almost_equal(output[0][0], 149.0353302)
def test_mat_default_extension_member(self): mat_handler = mh.MatlabHandler() assert mat_handler.extension == '.mat'
def test_mat_parse_failing_filename_type(self): mat_handler = mh.MatlabHandler() with self.assertRaises(TypeError): output = mat_handler.parse(5.2)
def test_mat_instantiation(self): mat_handler = mh.MatlabHandler()
def test_mat_parse_failing_output_name_type(self): mat_handler = mh.MatlabHandler() with self.assertRaises(TypeError): output = mat_handler.parse( 'tests/test_datasets/matlab_field_test.vtk', 5.2)
def test_mat_write_failing_infile_instantiation(self): mat_handler = mh.MatlabHandler() output = np.zeros((40, 3)) with self.assertRaises(RuntimeError): mat_handler.write( output, 'tests/test_datasets/matlab_output_test_out.mat')
def test_mat_default_infile_member(self): mat_handler = mh.MatlabHandler() assert mat_handler.infile == None
def test_mat_parse_failing_check_extension(self): mat_handler = mh.MatlabHandler() with self.assertRaises(ValueError): output = mat_handler.parse( 'tests/test_datasets/matlab_field_test.vtk')
def test_mat_parse_coords_1(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') np.testing.assert_almost_equal(output[33][0], 16.8143769)
def test_mat_parse_shape(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') assert output.shape == (64, 1)
def test_mat_parse_infile(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') assert mat_handler.infile == 'tests/test_datasets/matlab_output_test.mat'
def test_mat_instantiation(self): mat_handler = mh.MatlabHandler(mat_file) assert (isinstance(mat_handler, mh.MatlabHandler))
def test_mat_write_failing_filename_type(self): mat_handler = mh.MatlabHandler() output = mat_handler.parse( 'tests/test_datasets/matlab_output_test.mat') with self.assertRaises(TypeError): mat_handler.write(output, 4.)