Pārlūkot izejas kodu

binary_preparer renamed, functions and variables reanmed

Felix Schultze 9 gadi atpakaļ
vecāks
revīzija
c631b3409c

+ 0 - 53
imageprocessing/binaryPreparer.py

@@ -1,53 +0,0 @@
-import numpy as np
-
-import logging
-
-logger = logging.getLogger(__name__)
-
-
-def processBinary(path, sliceSize, sliceFrom=None, sliceTo=None, littleEndian=False):
-    logger.debug('littleEndian: ' + str(littleEndian))
-
-    rawFile = open(path, 'rb')
-    rawFile.seek(0, 2)
-    rawFileSize = rawFile.tell()
-    rawFile.seek(0, 0)
-
-    numx, numy = sliceSize
-
-    numberOfBytes = 4
-    floatsPerSlice = numx * numy
-    bytesPerSlice = floatsPerSlice * numberOfBytes
-    numberOfSlices = int(rawFileSize / bytesPerSlice)
-
-    '''
-    here we can get a subset of the binary for faster testing
-
-    tmpOutputFile = open('/tmp/binary_61_100_%d.raw' % time.time(), 'wb')
-    rawFile.seek(bytesPerSlice * 61, 0)
-    tmpOutputFile.write(rawFile.read(bytesPerSlice * 40))
-    tmpOutputFile.close()
-    rawFile.seek(0, 0)
-
-    raise ValueError('outputfile written')
-    '''
-
-    if (sliceFrom is not None and
-            sliceTo is not None):
-
-        numberOfSlices = sliceTo - sliceFrom + 1
-        rawFile.seek(sliceFrom * bytesPerSlice, 0)
-
-    floats = np.empty((1, numberOfSlices * floatsPerSlice), dtype=np.float32)
-
-    endianString = '>'
-    if littleEndian is True:
-        endianString = '<'
-
-    dt = np.dtype('%s%s' % (endianString, 'f'))
-    floats[0] = np.fromfile(rawFile, dtype=dt)
-
-    floats = (floats - floats.min()) / (floats.max() - floats.min())
-    floats = floats.reshape((1, numberOfSlices, numy, numx))
-
-    return floats

+ 53 - 0
imageprocessing/binary_preparer.py

@@ -0,0 +1,53 @@
+import numpy as np
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+def process_binary(path, slice_size, slice_from=None, slice_to=None, little_endian=False):
+    logger.debug('little_endian: ' + str(little_endian))
+
+    raw_file = open(path, 'rb')
+    raw_file.seek(0, 2)
+    raw_fileSize = raw_file.tell()
+    raw_file.seek(0, 0)
+
+    numx, numy = slice_size
+
+    number_of_bytes = 4
+    floats_per_slice = numx * numy
+    bytes_per_slice = floats_per_slice * number_of_bytes
+    number_of_slices = int(raw_fileSize / bytes_per_slice)
+
+    '''
+    here we can get a subset of the binary for faster testing
+
+    tmpOutputFile = open('/tmp/binary_61_100_%d.raw' % time.time(), 'wb')
+    raw_file.seek(bytes_per_slice * 61, 0)
+    tmpOutputFile.write(raw_file.read(bytes_per_slice * 40))
+    tmpOutputFile.close()
+    raw_file.seek(0, 0)
+
+    raise ValueError('outputfile written')
+    '''
+
+    if (slice_from is not None and
+            slice_to is not None):
+
+        number_of_slices = slice_to - slice_from + 1
+        raw_file.seek(slice_from * bytes_per_slice, 0)
+
+    floats = np.empty((1, number_of_slices * floats_per_slice), dtype=np.float32)
+
+    endian_string = '>'
+    if little_endian is True:
+        endian_string = '<'
+
+    dt = np.dtype('%s%s' % (endian_string, 'f'))
+    floats[0] = np.fromfile(raw_file, dtype=dt)
+
+    floats = (floats - floats.min()) / (floats.max() - floats.min())
+    floats = floats.reshape((1, number_of_slices, numy, numx))
+
+    return floats

+ 2 - 2
volumes/processing/service/SliceGenerator.py

@@ -9,7 +9,7 @@ from volumes.processing.models import AutomaticProcessing
 from skimage import img_as_int
 import numpy as np
 
-from imageprocessing import tiffPreparer, sliceMapCreator, binaryPreparer
+from imageprocessing import tiffPreparer, sliceMapCreator, binary_preparer
 from . import MultiProcessUByte, Normalizer
 
 import logging
@@ -86,7 +86,7 @@ def sliceGeneratorPlain(data, volumeId):
             frames = tiffPreparer.processTiffFile(volume.path)
         elif volume.rawData:
             logger.debug('volId: %s, reading raw data' % (volumeId))
-            frames = binaryPreparer.processBinary(volume.path, (volume.width, volume.height), littleEndian=volume.littleEndian)
+            frames = binary_preparer.process_binary(volume.path, (volume.width, volume.height), littleEndian=volume.littleEndian)
         else:
             raise ValueError('sorry, file currently not supported, is it a raw file?')