"""Information related to the default static distortion correction and its
inverse.
"""
# Static corrections taken from database files supplied by instrument scientist

# In degrees; these are the RA and DEC for the LMC field
__STATIC_REFERENCE_COORDS__ = {"x": 80.45476667, "y": -69.4999333}

"""
forward: A dictionary specifiying the information related to the default static
transformation of pixel coordinates to projection plane coordinates.
Containing the *linear* and *non-linear* surface fits information
including model definition and coefficients per array per axis.

backward: A dictionary specifying the information related to the inverse of the
default static transformation. Containing only one model type which maps
projection plane coordinates to pixel coordinates. The information includes 
model definition (type, domain, degree) and coefficients per array per
axis. Recomputed by CJS 07/13/2016
"""
STATIC_CORRECTIONS = {
    "forward": [
        # Linear model
        {"model": "Polynomial2D",
         "parameters": [{"x": {"c0_0": -3.767293338535515,
                               "c1_0": 0.01945507134593546,
                               "c0_1": 1.613586631961425E-4},
                         "y": {"c0_0": -47.40723615004112,
                               "c1_0": 1.563299085656958E-4,
                               "c0_1": 0.01971384089214057}},
                        {"x": {"c0_0": -47.77441111281951,
                               "c1_0": 0.02002115791291804,
                               "c0_1": 1.855292799634021E-4},
                         "y": {"c0_0": -47.76547084404991,
                               "c1_0": 1.654311720619638E-4,
                               "c0_1": 0.01971856033820672}},
                        {"x": {"c0_0": -47.41388591702555,
                               "c1_0": 0.02001482028626509,
                               "c0_1": -4.212420569230591E-4},
                         "y": {"c0_0": -4.654717879799149,
                               "c1_0": 2.286060564658466E-4,
                               "c0_1": 0.01969623747326584}},
                        {"x": {"c0_0": -3.608039600938993,
                               "c1_0": 0.01941851868447217,
                               "c0_1": -3.684556341286741E-4},
                         "y": {"c0_0": -4.196595494921446,
                               "c1_0": 1.417908733063215E-4,
                               "c0_1": 0.01969654015724558}}]},
        # Non-linear model
        {"model": "Polynomial2D",
         "parameters": [{"x": {"c0_0": -0.2000441189104647,
                               "c1_0": 2.493979183483538E-4,
                               "c2_0": -1.114794181513601E-7,
                               "c3_0": -4.531542177492621E-12,
                               "c0_1": 3.137509342682636E-4,
                               "c1_1": -2.641687769102021E-8,
                               "c2_1": 4.322499461312955E-12,
                               "c0_2": -1.623821782398624E-7,
                               "c1_2": 7.862705238522332E-12,
                               "c0_3": 8.649900385974039E-12},
                         "y": {"c0_0": -0.01304663181010625,
                               "c1_0": 2.174054284822841E-5,
                               "c2_0": -2.398957087927592E-8,
                               "c3_0": 7.310481620132716E-12,
                               "c0_1": 3.357755871516543E-5,
                               "c1_1": -8.825184536163208E-9,
                               "c2_1": 2.050018792243589E-12,
                               "c0_2": -2.478630823986458E-8,
                               "c1_2": 3.538515044761089E-12,
                               "c0_3": 4.562723271772565E-12}},
                        {"x": {"c0_0": -0.1949408064796304,
                               "c1_0": 2.877778046298606E-4,
                               "c2_0": -1.495360882919546E-7,
                               "c3_0": 5.523962776560459E-12,
                               "c0_1": 2.788514653546706E-4,
                               "c1_1": -1.417656730511652E-8,
                               "c2_1": 2.675437435818343E-12,
                               "c0_2": -1.353132791439666E-7,
                               "c1_2": 1.450848713190932E-12,
                               "c0_3": 4.966560575231940E-13},
                         "y": {"c0_0": -0.01563985104451207,
                               "c1_0": 1.397817242056433E-5,
                               "c2_0": -1.808648145552520E-9,
                               "c3_0": -1.598683318558063E-12,
                               "c0_1": 2.689748894070916E-5,
                               "c1_1": -1.262163320882350E-8,
                               "c2_1": 2.785894821583605E-12,
                               "c0_2": -7.291062769196125E-9,
                               "c1_2": 1.549659955759916E-12,
                               "c0_3": -1.631768127489460E-12}},
                        {"x": {"c0_0": -0.1789405696262646,
                               "c1_0": 2.741129335821148E-4,
                               "c2_0": -1.383254303482762E-7,
                               "c3_0": 3.002958493815011E-12,
                               "c0_1": 2.881098305197146E-4,
                               "c1_1": -2.258908094387217E-8,
                               "c2_1": -2.770570714472721E-12,
                               "c0_2": -1.563286907570526E-7,
                               "c1_2": 1.346663655660389E-11,
                               "c0_3": 5.052396058993053E-12},
                         "y": {"c0_0": -0.004138136556942223,
                               "c1_0": 2.034825825241239E-5,
                               "c2_0": -1.835024363784077E-8,
                               "c3_0": 3.064620164702450E-12,
                               "c0_1": 6.221093565420692E-6,
                               "c1_1": -1.870505456604141E-9,
                               "c2_1": 6.014753488124164E-12,
                               "c0_2": -1.140840726876328E-8,
                               "c1_2": -3.972015599966025E-12,
                               "c0_3": 5.135818314356853E-12}},
                        {"x": {"c0_0": -0.2110028606551117,
                               "c1_0": 2.937980723175633E-4,
                               "c2_0": -1.338927929629734E-7,
                               "c3_0": 3.873703618592271E-12,
                               "c0_1": 2.574191396723302E-4,
                               "c1_1": -2.259108137743001E-10,
                               "c2_1": -1.520549877320857E-13,
                               "c0_2": -1.254406813322947E-7,
                               "c1_2": -2.006490195091191E-12,
                               "c0_3": 1.283023891016379E-12},
                         "y": {"c0_0": -0.02271822870244537,
                               "c1_0": 3.573598058342320E-5,
                               "c2_0": -2.252987979165502E-8,
                               "c3_0": 4.293626327166727E-12,
                               "c0_1": 3.782918002580935E-5,
                               "c1_1": -7.899592934041771E-9,
                               "c2_1": 1.394587801179865E-12,
                               "c0_2": -2.922839126802432E-8,
                               "c1_2": 1.202405561311068E-12,
                               "c0_3": 6.870431670792159E-12}}]
         }],
    "backward": [
        {"model": "Polynomial2D",
         "parameters": [{"y": {"c0_0": 2403.75607932,
                               "c1_0": -0.442554169817,
                               "c2_0": 0.00193363093909,
                               "c3_0": -5.03519444689e-05,
                               "c0_1": 50.735616674,
                               "c0_2": -0.00123584145905,
                               "c0_3": -2.95312059021e-05,
                               "c1_1": -0.00117651461113,
                               "c1_2": -2.22685425613e-05,
                               "c2_1": -1.18721083283e-05},
                         "x": {"c0_0": 185.24987599,
                               "c1_0": 50.8928749348,
                               "c2_0": 0.01355637786,
                               "c3_0": 4.2643505188e-05,
                               "c0_1": 0.396532204298,
                               "c0_2": 0.0129659454566,
                               "c0_3": -5.64243720853e-05,
                               "c1_1": -0.00158153229914,
                               "c1_2": -4.03670841129e-05,
                               "c2_1": -2.96553038264e-05}},
                        {"y": {"c0_0": 2403.7468385,
                               "c1_0": -0.397345375562,
                               "c2_0": 0.000740068091411,
                               "c3_0": 1.07337220481e-05,
                               "c0_1": 50.7957888942,
                               "c0_2": 0.00190940311211,
                               "c0_3": 1.11702692867e-05,
                               "c1_1": -0.00103992845412,
                               "c1_2": -9.64107338319e-06,
                               "c2_1": -1.76568670155e-05},
                         "x": {"c0_0": 2384.627138,
                               "c1_0": 50.7773022266,
                               "c2_0": 0.0138517207909,
                               "c3_0": -2.35564064402e-05,
                               "c0_1": 0.465795789271,
                               "c0_2": 0.0168698181579,
                               "c0_3": -2.28190640835e-06,
                               "c1_1": -0.000522526221909,
                               "c1_2": 2.713672316e-06,
                               "c2_1": -1.49634214644e-05}},
                        {"y": {"c0_0": 209.244013461,
                               "c1_0": -0.564075500052,
                               "c2_0": -0.000713816743078,
                               "c3_0": -1.84821520469e-05,
                               "c0_1": 50.6924044225,
                               "c0_2": 0.00206233933607,
                               "c0_3": -3.32183830858e-05,
                               "c1_1": -0.00335545733688,
                               "c1_2": 2.66373630963e-05,
                               "c2_1": -4.06687359111e-05},
                         "x": {"c0_0": 2384.89536993,
                               "c1_0": 50.8250147375,
                               "c2_0": 0.0154929379084,
                               "c3_0": -8.33443464065e-06,
                               "c0_1": 0.652232615806,
                               "c0_2": 0.0160109941766,
                               "c0_3": -3.52035935106e-05,
                               "c1_1": 0.00375042771351,
                               "c1_2": -7.31892597914e-05,
                               "c2_1": 1.84049016124e-05}},
                        {"y": {"c0_0": 212.167208203,
                               "c1_0": -0.432682600525,
                               "c2_0": 0.00246681986635,
                               "c3_0": -2.85252802328e-05,
                               "c0_1": 50.7023393535,
                               "c0_2": 0.00309407013375,
                               "c0_3": -4.54946850124e-05,
                               "c1_1": 0.000917835761765,
                               "c1_2": -6.78639968058e-06,
                               "c2_1": -1.06802703499e-05},
                         "x": {"c0_0": 195.478389528,
                               "c1_0": 50.8602063005,
                               "c2_0": 0.0173865413651,
                               "c3_0": -1.66286923502e-05,
                               "c0_1": 0.423632757216,
                               "c0_2": 0.0164026000699,
                               "c0_3": -8.14998770372e-06,
                               "c1_1": 0.000183990666387,
                               "c1_2": 2.46558072091e-05,
                               "c2_1": 9.02393047362e-07}}]
         }],
         # These are never used but could all point to the same location?
         "pixel_references": [{"x": 173.7071643271124,
                               "y": 2403.391646719334},
                              {"x": 2363.932792542347,
                               "y": 2402.528473628532},
                              {"x": 2373.332945688426,
                               "y": 208.7789406472366},
                              {"x": 189.8208756078813,
                               "y": 211.6960945378711}]
}

# Static centre of rotation
# Relative to array A4 reference point
CENTER_OF_ROTATION = (-65.44, -75.154)
"""
Dictionary keyed by X, Y stating the relative offset in pixels for the given
key.
"""

# Dictionary mapping date ranges to static corrections
#STATIC_CORRECTIONS_DATE_MAPPING = {(None, None):
#                                   {"model": STATIC_CORRECTIONS,
#                                    "cor_offset": CENTER_OF_ROTATION}}
"""
A dictionary mapping a date range, the key (a tuple of dates, default
currently is None, None) to the appropriate static correction information,
the value, a dictionary keyed by MODEL, INVERSE,
CENTRE_OF_ROTATION_OFFSET. The MODEL and INVERSE values are dictionaries
that contain the coefficients for the defined models for each of the defined
arrays. The CENTRE_OF_ROTATION_OFFSET is a dictionary keyed by X, Y that
refer to the relative offsets to apply to translate everything to the centre
of rotation.
"""
