Commit f25845b2 authored by kulvait's avatar kulvait

Readme, timeToSeconds

Added function timeToSeconds
Added Readme
Formating by autopep8
parent 5fef0b50
Pipeline #164 failed with stages
# Python package denpy
## Instalation
```
pip install git+https://gitlab.stimulate.ovgu.de/vojtech.kulvait/denpy.git
```
......@@ -54,8 +54,9 @@ def storeNdarrayAsDEN(fileName, dataFrame, force=False):
elif len(dataFrame.shape) > 3:
raise ValueError(
'Dimension of dataFrame should be 2 or 3 but is %d.' % len(dataFrame.shape))
shape = dataFrame.shape#Now len is for sure 3
writeEmptyDEN(fileName, dimx=shape[0], dimy=shape[1], dimz=shape[2], force=force)#No effect
shape = dataFrame.shape # Now len is for sure 3
writeEmptyDEN(fileName, dimx=shape[0], dimy=shape[1], dimz=shape[2],
force=force) # No effect
header = np.fromfile(fileName, np.dtype('<i2'), 3)
rows = np.uint32(header[0])
columns = np.uint32(header[1])
......@@ -72,50 +73,53 @@ def storeNdarrayAsDEN(fileName, dataFrame, force=False):
def writeFrame(fileName, k, data, force=False):
if not force and os.path.exists(fileName):
raise IOError('File %s already exists, no header written' % fileName)
shape = data.shape
if len(shape) != 2:
raise ValueError('Dimension of data should be 2 %d.' % len(shape))
header = np.fromfile(file, np.dtype('<i2'), 3)
rows = np.uint32(header[0])
columns = np.uint32(header[1])
if shape[0] != rows or shape[1] != columns:
raise ValueError('There is dimension mismatch between frame (%d, %d) and expected (rows, cols) = (%d, %d) according to header.' % (rows, columns, shape[0], shape[1]))
f = open(file, "wb+")
data = np.array(data, np.dtype('<f4'))
data = data.reshape((rows * columns, ))
f.seek(6 + rows * columns * k * 4, os.SEEK_SET)
data.tofile(f)
f.close()
if not force and os.path.exists(fileName):
raise IOError('File %s already exists, no header written' % fileName)
shape = data.shape
if len(shape) != 2:
raise ValueError('Dimension of data should be 2 %d.' % len(shape))
header = np.fromfile(file, np.dtype('<i2'), 3)
rows = np.uint32(header[0])
columns = np.uint32(header[1])
if shape[0] != rows or shape[1] != columns:
raise ValueError('There is dimension mismatch between frame (%d, %d) and expected (rows, cols) = (%d, %d) according to header.' %
(rows, columns, shape[0], shape[1]))
f = open(file, "wb+")
data = np.array(data, np.dtype('<f4'))
data = data.reshape((rows * columns, ))
f.seek(6 + rows * columns * k * 4, os.SEEK_SET)
data.tofile(f)
f.close()
def writeEmptyDEN(fileName, dimx, dimy, dimz, force=False):
if not force and os.path.exists(fileName):
raise IOError('File %s already exists, no header written' % fileName)
outfile = open(file, "w")
header = np.array([dimx, dimy, dimz])
header = np.array(header, dtype='<i2')
header.tofile(outfile)
fileSize = dimx*dimy*dimz*4+6
outfile.seek(fileSize-1)
outfile.write('\0')
outfile.close()
if not force and os.path.exists(fileName):
raise IOError('File %s already exists, no header written' % fileName)
outfile = open(file, "w")
header = np.array([dimx, dimy, dimz])
header = np.array(header, dtype='<i2')
header.tofile(outfile)
fileSize = dimx * dimy * dimz * 4 + 6
outfile.seek(fileSize - 1)
outfile.write('\0')
outfile.close()
def readHeader(file):
header = np.fromfile(file, np.dtype('<i2'), 3)
par = {}
par["rows"] = np.uint32(header[0])
par["cols"] = np.uint32(header[1])
par["zdim"] = np.uint32(header[2])
return(par)
header = np.fromfile(file, np.dtype('<i2'), 3)
par = {}
par["rows"] = np.uint32(header[0])
par["cols"] = np.uint32(header[1])
par["zdim"] = np.uint32(header[2])
return(par)
# Trim frame to the specified dimensions
# Can get a subframe, where row_from is the first row index
# row_to is not included
# col_from is the first col index
# col_to is not included
def trimFrame(frame, row_from, row_to, col_from, col_to):
newdata = frame[row_from:row_to, col_from:col_to]
return(newdata)
def trimFrame(frame, row_from, row_to, col_from, col_to):
newdata = frame[row_from:row_to, col_from:col_to]
return(newdata)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
(c) 2019
DEN and DICOM IO manipulation
@author: Vojtech Kulvait
@author: Enno Schieferecke
"""
def timeToSeconds(naivetime):
strtime = str(naivetime).split('.', 1)[0]
secondfraction = float("0.%s" % str(naivetime).split('.', 1)[1])
sec = int(strtime[-2:]) + secondfraction
mins = int(strtime[-4:][:2])
hod = int(strtime[-6:][:2])
totalsec = sec + 60 * mins + 60 * 60 * hod
return(totalsec)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment