coord_correction_ml.py 1.55 KB
Newer Older
1
2
3
4
5
6
import re
from pathlib import Path

import joblib
import numpy as np

7
_coord_model_path = Path(__file__).parent / 'gris_coordinate_study' / 'multi_tree_stdx38_stdy36.gz'
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
_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

    """
23
    features = ['SLITPOSX', 'SLITPOSY', 'AZIMUT']
24
    vals = [gris_fitsfile.header[f] for f in features]
25
    vals.append(gris_fitsfile.p0_angle)
26
27
28
29
30
31
32

    # 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)

    # Insert Zenit
    vals.insert(4, gris_fitsfile.zenit)
33
34
35
36
37

    # Insert date parameters
    date = gris_fitsfile.obs_time
    day_of_year = date.timetuple().tm_yday
    vals.append(day_of_year)
38
    vals.append(date.year)
39
    x, y = _coord_model.predict(np.array(vals).reshape(-1, 1).T)[0]
40
    return x, y, coord_model_stdx, coord_model_stdy