Skip to content

Commit

Permalink
Merge pull request #17 from moeyensj/gauss
Browse files Browse the repository at this point in the history
Initial Orbit Determination
  • Loading branch information
moeyensj authored Dec 28, 2019
2 parents 119ad1a + 68d1f0b commit edaa3d1
Show file tree
Hide file tree
Showing 37 changed files with 1,728 additions and 371 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
numpy
scipy
astropy
astroquery
scikit-learn
matplotlib
seaborn
Expand All @@ -10,6 +11,8 @@ plotly
pyyaml
openorb
ipykernel
numba
spiceypy
pytest
pytest-cov
coveralls
3 changes: 3 additions & 0 deletions requirements_travis.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
numpy
scipy
astropy
astroquery
scikit-learn
matplotlib
seaborn
Expand All @@ -9,6 +10,8 @@ fortranformat
plotly
pyyaml
openorb
numba
spiceypy
pytest
pytest-cov<2.6.0
coveralls
2 changes: 2 additions & 0 deletions thor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .config import *
from .constants import *
from .data_processing import *
from .utils import *
from .io import *
from .orbits import *
from .coordinates import *
Expand Down
35 changes: 35 additions & 0 deletions thor/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
from astropy import units as u
from astropy.constants import codata2014 as c

AU_TO_KM = 6.684587122268446e-09

class Constants:

# Speed of light: AU per day (173.14463267424034)
C = c.c.to(u.au / u.d).value

# Gravitational constant: AU**3 / M_sun / d**2 (0.00029591220819207784)
G = c.G.to(u.AU**3 / u.M_sun / u.d**2).value

# Solar Mass: M_sun (1.0)
M_SUN = 1.0

# Earth Mass: M_sun (3.0034893488507934e-06)
M_EARTH = u.M_earth.to(u.M_sun)

# Earth Equatorial Radius (6378.1363 km (DE431/DE430))
R_EARTH = (6378.1363 * u.km).to(u.AU)

# Mean Obliquity at J2000: radians (0.40909280422232897)
OBLIQUITY = (84381.448 * u.arcsecond).to(u.radian).value

# Transformation matrix from Equatorial J2000 to Ecliptic J2000
TRANSFORM_EQ2EC = np.array([
[1, 0, 0],
[0, np.cos(OBLIQUITY), np.sin(OBLIQUITY)],
[0, -np.sin(OBLIQUITY), np.cos(OBLIQUITY)
]])

# Transformation matrix from Ecliptic J2000 to Equatorial J2000
TRANSFORM_EC2EQ = TRANSFORM_EQ2EC.T
10 changes: 3 additions & 7 deletions thor/coordinates/coordinate_transforms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import numpy as np

OBLIQUITY = np.radians(23.43928)
TRANSFORM_EQ2EC = np.matrix([[1, 0, 0],
[0, np.cos(OBLIQUITY), np.sin(OBLIQUITY)],
[0, -np.sin(OBLIQUITY), np.cos(OBLIQUITY)]])
TRANSFORM_EC2EQ = np.matrix([[1, 0, 0],
[0, np.cos(OBLIQUITY), -np.sin(OBLIQUITY)],
[0, np.sin(OBLIQUITY), np.cos(OBLIQUITY)]])
from ..constants import Constants as c

TRANSFORM_EQ2EC = c.TRANSFORM_EQ2EC
TRANSFORM_EC2EQ = c.TRANSFORM_EC2EQ

__all__ = ["equatorialToEclipticCartesian",
"eclipticToEquatorialCartesian",
Expand Down
2 changes: 1 addition & 1 deletion thor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .config import Config
from .cell import Cell
from .particle import TestParticle
from .orbits import propagateOrbits
from .orbits.propagate import propagateOrbits
from .data_processing import findExposureTimes
from .data_processing import grabLinkedDetections
from .plotting import plotOrbitsFindable
Expand Down
1 change: 1 addition & 0 deletions thor/observatories/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .codes import *
26 changes: 26 additions & 0 deletions thor/observatories/codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from ..utils import _downloadFile

__all__ = [
"getMPCObsCodeFile",
]

def getMPCObsCodeFile():
"""
Downloads the MPC Observatory Codes file. Checks if a newer version of the file exists online, if so,
replaces the previously downloaded file if available.
Parameters
----------
None
Returns
-------
None
"""
obscodes = os.path.join(os.path.dirname(__file__), "data/ObsCodes.html")
url = 'https://www.minorplanetcenter.net/iau/lists/ObsCodes.html'
_downloadFile(obscodes, url, update=True)
return

Empty file.
Empty file.
48 changes: 48 additions & 0 deletions thor/observatories/tests/test_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import filecmp
import shutil

from ..codes import getMPCObsCodeFile

def test_getMPCOBSCodeFile():
# Define some file paths, we expect only obscodes and obscodes_old to be affected
# by any function call to getMPCObsCodeFile
obscodes = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data/ObsCodes.html"))
obscodes_backup = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data/ObsCodes_backup.html"))
obscodes_test = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data/.ObsCodes_test.html"))
obscodes_old = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data/ObsCodes.html_old"))

getMPCObsCodeFile()

# Lets check the file downloaded
assert os.path.isfile(obscodes)

# Modify the file by removing the last 10 lines
codes = open(obscodes, "r")
lines = codes.readlines()
lines = lines[:-10]
codes.close()

# Write modified file to a new file
testfile = open(obscodes_test, "w")
testfile.writelines(lines)
testfile.close()

# Rename the modified file to the file name expected by getMPCObsCodeFile
# See if the function recognizes the change and as a result downloads the correct file again.
os.rename(obscodes, obscodes_backup)
shutil.copy(obscodes_test, obscodes)

getMPCObsCodeFile()

# Check if newly downloaded file is the same as the unmodified one, check that that modified one has been saved as
# ObsCodes_old.html
# (this will only fail in the unlikely chance that between the tests the MPC updated the MPC Obs Codes file)
assert filecmp.cmp(obscodes, obscodes_backup)
assert filecmp.cmp(obscodes_test, obscodes_old)

# Clean up files
os.remove(obscodes_backup)
os.remove(obscodes_old)
os.remove(obscodes_test)
os.remove(obscodes)
3 changes: 2 additions & 1 deletion thor/orbits/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .pyoorb import *
from .kepler import *
from .propagate import *
4 changes: 3 additions & 1 deletion thor/orbits/iod/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .gauss import *
from .gibbs import *
from .herrick_gibbs import *
from .gauss import *
from .iod import *
Loading

0 comments on commit edaa3d1

Please sign in to comment.