# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Demonstration of anticipated end-to-end usage of Orbit PreCalculations for "Checking"
#  - This is the expected usage to use stored cheby polynomials (& nightly-healpix) from the database to perform various "checking" functions
#  
#  - At present (20200618) this is incomplete and intended as a schematic to aid development

# #### Basic imports ...

# +
import time
import numpy as np
import scipy.stats as stats
import math
import random
from collections import defaultdict
import os
import sys
from collections import Counter
import glob 
import warnings
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import importlib
from astropy.time import Time
import pickle


# -------------------------------------------------------------------------------------
# Local imports
# -------------------------------------------------------------------------------------

# orbit_cheby & nbody_reader imports 
#sys.path.append( "/Users/matthewjohnpayne/Envs/orbit_cheby/orbit_cheby/" )
from orbit_cheby import orbit_cheby
from orbit_cheby import nbody_reader
importlib.reload(orbit_cheby)
importlib.reload(nbody_reader)

# obs_pos import(s) 
from orbit_cheby import obs_pos
importlib.reload(obs_pos)

# sql import(s) 
from orbit_cheby import sql
importlib.reload(sql)

# PreCalc import(s) 
from orbit_cheby import precalc
importlib.reload(precalc)

# 
from mpchecker2 import Check
importlib.reload(precalc)


# -

# ## Ephemeris Call
#  - How to get the position, etc, for a known, named object 
#  - Allow Ephem to take obsCode or observatoryXYZ @ each of the times

# +
# Declare the Ephem object: will populate MSC(s)
Eph = ephem.Ephem(designations, times, obsCode = 'F51')

# Get the sky-plane positions and uncertainties
# (other methods could/should be created to return, e.g., heliocentric coords)
Eph.generate_sky_predictions()
# -

# ## Position Check
#  - How to get residuals (and their significance) between input observations and a named, known object

Check().posn_check(primary_unpacked_provisional_designation,  detections )


# ## MPChecker 
#  - How to get objects "close to" a pointing

Check.mpchecker( pointings_object )

# ## CheckID 
#  - How to get the identity of unnamed observations (i.e. whether they are consistent with any named, known object(s))

Check.checkid( detections )

# ## CheckIDX
#  - Extending CheckID to allow for objects with highly uncertain mean-anomalies

Check.checkidX( detections )

StarcoderdataJupyterScriptsDedupFiltered