From bea53a57141e78f9381c996c8e4794e9a5077fc3 Mon Sep 17 00:00:00 2001 From: Steffen Hirtle Date: Thu, 29 Dec 2022 14:11:29 +0100 Subject: [PATCH 1/2] Fixed bug which prevented Fits header from being transfered --- src/astroimage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/astroimage.py b/src/astroimage.py index f929eea..85e331d 100644 --- a/src/astroimage.py +++ b/src/astroimage.py @@ -152,7 +152,7 @@ def crop(self, startx, endx, starty, endy): return def update_fits_header(self, original_header, background_mean, app, app_state): - if(self.fits_header is None): + if(original_header is None): self.fits_header = fits.Header() else: self.fits_header = original_header From 324c69e56744a1dc55da175b4f00fbe5d1eb3b3b Mon Sep 17 00:00:00 2001 From: Steffen Hirtle Date: Thu, 29 Dec 2022 16:53:29 +0100 Subject: [PATCH 2/2] Fixed conversion from xisf metadata to fits header and vice versa --- src/astroimage.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/astroimage.py b/src/astroimage.py index 85e331d..68ceb43 100644 --- a/src/astroimage.py +++ b/src/astroimage.py @@ -229,7 +229,9 @@ def update_saturation(self): return def update_xisf_imagedata(self): - for key in self.fits_header.keys(): + unique_keys = list(dict.fromkeys(self.fits_header.keys())) + + for key in unique_keys: if key == "BG-PTS": bg_pts = json.loads(self.fits_header["BG-PTS"]) @@ -237,9 +239,27 @@ def update_xisf_imagedata(self): self.image_metadata["FITSKeywords"]["BG-PTS" + str(i)] = [{"value": bg_pts[i],"comment": ""}] else: - value = str(self.fits_header[key]) - comment = str(self.fits_header.comments[key]) - self.image_metadata["FITSKeywords"][key] = [{"value": value, "comment":comment}] + value = str(self.fits_header[key]).splitlines() + comment = str(self.fits_header.comments[key]).splitlines() + + entry = [] + + for i in range(max(len(comment), len(value))): + value_i = "" + comment_i = "" + + if i < len(comment): + comment_i = comment[i] + if i < len(value): + value_i = value[i] + + entry.append({"value": value_i, "comment": comment_i}) + + if len(entry) == 0: + entry = [{"value": "", "comment": ""}] + + self.image_metadata["FITSKeywords"][key] = entry + def xisf_imagedata_2_fitsheader(self): bg_pts = [] @@ -247,10 +267,11 @@ def xisf_imagedata_2_fitsheader(self): if key.startswith("BG-PTS"): bg_pts.append(json.loads(self.image_metadata["FITSKeywords"][key][0]["value"])) - value = self.image_metadata["FITSKeywords"][key][0]["value"] - comment = self.image_metadata["FITSKeywords"][key][0]["comment"] + for i in range(len(self.image_metadata["FITSKeywords"][key])): + value = self.image_metadata["FITSKeywords"][key][i]["value"] + comment = self.image_metadata["FITSKeywords"][key][i]["comment"] - self.fits_header[key] = (value, comment) + self.fits_header[key] = (value, comment) if len(bg_pts) > 0: self.fits_header["BG-PTS"] = str(bg_pts) \ No newline at end of file