diff options
author | manojgudi | 2013-10-07 14:04:07 +0530 |
---|---|---|
committer | manojgudi | 2013-10-07 14:04:07 +0530 |
commit | e9576e44ef8f0ad67d8cd8a4e025a0f8da0727f8 (patch) | |
tree | 3a77657667b4ef037f712ee68a5ec86c86cba5c5 /gr-scigen/python | |
parent | ed97c528ce61496e10d612a4f5e9aef509b65ccf (diff) | |
download | gnuradio-e9576e44ef8f0ad67d8cd8a4e025a0f8da0727f8.tar.gz gnuradio-e9576e44ef8f0ad67d8cd8a4e025a0f8da0727f8.tar.bz2 gnuradio-e9576e44ef8f0ad67d8cd8a4e025a0f8da0727f8.zip |
added gr-scimod block+CMake change | compiles fine
Diffstat (limited to 'gr-scigen/python')
-rw-r--r-- | gr-scigen/python/CMakeLists.txt | 46 | ||||
-rw-r--r-- | gr-scigen/python/__init__.py | 52 | ||||
-rw-r--r-- | gr-scigen/python/generic.py | 66 | ||||
-rwxr-xr-x | gr-scigen/python/qa_scigen.py | 58 | ||||
-rw-r--r-- | gr-scigen/python/scigen.py | 1 |
5 files changed, 223 insertions, 0 deletions
diff --git a/gr-scigen/python/CMakeLists.txt b/gr-scigen/python/CMakeLists.txt new file mode 100644 index 000000000..74d9a6bae --- /dev/null +++ b/gr-scigen/python/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +include(GrPython) + +GR_PYTHON_INSTALL( + FILES + __init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/scigen + COMPONENT "scigen_python" +) + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) + +list(APPEND GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gr-scigen/python +) +list(APPEND GR_TEST_TARGET_DEPS gnuradio-scigen) + +include(GrTest) +file(GLOB py_qa_test_files "qa_*.py") +foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) +endforeach(py_qa_test_file) +endif(ENABLE_TESTING) diff --git a/gr-scigen/python/__init__.py b/gr-scigen/python/__init__.py new file mode 100644 index 000000000..11a291ae4 --- /dev/null +++ b/gr-scigen/python/__init__.py @@ -0,0 +1,52 @@ +# +# Copyright 2008,2009 Free Software Foundation, Inc. +# +# This application is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This application is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# The presence of this file turns this directory into a Python package + +''' +This is the GNU Radio SCIGEN module. Place your Python package +description here (python/__init__.py). +''' + +# ---------------------------------------------------------------- +# Temporary workaround for ticket:181 (swig+python problem) +import sys +_RTLD_GLOBAL = 0 +try: + from dl import RTLD_GLOBAL as _RTLD_GLOBAL +except ImportError: + try: + from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL + except ImportError: + pass + +if _RTLD_GLOBAL != 0: + _dlopenflags = sys.getdlopenflags() + sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL) +# ---------------------------------------------------------------- + + +# import any pure python here +from generic import * +# + +# ---------------------------------------------------------------- +# Tail of workaround +if _RTLD_GLOBAL != 0: + sys.setdlopenflags(_dlopenflags) # Restore original flags +# ---------------------------------------------------------------- diff --git a/gr-scigen/python/generic.py b/gr-scigen/python/generic.py new file mode 100644 index 000000000..f7807fdbc --- /dev/null +++ b/gr-scigen/python/generic.py @@ -0,0 +1,66 @@ +import gras +import numpy + +class generic(gras.Block): + + def __init__(self): + gras.Block.__init__(self, + name="generic", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + + def set_parameters(self,func_name,window): + self.n = window + self.func_name = func_name + + # Check if value of window is integral of length of input source vector + # For cases like -> input = [3 , 4, 5 ,6] & window = 3 + def isIntegralWin(self, input_item, window): + if (len(input_item) % window ): + raise Exception("Value of Window should be an integral value of length of input items") + + + def work(self, input_items, output_items): + + # Limit output_items to just the size of window + output_items[0] = output_items[0][:self.n] + from scilab import Scilab + Sci = Scilab() + + # Check number of input_instances + n_input_items = len(input_items) + + # Create output string instance which will be evaluated + out_eval_string = 'eval("Sci.'+self.func_name+'(' + + # Iterate for n_input_items + for i in range(n_input_items): + + # Check window condition + self.isIntegralWin(input_items[i][:], self.n) + + # If the window is greater than 1, input_items[i][:self.n] looks like [1 2 3 4 5] which is err for python since it requires comma as delimiters + if self.n == 1: + out_eval_string = out_eval_string + str(input_items[i][:self.n]) + "," + else: + print 'IN',str(input_items[i][:self.n]) + out_eval_string = out_eval_string + (str(input_items[i][:self.n].tolist())) + "," # Replace 10spaces with a singe comma + + out_eval_string = out_eval_string.rstrip(",") + ')")' + print "STRING ",str(out_eval_string) + + # for functions like sin + if n_input_items == 1 and self.n == 1: + output_items[0][:self.n] = eval(out_eval_string) + else: + output_items[0] = eval(out_eval_string) + + print "OUT",output_items[0] + #print 'SIZE,', output_items[0].size + + #Write a for loop for n_inputs + for i in range(n_input_items): + self.consume(i,self.n) # Consume from port 0 input_items + + self.produce(0,self.n) # Produce from port 0 output_items + diff --git a/gr-scigen/python/qa_scigen.py b/gr-scigen/python/qa_scigen.py new file mode 100755 index 000000000..f06dc8b5d --- /dev/null +++ b/gr-scigen/python/qa_scigen.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2013 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +#import mymod_swig as mymod +from generic import * + + +class qa_generic (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + + src0 = numpy.arange(0,3.1416,1) + + src0 = gr.vector_source_f(src0) + expected_result = (0.0, 0.8414709568023682, 0.9092974066734314, 0.14112000167369843) + + sqr = generic() + sqr.set_parameters("sin",1) + + dst = gr.vector_sink_f() + + self.tb.connect(src0, (sqr,0)) # src0(vector_source) -> sqr_input_0 + self.tb.connect(sqr,dst) # sqr_output_0 -> dst (vector_source) + + self.tb.run() + + result_data = dst.data() + print result_data, "Result data" + + self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6) + + +if __name__ == '__main__': + gr_unittest.main() diff --git a/gr-scigen/python/scigen.py b/gr-scigen/python/scigen.py new file mode 100644 index 000000000..ca5556bc8 --- /dev/null +++ b/gr-scigen/python/scigen.py @@ -0,0 +1 @@ +from generic import * |