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
357
+
get_ccsds_time_format - process and outputs the format of the time string extracted from the CDM.
358
+
The CCSDS time format is required to be of the general form
359
+
yyyy-[mm-dd|ddd]THH:MM:SS[.F*][Z]
360
+
(1) The date and time fields are separated by a "T".
361
+
(2) The date field has a four digit year followed by either a two digit
362
+
month and two digit day, or a three digit day-of-year.
363
+
(3) The year, month, day, and day-of-year fields are separated by a dash.
364
+
(4) The hours, minutes and seconds fields are each two digits separated
365
+
by colons.
366
+
(5) The fraction of seconds is optional and can have any number of
367
+
digits.
368
+
(6) If a fraction of seconds is provided, it is separated from the two
369
+
digit seconds by a period.
370
+
(7) The time string can end with an optional "Z" time zone indicator
371
+
372
+
Args:
373
+
- time_string(``str``): Original time string stored in CDM.
374
+
Returns:
375
+
- 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.
376
+
377
+
'''
378
+
time_format= []
379
+
numT=time_string.count('T')
380
+
ifnumT==-1:
381
+
# Case when this is 'T' does not exist in time_string
382
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nNo 'T' separator found between date and time portions of the string")
383
+
elifnumT>1:
384
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nMore than one 'T' separator found between date and time portions of the string")
385
+
idx_T=time_string.find('T')
386
+
ifidx_T==10:
387
+
time_format="yyyy-mm-ddTHH:MM:SS"
388
+
elifidx_T==8:
389
+
time_format="yyyy-DDDTHH:MM:SS"
390
+
else:
391
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nDate format not one of yyyy-mm-dd or yyyy-DDD.\n")
392
+
# % Check if 'Z' time zone indicator appended to the string
393
+
iftime_string[-1]=='Z':
394
+
z_opt=True
395
+
else:
396
+
z_opt=False
397
+
# % Find location of the fraction of seconds decimal separator
398
+
num_decimal=time_string.count('.')
399
+
ifnum_decimal>1:
400
+
#time_format = []
401
+
raiseRuntimeError(f"*** Error -- Invalid CCSDS time string: {time_string}\nMore than one fraction of seconds decimal separator ('.') found.\n")
402
+
idx_decimal=time_string.find('.')
403
+
nfrac=0
404
+
ifnum_decimal!=0:
405
+
ifz_opt:
406
+
nfrac=len(time_string) -1-idx_decimal-1
407
+
else:
408
+
nfrac=len(time_string) -1-idx_decimal
409
+
ifnfrac>0:
410
+
frac_str='.'+ ('F'*nfrac)
411
+
else:
412
+
frac_str=""
413
+
ifz_opt:
414
+
frac_str=frac_str+'Z'
415
+
time_format=time_format+frac_str
416
+
returntime_format
417
+
418
+
defdoy_2_date(value, doy, year, idx):
419
+
'''
420
+
Written by Andrew Ng, 18/03/2022,
421
+
Based on source code @ https://github.com/nasa/CARA_Analysis_Tools/blob/master/two-dimension_Pc/Main/TransformationCode/TimeTransformations/DOY2Date.m
422
+
Use the datetime python package.
423
+
doy_2_date - Converts Day of Year (DOY) date format to date format.
424
+
425
+
Args:
426
+
- value(``str``): Original date time string with day of year format "YYYY-DDDTHH:MM:SS.ff"
427
+
- doy (``str``): The day of year in the DOY format.
428
+
- year (``str``): The year.
429
+
- idx (``int``): Index of the start of the original "value" string at which characters 'DDD' are found.
430
+
Returns:
431
+
-value (``str``): Transformed date in traditional date format. i.e.: "YYYY-mm-ddTHH:MM:SS.ff"
0 commit comments