-
Notifications
You must be signed in to change notification settings - Fork 3
added handling of Roman WCS information #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
perrygreenfield
wants to merge
1
commit into
asdf-format:main
Choose a base branch
from
perrygreenfield:romanwcs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||
| import os | ||||
| import os.path | ||||
| import pathlib | ||||
| import time | ||||
| import numpy as np | ||||
| import tkinter as tk | ||||
| from tkinter import messagebox | ||||
|
|
@@ -122,11 +123,6 @@ def asdf_send_array( | |||
| home directory. | ||||
|
|
||||
| """ | ||||
| dbf = open('xxx.txt', 'w') | ||||
| print(filename, file=dbf) | ||||
| print(DS9TMP, file=dbf) | ||||
| dbf.close() | ||||
|
|
||||
| # Map between NumPy and DS9 storage fields. | ||||
| # | ||||
| # Hack in support for bool values | ||||
|
|
@@ -254,12 +250,10 @@ def parse_filename(filename): | |||
| return | ||||
| if len(apath) == 0: | ||||
| finished = True | ||||
| fd = open('parse.txt','w') | ||||
| fd.close() | ||||
| return fn, alist | ||||
|
|
||||
| def get_asdf_image(asdfpath): | ||||
| print(asdfpath) | ||||
|
|
||||
| retval = parse_filename(asdfpath) | ||||
| if retval is not None: | ||||
| fn, alist = retval | ||||
|
|
@@ -273,7 +267,12 @@ def get_asdf_image(asdfpath): | |||
| return None | ||||
| # Extract the referenced array | ||||
| node = af.tree | ||||
| return extract_asdf_array(node, alist, af) | ||||
| im = extract_asdf_array(node, alist, af) | ||||
| if 'roman' in af.tree: | ||||
| wcs = extract_gwcs(af.tree, af) | ||||
| else: | ||||
| wcs = None | ||||
| return im, wcs | ||||
|
|
||||
| def extract_asdf_array(tree, apath, ctx): | ||||
| """ | ||||
|
|
@@ -306,6 +305,42 @@ def extract_asdf_array(tree, apath, ctx): | |||
| arr = tagged_tree_to_custom_tree(node, ctx)._make_array() | ||||
| return arr | ||||
|
|
||||
| def fixwcs(hdr): | ||||
| """ | ||||
| Put the GWCS generated SIP header in a form that ds9 will accept. | ||||
|
|
||||
| Assumes the argument is an astropy.io.fit Header instance | ||||
| """ | ||||
| delete_list = ['naxis', 'naxis1', 'naxis2', 'sipmxerr'] | ||||
| for keyword in delete_list: | ||||
| del hdr[keyword] | ||||
| hdrstr = str(hdr) | ||||
| # Must strip the END statement out of this | ||||
| endstr = 'END' + 77 * ' ' | ||||
| blankcard = 80 * ' ' | ||||
| hdrstr = hdrstr.replace(endstr, blankcard) | ||||
| return hdrstr | ||||
|
|
||||
| def extract_gwcs(tree, ctx): | ||||
| # def extract_gwcs(tree, ctx): | ||||
| """ | ||||
| This currently only works for roman data | ||||
| """ | ||||
| import sys | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| node = tree | ||||
| apath = (('a', 'roman'), ('a', 'meta'), ('a', 'wcs')) | ||||
| for ptype, value in apath: | ||||
| if ptype == 'a': | ||||
| try: | ||||
| node = node[value] | ||||
| except KeyError: | ||||
| messagebox.showerror("ASDF Path Error", f"Specified ADSF path component '{value}' not in file") | ||||
| return | ||||
| gwcs = node | ||||
| gwcs = tagged_tree_to_custom_tree(gwcs, ctx) | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this |
||||
| fitswcs = gwcs.to_fits_sip(degree=5, max_inv_pix_error=None, npoints=10) | ||||
| return fixwcs(fitswcs) | ||||
|
|
||||
| def callsearch(pathlist, nodeitem, index, ctx, path, min_nelements): | ||||
| spath = path.copy() | ||||
| spath.append(index) | ||||
|
|
@@ -413,25 +448,28 @@ def __init__(self, root): | |||
| self.browse_image_button.config(state=tk.DISABLED) | ||||
|
|
||||
| def load_entry_field(self, event=None): | ||||
|
|
||||
| filepath = self.entry.get() | ||||
| print(filepath) | ||||
| if filepath: | ||||
| self.browse_image_button.config(state=tk.NORMAL) | ||||
| else: | ||||
| self.browse_image_button.config(state=tk.DISABLED) | ||||
| return | ||||
| if ':' in filepath: | ||||
| # print("filename: %s" % filepath) | ||||
| im = get_asdf_image(filepath) | ||||
| im, fitswcs = get_asdf_image(filepath) | ||||
| if im is None: | ||||
| return | ||||
| else: | ||||
| return | ||||
| self.ds9.send_array(im, filepath) | ||||
| wcsfn = str((DS9TMP / "wcs.fits").resolve()) | ||||
| with open(wcsfn, "wb") as fwcs: | ||||
| fwcs.write(bytes(fitswcs, 'utf-8')) | ||||
| self.ds9.set(f"wcs load {wcsfn}") | ||||
|
|
||||
|
|
||||
| def show_filename_help(self): | ||||
| messagebox.showinfo(title="Filename/Image Path Info", message=FILEPATH_DOC) | ||||
|
|
||||
|
|
||||
| def browse_filename(self): | ||||
| filename = filedialog.askopenfilename() | ||||
|
|
@@ -470,7 +508,6 @@ def load_selected_image(self): | |||
| filepath = filepath.split(':')[0] | ||||
| self.entry.delete(0, tk.END) | ||||
| self.entry.insert(0, f"{filepath}:{impath}") | ||||
| print(self.entry.get()) | ||||
| self.imbrow.destroy() | ||||
| self.load_entry_field() | ||||
|
|
||||
|
|
||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the follow-up mission-specific defaults can modify this logic so: