You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original MATLAB source code found at: https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/getCcsdsTimeFormat.m
6
-
The CCSDS time format is required to be of the general form
7
-
yyyy-[mm-dd|ddd]THH:MM:SS[.F*][Z]
8
-
(1) The date and time fields are separated by a "T".
9
-
(2) The date field has a four digit year followed by either a two digit
10
-
month and two digit day, or a three digit day-of-year.
11
-
(3) The year, month, day, and day-of-year fields are separated by a dash.
12
-
(4) The hours, minutes and seconds fields are each two digits separated
13
-
by colons.
14
-
(5) The fraction of seconds is optional and can have any number of
15
-
digits.
16
-
(6) If a fraction of seconds is provided, it is separated from the two
17
-
digit seconds by a period.
18
-
(7) The time string can end with an optional "Z" time zone indicator
19
-
'''
20
-
timeFormat= []
21
-
numT=timeString.count('T')
22
-
ifnumT==-1:
23
-
# Case when this is 'T' does not exist in timeString
24
-
print(f"*** Error -- Invalid CCSDS time string: {timeString}")
25
-
print(f" No 'T' separator found between date and time portions of the string\n")
26
-
return
27
-
elifnumT>1:
28
-
print(f"*** Error -- Invalid CCSDS time string: {timeString}\n")
29
-
print(f" More than one 'T' separator found between date and time portions of the string\n")
30
-
return
31
-
idxT=timeString.find('T')
32
-
ifidxT==10:
33
-
timeFormat="yyyy-mm-ddTHH:MM:SS"
34
-
elifidxT==8:
35
-
timeFormat="yyyy-DDDTHH:MM:SS"
36
-
else:
37
-
print(f"*** Error -- Invalid CCSDS time string: {timeString}\n", timeString)
38
-
print(f" Date format not one of yyyy-mm-dd or yyyy-DDD\n")
39
-
return
40
-
# % Check if 'Z' time zone indicator appended to the string
41
-
iftimeString[-1]=='Z':
42
-
zOpt=True
43
-
else:
44
-
zOpt=False
45
-
# % Find location of the fraction of seconds decimal separator
46
-
numDecimal=timeString.count('.')
47
-
ifnumDecimal>1:
48
-
print(f"*** Error -- Invalid CCSDS time string: {timeString}\n")
49
-
print(f" More than one fraction of seconds decimal separator ('.') found.\n")
50
-
timeFormat= []
51
-
return
52
-
idxDecimal=timeString.find('.')
53
-
nfrac=0
54
-
ifnumDecimal!=0:
55
-
ifzOpt:
56
-
nfrac=len(timeString) -1-idxDecimal-1
57
-
else:
58
-
nfrac=len(timeString) -1-idxDecimal
59
-
ifnfrac>0:
60
-
fracStr='.'+ ('F'*nfrac)
61
-
else:
62
-
fracStr=""
63
-
ifzOpt:
64
-
fracStr=fracStr+'Z'
65
-
timeFormat=timeFormat+fracStr
66
-
returntimeFormat
67
-
68
-
defDOY2Date(DOY, YEAR):
69
-
'''
70
-
Written by Andrew Ng, 18/03/2022,
71
-
Based on source code @ https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/DOY2Date.m
72
-
Use the datetime python package.
73
-
DOY2DATE - Converts Day of Year (DOY) to date number and full
Original MATLAB source code found at: https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/getCcsdsTimeFormat.m
356
+
The CCSDS time format is required to be of the general form
357
+
yyyy-[mm-dd|ddd]THH:MM:SS[.F*][Z]
358
+
(1) The date and time fields are separated by a "T".
359
+
(2) The date field has a four digit year followed by either a two digit
360
+
month and two digit day, or a three digit day-of-year.
361
+
(3) The year, month, day, and day-of-year fields are separated by a dash.
362
+
(4) The hours, minutes and seconds fields are each two digits separated
363
+
by colons.
364
+
(5) The fraction of seconds is optional and can have any number of
365
+
digits.
366
+
(6) If a fraction of seconds is provided, it is separated from the two
367
+
digit seconds by a period.
368
+
(7) The time string can end with an optional "Z" time zone indicator
369
+
370
+
Args:
371
+
- time)
372
+
'''
373
+
time_format= []
374
+
numT=time_string.count('T')
375
+
ifnumT==-1:
376
+
# Case when this is 'T' does not exist in time_string
377
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nNo 'T' separator found between date and time portions of the string")
378
+
elifnumT>1:
379
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nMore than one 'T' separator found between date and time portions of the string")
380
+
idx_T=time_string.find('T')
381
+
ifidx_T==10:
382
+
time_format="yyyy-mm-ddTHH:MM:SS"
383
+
elifidx_T==8:
384
+
time_format="yyyy-DDDTHH:MM:SS"
385
+
else:
386
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nDate format not one of yyyy-mm-dd or yyyy-DDD.\n")
387
+
# % Check if 'Z' time zone indicator appended to the string
388
+
iftime_string[-1]=='Z':
389
+
zOpt=True
390
+
else:
391
+
zOpt=False
392
+
# % Find location of the fraction of seconds decimal separator
393
+
num_decimal=time_string.count('.')
394
+
ifnum_decimal>1:
395
+
#time_format = []
396
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nMore than one fraction of seconds decimal separator ('.') found.\n")
397
+
idx_decimal=time_string.find('.')
398
+
nfrac=0
399
+
ifnum_decimal!=0:
400
+
ifzOpt:
401
+
nfrac=len(time_string) -1-idx_decimal-1
402
+
else:
403
+
nfrac=len(time_string) -1-idx_decimal
404
+
ifnfrac>0:
405
+
frac_str='.'+ ('F'*nfrac)
406
+
else:
407
+
frac_str=""
408
+
ifzOpt:
409
+
frac_str=frac_str+'Z'
410
+
time_format=time_format+frac_str
411
+
returntime_format
412
+
413
+
defDOY2Date(value,DOY, YEAR, idx):
414
+
'''
415
+
Written by Andrew Ng, 18/03/2022,
416
+
Based on source code @ https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/DOY2Date.m
417
+
Use the datetime python package.
418
+
DOY2DATE - Converts Day of Year (DOY) date format to date format.
419
+
420
+
Args:
421
+
- value(``str``): Original date time string with day of year format "YYYY-DDDTHH:MM:SS.ff"
422
+
- DOY (``str``): The day of year in the DOY format.
423
+
- YEAR (``str``): The year.
424
+
- idx (``int``): Index of the start of the original "value" string at which characters 'DDD' are found.
425
+
Returns:
426
+
-value (``str``): Transformed date in traditional date format. i.e.: "YYYY-mm-ddTHH:MM:SS.ff"
0 commit comments