def test_different_keyword_values_with_duplicate(self): ha = Header([('A', 1), ('B', 2), ('C', 3)]) hb = ha.copy() ha.append(('C', 4)) hb.append(('C', 5)) diff = HeaderDiff(ha, hb) assert not diff.identical assert diff.diff_keyword_values == {'C': [None, (4, 5)]}
def test_asymmetric_duplicate_keywords(self): ha = Header([('A', 1), ('B', 2), ('C', 3)]) hb = ha.copy() ha.append(('A', 2, 'comment 1')) ha.append(('A', 3, 'comment 2')) hb.append(('B', 4, 'comment 3')) hb.append(('C', 5, 'comment 4')) diff = HeaderDiff(ha, hb) assert not diff.identical assert diff.diff_keyword_values == {} assert (diff.diff_duplicate_keywords == {'A': (3, 1), 'B': (1, 2), 'C': (1, 2)}) report = diff.report() assert ("Inconsistent duplicates of keyword 'A' :\n" " Occurs 3 time(s) in a, 1 times in (b)") in report
def add_fffits_metadata(ff_filename, config, platepars_recalibrated, fallback_platepar): """ Add FITS metadata and WCS to FF files generated by RMS Args: ff_filename (str): full or relative path to FF file config (RMS.Config): config instance platepars_recalibrated (dict): dictionary with recalibrated platepars fallback_platepar (RMS.Platepar): platepar with fitted stars Returns: None """ ff_basename = os.path.basename(ff_filename) platepar_recalibrated = Platepar() try: platepar_data = platepars_recalibrated[ff_basename] with open("platepar_tmp.cal", "w") as f: json.dump(platepar_data, f) platepar_recalibrated.read("platepar_tmp.cal") except (FileNotFoundError, KeyError): platepar_recalibrated = fallback_platepar logger.warning(f"Using non-recalibrated platepar for {ff_basename}") fftime = getMiddleTimeFF(ff_basename, config.fps) fit_xy = np.array(fallback_platepar.star_list)[:, 1:3] _, fit_ra, fit_dec, _ = xyToRaDecPP([fftime] * len(fit_xy), fit_xy[:, 0], fit_xy[:, 1], [1] * len(fit_xy), platepar_recalibrated, extinction_correction=False) x0 = platepar_recalibrated.X_res / 2 y0 = platepar_recalibrated.Y_res / 2 _, ra0, dec0, _ = xyToRaDecPP([fftime], [x0], [y0], [1], platepar_recalibrated, extinction_correction=False) w = fit_wcs(fit_xy[:, 0], fit_xy[:, 1], fit_ra, fit_dec, x0, y0, ra0[0], dec0[0], 5, projection="ZEA") hdu_list = fits.open(ff_filename, scale_back=True) obstime = Time(filenameToDatetime(ff_basename)) header_meta = {} header_meta["OBSERVER"] = config.stationID.strip() header_meta["INSTRUME"] = "Global Meteor Network" header_meta["MJD-OBS"] = obstime.mjd header_meta["DATE-OBS"] = obstime.fits header_meta["NFRAMES"] = 256 header_meta["EXPTIME"] = 256 / config.fps header_meta["SITELONG"] = round(config.longitude, 2) header_meta["SITELAT"] = round(config.latitude, 2) for hdu in hdu_list: if hdu.header[ "NAXIS"] == 0: # First header is not an image so should not get WCS new_header = Header() else: new_header = w.to_fits(relax=True)[0].header for key, value in header_meta.items(): new_header.append((key, value)) for key, value in new_header.items(): if key in hdu.header: continue hdu.header[key] = value hdu_list.writeto(ff_filename, overwrite=True)