def test_image_save_overwrite(): image = PDS3Image.open(filename) image.save('Temp_Image.IMG') image_temp = PDS3Image.open('Temp_Image.IMG') image_temp.save(overwrite=True) new_image = PDS3Image.open(image_temp.filename) assert image_temp.filename == new_image.filename assert image_temp.bands == new_image.bands assert image_temp.lines == new_image.lines assert image_temp.samples == new_image.samples assert image_temp.format == new_image.format assert image_temp.dtype == new_image.dtype assert image_temp.start_byte == new_image.start_byte assert image_temp.shape == new_image.shape assert image_temp.size == new_image.size # Testing .label assert image_temp.label['FILE_RECORDS'] == new_image.label['FILE_RECORDS'] label_sample_type = image_temp.label['IMAGE']['SAMPLE_TYPE'] assert label_sample_type == new_image.label['IMAGE']['SAMPLE_TYPE'] # Testing .data assert image_temp.data.shape == new_image.data.shape assert image_temp.data.dtype == image.data.dtype os.remove('Temp_Image.IMG')
def test_image_save_1band(): image = PDS3Image.open(filename_3bands) image.data = image.data[0, :, :] image.save('Temp_Image.IMG') image_temp = PDS3Image.open('Temp_Image.IMG') assert image_temp.bands == 1 os.remove('Temp_Image.IMG')
def test_image_save_3bands(): image = PDS3Image.open(filename) temp_data = numpy.array([image.data, image.data, image.data]) image.data = temp_data.reshape(3, 10, 10) image.save('Temp_Image.IMG') image_temp = PDS3Image.open('Temp_Image.IMG') assert image_temp.bands == 3 os.remove('Temp_Image.IMG')
def test_image_save_lines_linesamples(): image = PDS3Image.open(filename) image.data = image.data[0, 3:8, 3:8] image.save('Temp_Image.IMG') image_temp = PDS3Image.open('Temp_Image.IMG') assert image_temp.lines == 5 assert image_temp.samples == 5 os.remove('Temp_Image.IMG')
def test_image_save_float_to_int(): image = PDS3Image.open(filename_float) ref_image = PDS3Image.open(filename) image.data /= 1.5 image.data = image.data.astype('>i2') image.save('Temp_Image.IMG') image_temp = PDS3Image.open('Temp_Image.IMG') assert image_temp.dtype == ref_image.dtype assert_almost_equal(image.data, ref_image.data) os.remove('Temp_Image.IMG')
def test_pds3_1band_labels(expected): image = PDS3Image.open(filename) assert image.filename == filename assert image.bands == 1 assert image.lines == 10 assert image.samples == 10 assert image.format == "BAND_SEQUENTIAL" assert image.dtype == numpy.dtype(">i2") assert image.start_byte == 640 assert image.shape == (1, 10, 10) # FIXME: Doublecheck that consolidating pixel_type and byte order # is actually OK for PDS images. I think here at the object level # its OK even though in the PDS labels the information is separate. assert image.size == 100 assert image.compression is None # Testing .label assert image.label["FILE_RECORDS"] == 42 assert image.label["IMAGE"]["SAMPLE_TYPE"] == "MSB_INTEGER" # Testing .data assert image.data.shape == (1, 10, 10) assert image.data.dtype == numpy.dtype(">i2") assert_almost_equal(image.data, expected)
def test_mission_data(): data_products = PlanetaryTestDataProducts() for file_name in data_products.products: image_path = os.path.join(data_products.directory, file_name) try: image = PDS3Image.open(image_path) assert data_products.mission_data[file_name]['opens'] == "True" data_label = data_products.mission_data[file_name]['label'] for key in data_label: try: if isinstance(data_label[key], dict): sub_dict = data_label[key] for sub_key in sub_dict: assert sub_dict[sub_key] == \ image.label[key][sub_key] else: assert data_label[key] == image.label[key] except: print ("Problem with %s label" % (file_name)) except (pvl.decoder.ParseError, KeyError, UnicodeDecodeError, ValueError): try: assert data_products.mission_data[file_name]['opens'] \ == "False" except: print ("%s is marked as True & should be false" % (file_name)) except AssertionError: print ("%s is marked as False & should be True" % (file_name))
def test_mission_data(): data_products = PlanetaryTestDataProducts() for file_name in data_products.products: image_path = os.path.join(data_products.directory, file_name) try: image = PDS3Image.open(image_path) assert data_products.mission_data[file_name]['opens'] == "True" data_label = data_products.mission_data[file_name]['label'] for key in data_label: try: if isinstance(data_label[key], dict): sub_dict = data_label[key] for sub_key in sub_dict: assert sub_dict[sub_key] == \ image.label[key][sub_key] else: assert data_label[key] == image.label[key] except: print("Problem with %s label" % (file_name)) except (pvl.decoder.ParseError, KeyError, UnicodeDecodeError, ValueError): try: assert data_products.mission_data[file_name]['opens'] \ == "False" except: print("%s is marked as True & should be false" % (file_name)) except AssertionError: print("%s is marked as False & should be True" % (file_name))
def test_pds3_1band_labels(expected): image = PDS3Image.open(filename) assert image.filename == filename assert image.bands == 1 assert image.lines == 10 assert image.samples == 10 assert image.format == 'BAND_SEQUENTIAL' assert image.dtype == numpy.dtype('>i2') assert image.start_byte == 640 assert image.shape == (1, 10, 10) # FIXME: Doublecheck that consolidating pixel_type and byte order # is actually OK for PDS images. I think here at the object level # its OK even though in the PDS labels the information is separate. assert image.size == 100 assert image.compression is None # Testing .label assert image.label['FILE_RECORDS'] == 42 assert image.label['IMAGE']['SAMPLE_TYPE'] == 'MSB_INTEGER' # Testing .data assert image.data.shape == (1, 10, 10) assert image.data.dtype == numpy.dtype('>i2') assert_almost_equal(image.data, expected)
def test_numpy_array_save_i2(): array = numpy.arange(100, dtype='>i2') array = array.reshape(1, 10, 10) temp = PDS3Image(array) temp.save('Temp_Image.IMG') image_temp = PDS3Image.open('Temp_Image.IMG') assert image_temp.bands == 1 assert image_temp.lines == 10 assert image_temp.samples == 10 assert image_temp.format == 'BAND_SEQUENTIAL' assert image_temp.dtype == '>i2' assert image_temp.shape == (1, 10, 10) assert image_temp.size == 100 assert_almost_equal(image_temp.data, array) os.remove('Temp_Image.IMG')
def test_mission_data(): with open(os.path.join(DATA_DIR, "data.json"), "r") as r: data = json.load(r) for file_name in data.keys(): image_path = os.path.join(DATA_DIR, file_name) try: image = PDS3Image.open(image_path) assert data[file_name]["opens"] == "True" assert data[file_name]["label"] == image.label.items()[0][1] except (pvl.decoder.ParseError, KeyError, UnicodeDecodeError, ValueError): try: assert data[file_name]["opens"] == "False" except: print(file_name, "is marked as True and should be false") except AssertionError: print(file_name, "is marked as False and should be True")
def test_bz2_pds3_1band_labels(expected): image = PDS3Image.open(bz2_filename) assert image.filename == bz2_filename assert image.bands == 1 assert image.lines == 10 assert image.samples == 10 assert image.format == "BAND_SEQUENTIAL" assert image.dtype == numpy.dtype(">i2") assert image.start_byte == 640 assert image.shape == (1, 10, 10) assert image.size == 100 assert image.compression == "bz2" # Testing .label assert image.label["FILE_RECORDS"] == 42 assert image.label["IMAGE"]["SAMPLE_TYPE"] == "MSB_INTEGER" # Testing .data assert image.data.shape == (1, 10, 10) assert image.data.dtype == numpy.dtype(">i2") assert_almost_equal(image.data, expected)
def test_gz_pds3_1band_labels(expected): image = PDS3Image.open(gzipped_filename) assert image.filename == gzipped_filename assert image.bands == 1 assert image.lines == 10 assert image.samples == 10 assert image.format == 'BAND_SEQUENTIAL' assert image.dtype == numpy.dtype('>i2') assert image.start_byte == 640 assert image.shape == (1, 10, 10) assert image.size == 100 assert image.compression == 'gz' # Testing .label assert image.label['FILE_RECORDS'] == 42 assert image.label['IMAGE']['SAMPLE_TYPE'] == 'MSB_INTEGER' # Testing .data assert image.data.shape == (1, 10, 10) assert image.data.dtype == numpy.dtype('>i2') assert_almost_equal(image.data, expected)
def test_image_save_samefile(): image = PDS3Image.open(filename) with pytest.raises(IOError): image.save(image.filename)