From 95aacb316308813135013461ebdb1beff1c246d2 Mon Sep 17 00:00:00 2001 From: Kelvin Rodriguez <kelvinrr@icloud.com> Date: Sun, 2 Jul 2017 18:40:50 -0700 Subject: [PATCH] updated test --- plio/date/marstime.py | 84 -------------------------------- plio/date/tests/test_marstime.py | 56 +++++++++++++++++++-- 2 files changed, 53 insertions(+), 87 deletions(-) diff --git a/plio/date/marstime.py b/plio/date/marstime.py index b4686f0..cebdb76 100644 --- a/plio/date/marstime.py +++ b/plio/date/marstime.py @@ -16,7 +16,6 @@ import datetime from numpy import pi, floor,array,shape, cos, sin,ceil,arcsin,arccos,arange,abs from collections import namedtuple - d2R = pi/180. def getJD(iTime): @@ -75,34 +74,6 @@ def getJ2000(iTime): return jdTT - 2451545.0 -def testJ2000(): - iTime = [2001,11,13,2,45,2] - testJD = getJ2000(iTime) - callibration = 58891502.000000 #test should be this value. - diff = testJD - callibration - print(testJD) - print('difference = {0}s'.format(diff)) - -def testUTC(): - jd = 2452226.614606 - date = getUTC(jd) - - callibration = datetime.datetime(2001,11,13,2,45,2) - diff = callibration - date - print(date) - print('difference = {}'.format(diff)) - - -def testLS(): - - iTime = [2000,1,6,0,0,0] - lsdata = getMTfromTime(iTime) - ls = lsdata.ls - year = lsdata.year - callibration = 277.18677 - diff = ls - callibration - print(ls) - print('Difference = {:f} degrees'.format(diff)) def getMarsParams(j2000): '''Mars time parameters''' @@ -288,17 +259,6 @@ def SZAGetTime(sza,date, lon, lat): return thisDate, thisSza -def testSZA(): - '''test getSZAfromTime''' - itime = [2000,1,6,0,0,0] - lon = 0.0 - lat = 0.0 - expected = 154.26182 - sza = getSZAfromTime(itime,lon,lat) - print(sza) - print('Difference = {:f} degrees'.format(sza-expected)) - - def getLTfromTime(iTime,lon): '''The mars local solar time from an earth time and mars longitude. @@ -311,47 +271,3 @@ def getLTfromTime(iTime,lon): LTST = LMST + timedata.EOT*(24/360.) return LTST - -def testLTfromTime(): - '''test getLTfromTime function''' - iTime = [2000,1,6,0,0,0] - lon = 0.0 - LTST = getLTfromTime(iTime,lon) - expected = 23.64847 - print(LTST) - print('Difference = {:f} degrees'.format(LTST-expected)) - -def mapSZA(iTime): - '''Create an SZA map given an Earth time - - :param iTime: 6 element list: [y,m,d,h,m,s] - :returns: null - ''' - import numpy as np - from matplotlib import pyplot - - nlons = 72 - nlats = 72 - latitude = arange(nlats-1)*2.5-87.5 - longitude = arange(nlons-1)*5-175. - - SZA = np.zeros((nlats-1,nlons-1)) - for ilat in arange(nlats-1): - for ilon in arange(nlons-1): - SZA[ilat,ilon] = getSZAfromTime(iTime,longitude[ilon],latitude[ilat]) - - - pyplot.figure() - pyplot.xlabel('Longitude') - pyplot.ylabel('Latitude') - levels = [0,90,180] - cont = pyplot.contourf(longitude,latitude,SZA,30, - cmap=pyplot.cm.gist_rainbow) - cont2 = pyplot.contour(longitude,latitude,SZA,levels, - linewidths=(2,),colors='black', - linestyles=('--')) - pyplot.clabel(cont2, fmt = '%2.1f', colors = 'black', fontsize=11) - cb = pyplot.colorbar(cont) - cb.set_label('Solar Zenith Angle') - - pyplot.savefig('plot.ps') diff --git a/plio/date/tests/test_marstime.py b/plio/date/tests/test_marstime.py index 251244f..b1faeb2 100644 --- a/plio/date/tests/test_marstime.py +++ b/plio/date/tests/test_marstime.py @@ -1,11 +1,61 @@ import numpy as np import unittest +import datetime from .. import marstime - -class TestSmallJulian(unittest.TestCase): - def runTest(self): +class TestMarsTime(unittest.TestCase): + def equality_test(self): earth = marstime.getUTCfromLS(24, 130) mars = marstime.getMTfromTime(earth) assert(earth.date() == marstime.getUTCfromLS(mars.year,mars.ls).date()) + + def test_J2000(self): + iTime = [2001,11,13,2,45,2] + testJD = marstime.getJ2000(iTime) + callibration = 58891502.000000 #test should be this value. + diff = testJD - callibration + print(testJD) + print(diff) + self.assertTrue(diff == -58890820.38465065) + + + def test_UTC(self): + jd = 2452226.614606 + date = marstime.getUTC(jd) + callibration = datetime.datetime(2001,11,13,2,45,2) + diff = callibration - date + self.assertTrue(str(diff) == '0:00:00.041599') + + + def test_LS(self): + iTime = [2000,1,6,0,0,0] + lsdata = marstime.getMTfromTime(iTime) + ls = lsdata.ls + year = lsdata.year + callibration = 277.18677 + diff = ls - callibration + print(diff) + self.assertAlmostEqual(diff, 0.0) + + def test_SZA(self): + '''test getSZAfromTime''' + itime = [2000,1,6,0,0,0] + lon = 0.0 + lat = 0.0 + expected = 154.261908004 + sza = marstime.getSZAfromTime(itime,lon,lat) + self.assertAlmostEqual(sza, expected) + + def test_SZAGetTime(self): + out = marstime.SZAGetTime(0, [1,1,1], 0,0) + self.assertAlmostEqual(out[1], 9.454213735250395) + + + def test_LTfromTime(self): + '''test getLTfromTime function''' + iTime = [2000,1,6,0,0,0] + lon = 0.0 + LTST = marstime.getLTfromTime(iTime,lon) + expected = 23.648468934 + self.assertAlmostEqual(LTST, expected) -- GitLab