Skip to content

Commit

Permalink
Merge pull request #10 from caspervdw/fix-timestamp
Browse files Browse the repository at this point in the history
FIX Timestamp on linux
  • Loading branch information
caspervdw committed Nov 3, 2015
2 parents 59f957c + 9f4a19a commit 7c57f85
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
11 changes: 7 additions & 4 deletions pims_nd2/ND2SDK.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
if platform == "linux" or platform == "linux2":
nd2 = cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), 'ND2SDK',
'linux', 'libnd2ReadSDK.so'))
def jdn_to_datetime(jdn):
return None # ND2SDK gives no timestamp on linux
elif platform == "darwin":
raise OSError("Unsupported OS. The ND2SDK for OSX is included, "
"please try to implement!")
Expand All @@ -23,8 +21,13 @@ def jdn_to_datetime(jdn):
os.environ["PATH"] += os.pathsep + os.path.join(dlldir)
nd2 = cdll.LoadLibrary('v6_w32_nd2ReadSDK.dll')

def jdn_to_datetime(jdn):
return datetime.fromtimestamp((jdn - 2440587.5) * 86400.)

def jdn_to_datetime_local(jdn):
return datetime.fromtimestamp((jdn - 2440587.5) * 86400.)


def jdn_to_datetime_utc(jdn):
return datetime.utcfromtimestamp((jdn - 2440587.5) * 86400.)


LIMFILEHANDLE = c_int
Expand Down
Binary file modified pims_nd2/ND2SDK/linux/libnd2ReadSDK.so
Binary file not shown.
3 changes: 2 additions & 1 deletion pims_nd2/nd2reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def metadata(self):
'plane_count': bufmd.uiPlaneCount,
'angle': bufmd.dAngle,
'calibration_um': bufmd.dCalibration,
'time_start': h.jdn_to_datetime(bufmd.dTimeStart),
'time_start': h.jdn_to_datetime_local(bufmd.dTimeStart),
'time_start_utc': h.jdn_to_datetime_utc(bufmd.dTimeStart),
'objective': bufmd.wszObjectiveName,
'magnification': bufmd.dObjectiveMag,
'NA': bufmd.dObjectiveNA,
Expand Down
7 changes: 2 additions & 5 deletions pims_nd2/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,9 @@ def test_metadata(self):
assert_allclose(self.v.colors[0], [0.47, 0.91, 0.06], atol=0.01)

def test_time(self):
if platform == 'linux' or platform == 'linux2':
raise nose.SkipTest('time_start not supported on linux. Skipping.')
time = self.v.metadata['time_start']
time = self.v.metadata['time_start_utc']
assert_equal((time.year, time.month, time.day, time.hour, time.minute,
time.second, time.microsecond),
(2014, 6, 18, 15, 55, 23, 392018))
time.second), (2014, 6, 18, 13, 55, 23))

def test_metadata_framewise(self):
self.v.bundle_axes = 'yx'
Expand Down

0 comments on commit 7c57f85

Please sign in to comment.