Skip to content

Commit 09b13c0

Browse files
committed
Amended method names to snake case
1 parent 713ad75 commit 09b13c0

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

kessler/cdm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import datetime
1515
import copy
1616
import pandas as pd
17-
from . import time_utils
1817
from . import util
1918

2019

@@ -196,10 +195,10 @@ def set_header(self, key, value):
196195
if key in self._keys_header:
197196
if key in self._keys_with_dates:
198197
# We have a field with a date string as the value. Check if the string is in the format needed by the CCSDS 508.0-B-1 standard
199-
timeFormat = util.getCcsdsTimeFormat(value)
198+
timeFormat = util.get_ccsds_time_format(value)
200199
idx = timeFormat.find('DDD')
201200
if idx!=-1:
202-
value = util.DOY2Date(value, value[idx:idx+3], value[0:4], idx)
201+
value = util.DOY_2_date(value, value[idx:idx+3], value[0:4], idx)
203202
try:
204203
_ = datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%f')
205204
except Exception as e:

kessler/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,11 @@ def progress_bar_end(message=None):
349349
if message is not None:
350350
print(message)
351351

352-
def getCcsdsTimeFormat(time_string):
352+
def get_ccsds_time_format(time_string):
353353
'''
354354
Adapted by Andrew Ng, 18/3/2022.
355355
Original MATLAB source code found at: https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/getCcsdsTimeFormat.m
356+
get_ccsds_time_format - process and outputs the format of the time string extracted from the CDM.
356357
The CCSDS time format is required to be of the general form
357358
yyyy-[mm-dd|ddd]THH:MM:SS[.F*][Z]
358359
(1) The date and time fields are separated by a "T".
@@ -366,9 +367,12 @@ def getCcsdsTimeFormat(time_string):
366367
(6) If a fraction of seconds is provided, it is separated from the two
367368
digit seconds by a period.
368369
(7) The time string can end with an optional "Z" time zone indicator
369-
370+
370371
Args:
371-
- time)
372+
- time_string(``str``): Original time string stored in CDM.
373+
Returns:
374+
- time_format(``str``): Outputs the format of the time string. It must be of the form yyyy-[mm-dd|ddd]THH:MM:SS[.F*][Z], otherwise it is invalid and a RuntimeError is raised.
375+
372376
'''
373377
time_format = []
374378
numT = time_string.count('T')
@@ -410,12 +414,12 @@ def getCcsdsTimeFormat(time_string):
410414
time_format = time_format + frac_str
411415
return time_format
412416

413-
def DOY2Date(value,DOY, YEAR, idx):
417+
def DOY_2_date(value, DOY, YEAR, idx):
414418
'''
415419
Written by Andrew Ng, 18/03/2022,
416420
Based on source code @ https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/DOY2Date.m
417421
Use the datetime python package.
418-
DOY2DATE - Converts Day of Year (DOY) date format to date format.
422+
DOY_2_date - Converts Day of Year (DOY) date format to date format.
419423
420424
Args:
421425
- value(``str``): Original date time string with day of year format "YYYY-DDDTHH:MM:SS.ff"

tests/test_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ def test_from_cartesian_to_rtn_2(self):
112112
self.assertAlmostEqual(np.linalg.norm(state_xyz[0]), np.linalg.norm(state_rtn[0]), places=1)
113113
self.assertAlmostEqual(np.linalg.norm(state_xyz[1]), np.linalg.norm(state_rtn[1]), places=1)
114114

115-
def test_getCcsdsTimeFormat(self):
115+
def test_get_ccsds_time_format(self):
116116
# This test is written by Andrew Ng, 19/03/22. It makes use of example CDMs provided by the NASA CARA
117117
# analysis repo at https://github.com/nasa/CARA_Analysis_Tools/tree/master/two-dimension_Pc/UnitTest/InputFiles.
118118
test_case1 = "2000-01-01T00:00:00.000" #From AlfanoTestCase11.cdm
119119
test_case2 = "2018-229T13:56:33.000" # From DensityDecorrelationTestCaseCDM.txt
120120
test_case1_correct = "yyyy-mm-ddTHH:MM:SS.FFF"
121121
test_case2_correct = "yyyy-DDDTHH:MM:SS.FFF"
122122

123-
self.assertEqual(kessler.util.getCcsdsTimeFormat(test_case1), test_case1_correct)
124-
self.assertEqual(kessler.util.getCcsdsTimeFormat(test_case2), test_case2_correct)
125-
def test_DOY2Date(self):
123+
self.assertEqual(kessler.util.get_ccsds_time_format(test_case1), test_case1_correct)
124+
self.assertEqual(kessler.util.get_ccsds_time_format(test_case2), test_case2_correct)
125+
def test_DOY_2_date(self):
126126
# This test is written by Andrew Ng, 19/03/22. It makes use of example CDMs provided by the NASA CARA
127127
# analysis repo at https://github.com/nasa/CARA_Analysis_Tools/tree/master/two-dimension_Pc/UnitTest/InputFiles.
128128
example1 = "2010-202T12:25:19.000" # From SingleCovTestCase1-4.cdm
@@ -133,6 +133,6 @@ def test_DOY2Date(self):
133133
Year_2= example2[0:4]
134134
test_case1_correct = "2010-7-21T12:25:19.00"
135135
test_case2_correct = "2018-8-17T13:56:33.00"
136-
self.assertEqual(kessler.util.DOY2Date(example1, DOY_1, Year_1, 5), test_case1_correct)
137-
self.assertEqual(kessler.util.DOY2Date(example2, DOY_2, Year_2, 5), test_case2_correct)
136+
self.assertEqual(kessler.util.DOY_2_date(example1, DOY_1, Year_1, 5), test_case1_correct)
137+
self.assertEqual(kessler.util.DOY_2_date(example2, DOY_2, Year_2, 5), test_case2_correct)
138138

0 commit comments

Comments
 (0)