diff --git a/README.md b/README.md index 7d72110..cdfc58a 100644 --- a/README.md +++ b/README.md @@ -113,12 +113,14 @@ component, text field or buffer. ## Installation +The _IMCtermite_ library may be employed both as a _CLI_ tool and a _python_ +module. + ### CLI tool -The _IMCtermite_ library may be employed both as a _CLI_ tool and a _python_ -module. To build the CLI tool locally use the default target `make` resulting -in the binary `imctermite` while the installation of it in the location -`/usr/local/bin` is done via +To build the CLI tool locally use the default target `make` resulting +in the binary `imctermite`. To ensure system-wide availability the installation +of the tool (in the default location `/usr/local/bin`) is done via ``` make install @@ -168,4 +170,33 @@ the `--output` option. ### Python +Given the `imctermite` module is available we can import it and declare an instance +of it by passing a _raw_ file to the constructor + +```Python +import imc_termite + +imcraw = imc_termite.imctermite(b"sample/sampleA.raw") +``` + +An example of how to create an instance and obtain the list of channels is: + +```Python +import imc_termite + +# declare and initialize instance of "imctermite" by passing a raw-file +try : + imcraw = imc_termite.imctermite(b"samples/sampleA.raw") +except RuntimeError as e : + print("failed to load/parse raw-file: " + str(e)) + +# obtain list of channels as list of dictionaries (without data) +channels = imcraw.get_channels(False) +print(channels) +``` + +A more complete example including the methods for obtaining the channels including +their data and or directly printing them to files can be found at +[Usage](python/usage.py). + ## References diff --git a/cython/imc_termite.pxd b/cython/imc_termite.pxd index 1d6ffc3..7ee3375 100644 --- a/cython/imc_termite.pxd +++ b/cython/imc_termite.pxd @@ -11,8 +11,8 @@ cdef extern from "imc_raw.hpp" namespace "imc": imc_termite() except + imc_termite(string rawfile) except + # provide raw file - void submit_file(string rawfile) except+ + void set_file(string rawfile) except + # get JSON list of channels - vector[string] get_channels() except+ + vector[string] get_channels(bool json, bool data) except + # print all channels - void print_channels(string outputdir) except+ + void print_channels(string outputdir) except + diff --git a/cython/py_imc_termite.pyx b/cython/py_imc_termite.pyx index 34cf596..af62123 100644 --- a/cython/py_imc_termite.pyx +++ b/cython/py_imc_termite.pyx @@ -16,12 +16,14 @@ cdef class imctermite: # provide raw file def submit_file(self,string rawfile): - self.cpp_tdm.set_file(rawfile) + self.cpp_imc.set_file(rawfile) # get JSON list of channels def get_channels(self, bool data): - return self.cpp_imc.get_channels() + chnlst = self.cpp_imc.get_channels(True,data) + chnlstjn = [jn.loads(chn.decode()) for chn in chnlst] + return chnlstjn # print a channels - def print_channel(self, string outputdir): - self.cpp_tdm.print_channels(outputdir) + def print_channels(self, string outputdir): + self.cpp_imc.print_channels(outputdir) diff --git a/cython/setup.py b/cython/setup.py index 53d9472..7a8598c 100644 --- a/cython/setup.py +++ b/cython/setup.py @@ -20,5 +20,5 @@ setup( author_email='mario.fink@record-evolution.de', url='https://github.com/RecordEvolution/IMCtermite.git', name="imc_termite", - ext_modules=cythonize(extensions) + ext_modules=cythonize(extensions,force=True) ) diff --git a/lib/imc_channel.hpp b/lib/imc_channel.hpp index 111fe5e..a5766cf 100644 --- a/lib/imc_channel.hpp +++ b/lib/imc_channel.hpp @@ -364,11 +364,11 @@ namespace imc <<"\",\"comment\":\""<(ydata_,0) - <<"\",\"xdata\":\""<(xdata_,0); + ss<<",\"ydata\":"<(ydata_,0) + <<",\"xdata\":"<(xdata_,0); } // ss<<"\",\"aff. blocks\":\""< 0 : + chnydata = channelsdata[0]['ydata'] + chnxdata = channelsdata[0]['xdata'] + +print(len(chnydata)) +print(len(chnxdata)) + +# print the channels into a specific directory +imcraw.print_channels(b"./")