def test_get_time_coordinates(self) -> None: db = create_bundle_db_in_memory() db.create_tables() fits_product_lidvid = "urn:nasa:pds:hst_13012:data_acs_raw:jbz504eoq_raw::2.3" os_filepath = path_to_testfile("jbz504eoq_raw.fits") populate_database_from_fits_file(db, os_filepath, fits_product_lidvid) file_basename = basename(os_filepath) card_dicts = db.get_card_dictionaries(fits_product_lidvid, file_basename) nb = get_time_coordinates( get_start_stop_times( DictLookup("test_get_time_coordinates", card_dicts))) doc = xml.dom.getDOMImplementation().createDocument(None, None, None) str: bytes = nb(doc).toxml().encode() str = pretty_print(str) expected = b"""<?xml version="1.0"?> <Time_Coordinates> <start_date_time>2012-09-27T20:23:28Z</start_date_time> <stop_date_time>2012-09-27T20:27:58Z</stop_date_time> </Time_Coordinates> """ self.assertEqual(expected, str)
def test_file_offsets(self) -> None: fits_product_lidvid = "urn:nasa:pds:hst_09059:data_acs_raw:j6gp01lzq_raw::2.0" os_filepath = path_to_testfile("j6gp01lzq_raw.fits") populate_database_from_fits_file(self.db, os_filepath, fits_product_lidvid) offsets = get_file_offsets(self.db, fits_product_lidvid) self.assertEqual(4, len(offsets))
def get_card_dicts(suffix: str) -> CARD_SET: fits_product_lidvid = ( f"urn:nasa:pds:hst_13012:data_acs_{suffix}:jbz504eoq_{suffix}::1.0" ) os_filepath = path_to_testfile(f"jbz504eoq_{suffix}.fits") populate_database_from_fits_file(db, os_filepath, fits_product_lidvid) file_basename = basename(os_filepath) return db.get_card_dictionaries(fits_product_lidvid, file_basename)
def make_lidvid(suffix: str) -> Tuple[str, str]: collection_type = get_collection_type(suffix=suffix) fits_product_lidvid = f"urn:nasa:pds:hst_09059:{collection_type}_acs_{suffix}:j6gp01mkq::1.0" self.db.create_fits_product(fits_product_lidvid, collection_lidvid) file_basename = f"j6gp01mkq_{suffix}.fits" os_filepath = path_to_testfile(file_basename) temp_filepath = os.path.join(mast_dir, file_basename) shutil.copyfile(os_filepath, temp_filepath) populate_database_from_fits_file(self.db, temp_filepath, fits_product_lidvid) return (fits_product_lidvid, file_basename)
def test_populate_from_bad_fits_file(self) -> None: fits_product_lidvid = "urn:nasa:pds:hst_09059:data_acs_raw:j6gp02lzq_raw::2.0" os_filepath = path_to_testfile("j6gp02lzq_raw.fits") populate_database_from_fits_file(self.db, os_filepath, fits_product_lidvid) self.assertFalse( self.db.fits_file_exists(basename(os_filepath), fits_product_lidvid)) self.assertTrue( self.db.bad_fits_file_exists(basename(os_filepath), fits_product_lidvid))
def test_get_card_dictionaries(self) -> None: fits_product_lidvid = "urn:nasa:pds:hst_09059:data_acs_raw:j6gp01lzq_raw::2.0" os_filepath = path_to_testfile("j6gp01lzq_raw.fits") populate_database_from_fits_file(self.db, os_filepath, fits_product_lidvid) file_basename = basename(os_filepath) card_dicts = get_card_dictionaries(self.db, fits_product_lidvid, file_basename) self.assertTrue(card_dicts) self.assertEqual(4, len(card_dicts)) self.assertEqual(16, int(card_dicts[0]["BITPIX"]))
def _populate_products(changes_dict: ChangesDict, db: BundleDB, sv_deltas: COWFS) -> None: for lid, (vid, changed) in changes_dict.items(): if lid.is_product_lid(): lidvid = LIDVID.create_from_lid_and_vid(lid, vid) collection_lidvid = changes_dict.parent_lidvid(lidvid) if changed: product_path = lid_to_dirpath(lidvid.lid()) if collection_lidvid.lid().collection_id == "document": db.create_document_product(str(lidvid), str(collection_lidvid)) doc_files = [ doc_file for doc_file in sv_deltas.listdir(product_path) if (fs.path.splitext(doc_file)[1].lower() in DOCUMENT_SUFFIXES) ] for doc_file in doc_files: sys_filepath = sv_deltas.getsyspath( fs.path.join(product_path, doc_file)) db.create_document_file(sys_filepath, doc_file, str(lidvid)) else: db.create_fits_product(str(lidvid), str(collection_lidvid)) fits_files = [ fits_file for fits_file in sv_deltas.listdir(product_path) if fs.path.splitext(fits_file)[1].lower() == ".fits" ] for fits_file in fits_files: fits_file_path = fs.path.join(product_path, fits_file) fits_os_path = sv_deltas.getsyspath(fits_file_path) populate_database_from_fits_file( db, fits_os_path, str(lidvid)) else: if changes_dict.changed(collection_lidvid.lid()): db.create_collection_product_link(str(collection_lidvid), str(lidvid))
def test_populate_from_fits_file(self) -> None: fits_product_lidvid = "urn:nasa:pds:hst_09059:data_acs_raw:j6gp01lzq_raw::2.0" os_filepath = path_to_testfile("j6gp01lzq_raw.fits") populate_database_from_fits_file(self.db, os_filepath, fits_product_lidvid) file_basename = basename(os_filepath) self.assertTrue( self.db.fits_file_exists(file_basename, fits_product_lidvid)) self.assertFalse( self.db.bad_fits_file_exists(file_basename, fits_product_lidvid)) # test that we got some HDUS self.assertTrue( self.db.hdu_exists(0, file_basename, fits_product_lidvid)) # test that we got some cards self.assertTrue(self.db.card_exists("BITPIX", 0, fits_product_lidvid))
def test_get_file_contents(self) -> None: db = create_bundle_db_in_memory() db.create_tables() fits_product_lidvid = "urn:nasa:pds:hst_13012:data_acs_raw:jbz504eoq_raw::2.0" os_filepath = path_to_testfile("jbz504eoq_raw.fits") populate_database_from_fits_file(db, os_filepath, fits_product_lidvid) file_basename = basename(os_filepath) card_dicts = db.get_card_dictionaries(fits_product_lidvid, file_basename) fb = get_file_contents(db, card_dicts, "acs", fits_product_lidvid) doc = _fragment_wrapper({"frag": fb}) str: bytes = doc.toxml().encode() str = pretty_print(str) expected = b"""<?xml version="1.0"?> <Wrapper> <Header> <local_identifier>hdu_0</local_identifier> <offset unit="byte">0</offset> <object_length unit="byte">14400</object_length> <parsing_standard_id>FITS 3.0</parsing_standard_id> <description>Global FITS Header</description> </Header> <Header> <local_identifier>hdu_1</local_identifier> <offset unit="byte">14400</offset> <object_length unit="byte">8640</object_length> <parsing_standard_id>FITS 3.0</parsing_standard_id> <description>FITS Header</description> </Header> <Array_2D_Image> <offset unit="byte">23040</offset> <axes>2</axes> <axis_index_order>Last Index Fastest</axis_index_order> <Element_Array> <data_type>SignedMSB2</data_type> </Element_Array> <Axis_Array> <axis_name>Line</axis_name> <elements>1024</elements> <sequence_number>1</sequence_number> </Axis_Array> <Axis_Array> <axis_name>Sample</axis_name> <elements>1024</elements> <sequence_number>2</sequence_number> </Axis_Array> </Array_2D_Image> <Header> <local_identifier>hdu_2</local_identifier> <offset unit="byte">2122560</offset> <object_length unit="byte">5760</object_length> <parsing_standard_id>FITS 3.0</parsing_standard_id> <description>FITS Header</description> </Header> <Header> <local_identifier>hdu_3</local_identifier> <offset unit="byte">2128320</offset> <object_length unit="byte">5760</object_length> <parsing_standard_id>FITS 3.0</parsing_standard_id> <description>FITS Header</description> </Header> </Wrapper> """ self.assertEqual(expected, str)