Commit 3dde378c authored by Carl Schaffer's avatar Carl Schaffer
Browse files

moving coord correction via ml to dedicated module, adding uncertainties

parent fdca9e79
import re
from pathlib import Path
import joblib
import numpy as np
_coord_model_path = Path(__file__).parent.parent / 'gris_coordinate_study' / 'multi_tree_stdx38_stdy36.gz'
_coord_model = joblib.load(_coord_model_path)
coord_model_stdx, coord_model_stdy = (int(i) for i in
re.search(r'stdx(\d+)_stdy(\d+)', _coord_model_path.name).groups())
def get_coords_ml(gris_fitsfile):
"""
Determine the coordinates of the observation from a pre-trained statistical model.
The model was trained trained and evaluated against a dataset of original data and
results of a manual cross correlation with hmi. Albeit not being totally accurate,
the model has been shown to systematically reduce the distance between the given
and the actual coordinates. The typical accuracy (stdev) is around 40"
Returns: x,y tuple of the estimated observation center in Helioprojective Coordinates
"""
features = ['SLITPOSX', 'SLITPOSY', 'AZIMUT', 'P0ANGLE']
vals = [gris_fitsfile.header[f] for f in features]
# Insert bogus parallax angle, it is 0 for all cases I observed
# so far anyway plus is not used very strongly by the model
vals.insert(2, 0)
date = gris_fitsfile.obs_time
# Insert Zenit
vals.insert(4, gris_fitsfile.zenit)
vals.append(date.day_of_year)
vals.append(date.year)
x, y = _coord_model.predict(np.array(vals).reshape(-1, 1).T)
return x, y, coord_model_stdx, coord_model_stdy
......@@ -3,22 +3,15 @@ import re
from glob import glob
from math import isnan
from os.path import exists, join
from pathlib import Path
import joblib
import numpy as np
from astropy.io.fits import Card
from pandas import to_datetime
from scipy.io.idl import readsav
from kis_tools.gris.GrisFitsFile import GrisFitsFile
from kis_tools.gris.headers.template_builder import HEADER_TEMPLATE
from kis_tools.util.calculations import rotate_around_first_coord
_coord_model_path = Path(__file__).parent.parent / 'gris_coordinate_study' / 'multi_tree_stdx38_stdy36.gz'
_coord_model = joblib.load(_coord_model_path)
_coord_model_stdx, _coord_model_stdy = (int(i) for i in
re.search(r'stdx(\d+)_stdy(\d+)', _coord_model_path.name).groups())
class GrisWCSGenerator(object):
def __init__(self, fits_file, cross_correlation_file=None):
......@@ -62,30 +55,8 @@ class GrisWCSGenerator(object):
else:
self.coords = self.get_coords_from_header()
def get_coords_ml(self):
"""
Determine the coordinates of the observation from a pre-trained statistical model.
The model was trained trained and evaluated against a dataset of original data and
results of a manual cross correlation with hmi. Albeit not being totally accurate,
the model has been shown to systematically reduce the distance between the given
and the actual coordinates. The typical accuracy (stdev) is around 40"
Returns: x,y tuple of the estimated observation center in Helioprojective Coordinates
"""
features = ['SLITPOSX', 'SLITPOSY', 'AZIMUT', 'P0ANGLE']
vals = [self.infile.header[f] for f in features]
# Insert bogus parallax angle, it is 0 for all cases I observed
# so far anyway plus is not used very strongly by the model
vals.insert(2, 0)
date = to_datetime(self.infile['DATE-OBS'] + self.infile['UT'])
# Insert Zenit
vals.insert(4, 90 - self.infile.header['ELEVATIO'])
vals.append(date.day_of_year)
vals.append(date.year)
x, y = _coord_model.predict(np.array(vals).reshape(-1, 1).T)
return x, y
def get_coords_from_header(self):
"""coordinates for slit, the Keywords 'SLITPOSX' and 'SLITPOSY' are assumed to be the center of the slit
......@@ -98,6 +69,7 @@ class GrisWCSGenerator(object):
"""
coords = self.infile.coords.value
self.coord_uncertainties = self.infile.coord_uncertainty
return coords[:, 0], coords[:, 1]
def get_coords_from_save(self):
......@@ -225,8 +197,8 @@ class GrisWCSGenerator(object):
# Uncertainties estimated from difference between cross correlated coordinates and coordinates
# from the telescope. They showed a significantly larger uncertainty for the Y coordinate. See documentation of
# https://gitlab.leibniz-kis.de/sdc/sdc_importer/issues/199
spatial_uncertainty_x = 5 if has_ccorr else 141
spatial_uncertainty_y = 5 if has_ccorr else 186
spatial_uncertainty_x = 5 if has_ccorr else self.coord_uncertainties[0]
spatial_uncertainty_y = 5 if has_ccorr else self.coord_uncertainties[1]
c_syer = [
spatial_uncertainty_x,
spatial_uncertainty_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