Commit e6dbf882 authored by Carl Schaffer's avatar Carl Schaffer
Browse files

basic IFU header wcs functionality

parent 6517dad5
......@@ -32,7 +32,6 @@ from kis_tools.gris.headers.template_builder import (
hyphenated,
)
from kis_tools.gris.headers.wcs_generators import get_wcs_generator
from kis_tools.gris.headers.wcs_generators.gris import reorder_gris_data
from kis_tools.util.gitinfo import get_git_info
from kis_tools.util.util import (
gen_history_time,
......@@ -182,8 +181,8 @@ def main(infile, outfile=None, wcs_generator=None, **kwargs): # noqa: C901
card = (keyword, value, comment)
return card
for index,row in HEADER_TEMPLATE.iterrows():
keyword, default_value, decimal_digits = row['KEYWORD'],row['fixed_val'],row['decimal_digits']
for index, row in HEADER_TEMPLATE.iterrows():
keyword, default_value, decimal_digits = row['KEYWORD'], row['fixed_val'], row['decimal_digits']
if keyword == "COMMENT":
cards = process_comment(default_value)
card_list += cards
......@@ -235,7 +234,7 @@ def main(infile, outfile=None, wcs_generator=None, **kwargs): # noqa: C901
# create header from card list
header = Header(card_list)
DATA = reorder_gris_data(wcs_generator.infile.data, reverse_axes=True)
DATA = wcs_generator.reordered_data()
f = PrimaryHDU(data=DATA, header=header)
if outfile is not None:
......
import datetime
import re
from glob import glob
from os.path import join, dirname
from os.path import join, dirname, basename
from warnings import warn
import pandas as pd
......@@ -294,7 +294,7 @@ class GrisTranslator(GREGORTranslator):
`True` if the header is recognized by this class. `False`
otherwise.
"""
if not filename.startswith("gris_"):
if not basename(filename).startswith("gris_"):
return False
if "SOLARNET" in header:
......
......@@ -5,3 +5,7 @@ class WCSGenerator(ABC):
@abstractmethod
def make_wcs_cards(self):
"""Generate WCS cards for the underlying file"""
@abstractmethod
def reordered_data(self):
"""Generate WCS cards for the underlying file"""
......@@ -69,7 +69,7 @@ class GrisWCSGenerator(WCSGenerator):
coords = self.infile.coords.value
self.coord_uncertainties = self.infile.coord_uncertainty
return coords[0, :, 0], coords[1, 0, :]
return coords[:, 0], coords[:, 1]
def get_coords_from_save(self):
"""Extract coordinates from cross correlation file. If the scan was performed with an angle of 0 degrees,
......@@ -150,13 +150,37 @@ class GrisWCSGenerator(WCSGenerator):
return cards
def reordered_data(self):
"""
Reorder gris data for easier access
Args:
data: input data array
reverse_axes: reverse the order of axes, necessary if writing the data to a fits file afterwards
Returns:
"""
# add degenerate dimension to depict x and y for spatial coordinate
# change axis order from (y,stokes,x,wave) to (x,y,wave,stokes)
trans_data = np.swapaxes(self.infile.data, 0, 1)
trans_data = np.array([trans_data])
trans_data = np.swapaxes(trans_data, -1, -2)
for i in range(int(len(trans_data.shape) / 2)):
trans_data = np.swapaxes(trans_data, 0 + i, -1 - i)
pass
return trans_data
def make_wcs_cards(self):
"""Generate WCS keywords. The spatial extent is represented by introducing a degenerate axis.
The values specified in the header contain axes of SOLARX and SOLARY rotated to be parallel with
the SOLARX axis. They the also contain a rotation matrix to orient the slit correctly within the
coordinate system. This is necessary to make the specification of the values more intuitive."""
shape = reorder_gris_data(self.data_in).shape
shape = self.reordered_data().T.shape
def get_angle(x, y):
v = np.array([x, y])
......@@ -229,30 +253,6 @@ class GrisWCSGenerator(WCSGenerator):
return cards
def reorder_gris_data(data, reverse_axes=False):
"""
Reorder gris data for easier access
Args:
data: input data array
reverse_axes: reverse the order of axes, necessary if writing the data to a fits file afterwards
Returns:
"""
# add degenerate dimension to depict x and y for spatial coordinate
# change axis order from (y,stokes,x,wave) to (x,y,wave,stokes)
trans_data = np.swapaxes(data, 0, 1)
trans_data = np.array([trans_data])
trans_data = np.swapaxes(trans_data, -1, -2)
if reverse_axes:
for i in range(int(len(trans_data.shape) / 2)):
trans_data = np.swapaxes(trans_data, 0 + i, -1 - i)
pass
return trans_data
class GrisIFUWCSGenerator(GrisWCSGenerator):
......@@ -264,13 +264,41 @@ class GrisIFUWCSGenerator(GrisWCSGenerator):
self.data_in = self.infile.data
self.coords = self.get_coords_from_header()
def get_coords_from_header(self):
"""coordinates for slit, the Keywords 'SLITPOSX' and 'SLITPOSY' are assumed to be the center of the slit
while the keyword 'SLITORIE' describes the rotation of the slit w.r.t. the helioprojective axes. The
algorithm further assumes that each pixel represents a square area with side length of 'STEPSIZE'.
These assumptions are used to calculate the coordinates for the center of each pixel within the data array.
Returns:
(X,Y):ndarray(float) x and y coordinates for each pixel of the slit
"""
coords = self.infile.coords.value
self.coord_uncertainties = self.infile.coord_uncertainty
return coords[0, :, 0], coords[1, 0, :]
def reordered_data(self):
"""
Reorder gris data for easier access
Args:
data: input data array
reverse_axes: reverse the order of axes, necessary if writing the data to a fits file afterwards
Returns:
"""
data = self.infile.data
return data
def make_wcs_cards(self):
"""Generate WCS keywords. The spatial extent is represented by introducing a degenerate axis.
The values specified in the header contain axes of SOLARX and SOLARY rotated to be parallel with
the SOLARX axis. They the also contain a rotation matrix to orient the slit correctly within the
coordinate system. This is necessary to make the specification of the values more intuitive."""
shape = self.data_in.T.shape
shape = self.reordered_data().T.shape
def get_angle(x, y):
v = np.array([x, y])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment