Merge upstream Use location from FITS header if available

spacecruft
Jeff Moe 2022-08-24 19:59:23 -06:00
parent e6c7eec4d4
commit 1d549b6237
2 changed files with 44 additions and 19 deletions

View File

@ -56,8 +56,6 @@ if __name__ == "__main__":
warnings.simplefilter("ignore", AstropyWarning) warnings.simplefilter("ignore", AstropyWarning)
# Observer settings
site_id = cfg.getint("Observer", "cospar")
nstarsmin = cfg.getint("Processing", "nstarsmin") nstarsmin = cfg.getint("Processing", "nstarsmin")
@ -157,7 +155,7 @@ if __name__ == "__main__":
obs = [] obs = []
for t in tracks: for t in tracks:
# Add to observation # Add to observation
obs.append(Observation(ff, t.tmid, t.x0, t.y0, site_id, obs.append(Observation(ff, t.tmid, t.x0, t.y0, ff.site_id,
t.satno, t.cospar, t.catalogname)) t.satno, t.cospar, t.catalogname))
# Write observations # Write observations

View File

@ -307,10 +307,17 @@ class FourFrame:
self.ra0 = None self.ra0 = None
self.dec0 = None self.dec0 = None
self.tracked = False self.tracked = False
self.lat = None
self.lon = None
self.height = None
self.has_location = False
else: else:
# Read FITS file # Read FITS file
hdu = fits.open(fname) hdu = fits.open(fname)
# Read header
header = hdu[0].header
# Read image planes # Read image planes
self.zavg, self.zstd, self.zmax, self.znum = hdu[0].data self.zavg, self.zstd, self.zmax, self.znum = hdu[0].data
@ -319,38 +326,51 @@ class FourFrame:
# Frame properties # Frame properties
self.ny, self.nx = self.zavg.shape self.ny, self.nx = self.zavg.shape
self.nz = hdu[0].header["NFRAMES"] self.nz = header["NFRAMES"]
# Read frame time oselfsets # Read frame time oselfsets
self.dt = np.array([hdu[0].header["DT%04d" % i] for i in range(self.nz)]) self.dt = np.array([header["DT%04d" % i] for i in range(self.nz)])
# Read header # Read header
self.mjd = hdu[0].header["MJD-OBS"] self.mjd = header["MJD-OBS"]
self.nfd = hdu[0].header["DATE-OBS"] self.nfd = header["DATE-OBS"]
self.site_id = hdu[0].header["COSPAR"] self.site_id = header["COSPAR"]
self.observer = hdu[0].header["OBSERVER"] self.observer = header["OBSERVER"]
self.texp = hdu[0].header["EXPTIME"] self.texp = header["EXPTIME"]
self.fname = fname self.fname = fname
self.froot = os.path.splitext(fname)[0] self.froot = os.path.splitext(fname)[0]
# Location info
keys = ["SITELONG", "SITELAT", "ELEVATIO"]
if np.all([key in header for key in keys]):
self.lon = header["SITELONG"]
self.lat = header["SITELAT"]
self.height = header["ELEVATIO"]
self.has_location = True
else:
self.lon = None
self.lat = None
self.height = None
self.has_location = False
# Astrometry keywords # Astrometry keywords
self.crpix = np.array([hdu[0].header["CRPIX1"], hdu[0].header["CRPIX2"]]) self.crpix = np.array([header["CRPIX1"], header["CRPIX2"]])
self.crval = np.array([hdu[0].header["CRVAL1"], hdu[0].header["CRVAL2"]]) self.crval = np.array([header["CRVAL1"], header["CRVAL2"]])
self.cd = np.array( self.cd = np.array(
[ [
[hdu[0].header["CD1_1"], hdu[0].header["CD1_2"]], [hdu[0].header["CD1_1"], hdu[0].header["CD1_2"]],
[hdu[0].header["CD2_1"], hdu[0].header["CD2_2"]], [hdu[0].header["CD2_1"], hdu[0].header["CD2_2"]],
] ]
) )
self.ctype = [hdu[0].header["CTYPE1"], hdu[0].header["CTYPE2"]] self.ctype = [header["CTYPE1"], header["CTYPE2"]]
self.cunit = [hdu[0].header["CUNIT1"], hdu[0].header["CUNIT2"]] self.cunit = [header["CUNIT1"], header["CUNIT2"]]
self.crres = np.array([hdu[0].header["CRRES1"], hdu[0].header["CRRES2"]]) self.crres = np.array([header["CRRES1"], header["CRRES2"]])
self.ra0 = self.crval[0] self.ra0 = self.crval[0]
self.dec0 = self.crval[1] self.dec0 = self.crval[1]
# Check for sidereal tracking # Check for sidereal tracking
try: try:
self.tracked = bool(hdu[0].header["TRACKED"]) self.tracked = bool(header["TRACKED"])
except KeyError: except KeyError:
self.tracked = False self.tracked = False
@ -392,9 +412,16 @@ class FourFrame:
nmjd = int(np.ceil(texp)) nmjd = int(np.ceil(texp))
ra0, de0 = self.crval[0], self.crval[1] ra0, de0 = self.crval[0], self.crval[1]
radius = np.sqrt(self.wx * self.wx + self.wy * self.wy) radius = np.sqrt(self.wx * self.wx + self.wy * self.wy)
lat = cfg.getfloat("Observer", "latitude")
lon = cfg.getfloat("Observer", "longitude") # Use FITS location if available, config otherwise
height = cfg.getfloat("Observer", "height") if self.has_location:
lat = self.lat
lon = self.lon
height = self.height
else:
lat = cfg.getfloat("Observer", "latitude")
lon = cfg.getfloat("Observer", "longitude")
height = cfg.getfloat("Observer", "height")
# Format command # Format command
command = f"satpredict -t {nfd} -l {texp} -n {nmjd} -L {lon} -B {lat} -H {height}" command = f"satpredict -t {nfd} -l {texp} -n {nmjd} -L {lon} -B {lat} -H {height}"