Skip to content

Commit

Permalink
Merge pull request #106 from dstansby/remove-tolist
Browse files Browse the repository at this point in the history
Remove expensive calls to tolist()
  • Loading branch information
dstansby committed Oct 31, 2020
2 parents 62367cc + 6506185 commit e259e24
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions cdflib/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@ def breakdown_tt2000(tt2000, to_np: bool = False):
t2 = t2s[x]
t3 = new_tt2000[x]
nansec = nansecs[x]
xdate = xdates[:, x].tolist()

xdate.append(0)
xdate.append(0)
xdate.append(nansec)
xdate = np.zeros(9)
xdate[:6] = xdates[:, x]
xdate[8] = nansec

tmpNanosecs = CDFepoch.compute_tt2000(xdate)
if (tmpNanosecs != t3):
dat0 = CDFepoch._LeapSecondsfromYMD(xdate[0],
Expand All @@ -473,32 +473,30 @@ def breakdown_tt2000(tt2000, to_np: bool = False):
nansec = CDFepoch.SECinNanoSecs + nansec
tmpy = tmpy - 1
epoch = tmpy + CDFepoch.J2000Since0AD12hSec
xdate = CDFepoch._EPOCHbreakdownTT2000(epoch)[:, 0].tolist()
xdate.append(0)
xdate.append(0)
xdate.append(nansec)
xdate = np.zeros(9)
xdate[:6] = CDFepoch._EPOCHbreakdownTT2000(epoch)[:, 0]
xdate[8] = nansec
tmpNanosecs = CDFepoch.compute_tt2000(xdate)
if (tmpNanosecs != t3):
dat0 = CDFepoch._LeapSecondsfromYMD(xdate[0],
xdate[1], xdate[2])
tmpx = t2 - int(dat0 * CDFepoch.SECinNanoSecs)
tmpy = int((1.0*tmpx)/CDFepoch.SECinNanoSecsD)
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
xdate = CDFepoch._EPOCHbreakdownTT2000(epoch)[:, 0].tolist()
xdate.append(0)
xdate.append(0)
xdate.append(nansec)
xdate = np.zeros(9)
xdate[:6] = CDFepoch._EPOCHbreakdownTT2000(epoch)[:, 0]
xdate[8] = nansec
tmpNanosecs = CDFepoch.compute_tt2000(xdate)
if (tmpNanosecs != t3):
dat0 = CDFepoch._LeapSecondsfromYMD(xdate[0],
xdate[1],
xdate[2])
tmpx = t2 - int(dat0 * CDFepoch.SECinNanoSecs)
tmpy = int((1.0*tmpx)/CDFepoch.SECinNanoSecsD)
tmpy = int((1.0 * tmpx) / CDFepoch.SECinNanoSecsD)
nansec = int(tmpx - tmpy * CDFepoch.SECinNanoSecs)
if (nansec < 0):
nansec = CDFepoch.SECinNanoSecs + nansec
Expand Down Expand Up @@ -533,7 +531,7 @@ def breakdown_tt2000(tt2000, to_np: bool = False):
@staticmethod
def compute_tt2000(datetimes, to_np: bool = False):

if not isinstance(datetimes, (list, tuple)):
if not isinstance(datetimes, (list, tuple, np.ndarray)):
raise TypeError('datetime must be in list form')

if isinstance(datetimes[0], numbers.Number):
Expand Down

0 comments on commit e259e24

Please sign in to comment.