Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
xdate1 = CDFepoch._EPOCHbreakdownTT2000(epoch)
xdate1.append(0)
xdate1.append(0)
xdate1.append(nansec)
tmpNanosecs = CDFepoch.compute_tt2000(xdate1)
if tmpNanosecs != t3:
dat0 = CDFepoch._LeapSecondsfromYMD(xdate1[0],
xdate1[1], xdate1[2])
tmpx = t2 - int(dat0 * CDFepoch.SECinNanoSecs)
tmpy = int(float(tmpx / CDFepoch.SECinNanoSecsD))
nansec = int(tmpx - tmpy * CDFepoch.SECinNanoSecs)
if nansec < 0:
nansec = CDFepoch.SECinNanoSecs + nansec
tmpy -= 1
epoch = tmpy + CDFepoch.J2000Since0AD12hSec
xdate1 = CDFepoch._EPOCHbreakdownTT2000(epoch)
xdate1.append(0)
xdate1.append(0)
xdate1.append(nansec)
tmpNanosecs = CDFepoch.compute_tt2000(xdate1)
if tmpNanosecs != t3:
dat0 = CDFepoch._LeapSecondsfromYMD(xdate1[0],
xdate1[1], xdate1[2])
tmpx = t2 - int(dat0 * CDFepoch.SECinNanoSecs)
tmpy = int((1.0 * tmpx) / CDFepoch.SECinNanoSecsD)
nansec = int(tmpx - tmpy * CDFepoch.SECinNanoSecs)
if nansec < 0:
nansec = CDFepoch.SECinNanoSecs + nansec
tmpy = tmpy - 1
epoch = tmpy + CDFepoch.J2000Since0AD12hSec
xdate1 = CDFepoch._EPOCHbreakdownTT2000(epoch)
xdate1.append(0)
def _LeapSecondsfromYMD(year, month, day): # @NoSelf
j = -1
m = 12 * year + month
for i, _ in reversed(list(enumerate(CDFepoch.LTS))):
n = 12 * CDFepoch.LTS[i][0] + CDFepoch.LTS[i][1]
if m >= n:
j = i
break
if j == -1:
return 0.0
da = CDFepoch.LTS[j][3]
# pre-1972
if j < CDFepoch.NERA1:
jda = CDFepoch._JulianDay(year, month, day)
da = da + ((jda - CDFepoch.MJDbase) - CDFepoch.LTS[j][4]) * CDFepoch.LTS[j][5]
return da
def breakdown(epochs, to_np=None): # @NoSelf
# Returns either a single array, or a array of arrays depending on the input
if isinstance(epochs, int) or isinstance(epochs, np.int64):
return CDFepoch.breakdown_tt2000(epochs, to_np)
elif isinstance(epochs, float) or isinstance(epochs, np.float64):
return CDFepoch.breakdown_epoch(epochs, to_np)
elif isinstance(epochs, complex) or isinstance(epochs, np.complex128):
return CDFepoch.breakdown_epoch16(epochs, to_np)
elif isinstance(epochs, list) or isinstance(epochs, tuple) or isinstance(epochs, np.ndarray):
if isinstance(epochs[0], int) or isinstance(epochs[0], np.int64):
return CDFepoch.breakdown_tt2000(epochs, to_np)
elif isinstance(epochs[0], float) or isinstance(epochs[0], np.float64):
return CDFepoch.breakdown_epoch(epochs, to_np)
elif isinstance(epochs[0], complex) or isinstance(epochs[0], np.complex128):
return CDFepoch.breakdown_epoch16(epochs, to_np)
else:
print('Bad input')
return None
else:
print('Bad input')
return None
def encode_tt2000(tt2000, iso_8601=None, unixtime=False): # @NoSelf
if isinstance(tt2000, int) or isinstance(tt2000, np.int64):
new_tt2000 = [tt2000]
elif isinstance(tt2000, list) or isinstance(tt2000, np.ndarray):
new_tt2000 = tt2000
else:
print('Bad input')
encoded = list()
for x in new_tt2000:
epoch, nansec = CDFepoch.breakdown_tt2000(x, encoding=True)
epoch_astropy = Time(epoch, format='unix')
base = Time('0000-01-01 00:00:00', scale='tai')
t = epoch_astropy.unix + base.unix
tt = Time(t, format='unix')
if iso_8601:
encoded.append(tt.isot[:-3] + str(nansec))
elif not iso_8601 and not unixtime:
nansec = str(nansec)
one = nansec[:3]
two = nansec[3:6]
three = nansec[6:]
encoded.append(tt.iso[:-3] + one + '.' + two + '.' + three)
elif unixtime:
u_time = float(str(tt.unix)[:-7] + str(nansec)[:3])
encoded.append(u_time)
if len(encoded) == 1:
The start/end times should be in either be in epoch units, or in the list
format described in "compute_epoch/epoch16/tt2000" section.
"""
if isinstance(epochs, float) or isinstance(epochs, np.float64):
return CDFepoch.epochrange_epoch(epochs, starttime, endtime)
elif isinstance(epochs, int) or isinstance(epochs, np.int64):
return CDFepoch.epochrange_tt2000(epochs, starttime, endtime)
elif isinstance(epochs, complex) or isinstance(epochs, np.complex128):
return CDFepoch.epochrange_epoch16(epochs, starttime, endtime)
elif isinstance(epochs, list) or isinstance(epochs, tuple) or isinstance(epochs, np.ndarray):
if isinstance(epochs[0], float) or isinstance(epochs[0], np.float64):
return CDFepoch.epochrange_epoch(epochs, starttime, endtime)
elif isinstance(epochs[0], int) or isinstance(epochs[0], np.int64):
return CDFepoch.epochrange_tt2000(epochs, starttime, endtime)
elif isinstance(epochs[0], complex) or isinstance(epochs[0], np.complex128):
return CDFepoch.epochrange_epoch16(epochs, starttime, endtime)
else:
print('Bad input')
return None
else:
print('Bad input')
return None
def findepochrange(epochs, starttime=None, endtime=None): # @NoSelf
"""
Finds the record range within the start and end time from values
of a CDF epoch data type. It returns a list of record numbers.
If the start time is not provided, then it is
assumed to be the minimum possible value. If the end time is not
provided, then the maximum possible value is assumed. The epoch is
assumed to be in the chronological order. The start and end times
should have the proper number of date/time components, corresponding
to the epoch's data type.
The start/end times should be in either be in epoch units, or in the list
format described in "compute_epoch/epoch16/tt2000" section.
"""
if isinstance(epochs, float) or isinstance(epochs, np.float64):
return CDFepoch.epochrange_epoch(epochs, starttime, endtime)
elif isinstance(epochs, int) or isinstance(epochs, np.int64):
return CDFepoch.epochrange_tt2000(epochs, starttime, endtime)
elif isinstance(epochs, complex) or isinstance(epochs, np.complex128):
return CDFepoch.epochrange_epoch16(epochs, starttime, endtime)
elif isinstance(epochs, list) or isinstance(epochs, tuple) or isinstance(epochs, np.ndarray):
if isinstance(epochs[0], float) or isinstance(epochs[0], np.float64):
return CDFepoch.epochrange_epoch(epochs, starttime, endtime)
elif isinstance(epochs[0], int) or isinstance(epochs[0], np.int64):
return CDFepoch.epochrange_tt2000(epochs, starttime, endtime)
elif isinstance(epochs[0], complex) or isinstance(epochs[0], np.complex128):
return CDFepoch.epochrange_epoch16(epochs, starttime, endtime)
else:
print('Bad input')
return None
else:
print('Bad input')
return None
count = len(new_tt2000)
toutcs = list()
for x in range(0, count):
nanoSecSinceJ2000 = new_tt2000[x]
toPlus = 0.0
t3 = nanoSecSinceJ2000
datx = CDFepoch._LeapSecondsfromJ2000(nanoSecSinceJ2000)
if nanoSecSinceJ2000 > 0:
secSinceJ2000 = int(nanoSecSinceJ2000 / CDFepoch.SECinNanoSecsD)
nansec = int(nanoSecSinceJ2000 - secSinceJ2000 * CDFepoch.SECinNanoSecs)
secSinceJ2000 = secSinceJ2000 - 32
secSinceJ2000 = secSinceJ2000 + 43200
nansec = nansec - 184000000
else:
nanoSecSinceJ2000 = nanoSecSinceJ2000 + CDFepoch.T12hinNanoSecs
nanoSecSinceJ2000 = nanoSecSinceJ2000 - CDFepoch.dTinNanoSecs
secSinceJ2000 = int(nanoSecSinceJ2000 / CDFepoch.SECinNanoSecsD)
nansec = int(nanoSecSinceJ2000 - secSinceJ2000 * CDFepoch.SECinNanoSecs)
if nansec < 0:
nansec = CDFepoch.SECinNanoSecs + nansec
secSinceJ2000 = secSinceJ2000 - 1
t2 = secSinceJ2000 * CDFepoch.SECinNanoSecs + nansec
if datx[0] > 0.0:
# post-1972...
secSinceJ2000 = secSinceJ2000 - int(datx[0])
epoch = CDFepoch.J2000Since0AD12hSec + secSinceJ2000
if datx[1] == 0.0:
date1 = CDFepoch._EPOCHbreakdownTT2000(epoch)
else:
epoch = epoch - 1
date1 = CDFepoch._EPOCHbreakdownTT2000(epoch)
def breakdown(epochs, to_np=None): # @NoSelf
# Returns either a single array, or a array of arrays depending on the input
if isinstance(epochs, int) or isinstance(epochs, np.int64):
return CDFepoch.breakdown_tt2000(epochs, to_np)
elif isinstance(epochs, float) or isinstance(epochs, np.float64):
return CDFepoch.breakdown_epoch(epochs, to_np)
elif isinstance(epochs, complex) or isinstance(epochs, np.complex128):
return CDFepoch.breakdown_epoch16(epochs, to_np)
elif isinstance(epochs, list) or isinstance(epochs, tuple) or isinstance(epochs, np.ndarray):
if isinstance(epochs[0], int) or isinstance(epochs[0], np.int64):
return CDFepoch.breakdown_tt2000(epochs, to_np)
elif isinstance(epochs[0], float) or isinstance(epochs[0], np.float64):
return CDFepoch.breakdown_epoch(epochs, to_np)
elif isinstance(epochs[0], complex) or isinstance(epochs[0], np.complex128):
return CDFepoch.breakdown_epoch16(epochs, to_np)
else:
print('Bad input')
return None
else:
print('Bad input')