-
-
Save forstater/140d3c97f80c0821fcb0 to your computer and use it in GitHub Desktop.
A Python gist to convert any data type supported by MOSAIC (https://github.com/usnistgov/mosaic) to a simple binary format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Extend the MOSAIC ConvertToCSV class to export arbitrary binary files. | |
:Created: 02/25/2015 | |
:Author: Arvind Balijepalli <[email protected]> | |
:ChangeLog: | |
.. line-block:: | |
02/25/15 AB Initial version | |
""" | |
import mosaic.ConvertToCSV as conv | |
import mosaic.binTrajIO as bin | |
import mosaic.settings as sett | |
import numpy as np | |
from mosaic.metaTrajIO import EmptyDataPipeError | |
class ConvertToBin(conv.ConvertToCSV): | |
def Convert(self, blockSize, binType): | |
""" | |
Start converting data | |
:Parameters: | |
- `blockSize` : number of data points to convert. | |
- `binType` : Numpy binary type. | |
""" | |
try: | |
while(True): | |
np.array( self.trajDataObj.popdata(blockSize), dtype=binType ).tofile(self._filename()) | |
except EmptyDataPipeError: | |
pass | |
if __name__ == '__main__': | |
s={ | |
"AmplifierOffset": 0.0, | |
"SamplingFrequency": 250000, | |
"AmplifierScale": "1.0", | |
"ColumnTypes": "[('curr_pA', '>f8'), ('volts', '>f8')]", | |
"dcOffset": 0.0, | |
"filter": "*.bin", | |
"start": 0.0, | |
"HeaderOffset": 0, | |
"IonicCurrentColumn": "curr_pA" | |
} | |
ConvertToBin( | |
bin.binTrajIO(dirname=".", **s ), | |
outdir="convert", | |
extension="bin" | |
).Convert(blockSize=10000000, binType='f4') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment