# Saving PMTs as Python Dictionaries to .Mat File

**URL:** <https://www.ruby-forum.com/t/saving-pmts-as-python-dictionaries-to-mat-file/232430>\
**Category:** GNU Radio\
**Created:** [October 9, 2014, 2:59am UTC](https://www.ruby-forum.com/t/saving-pmts-as-python-dictionaries-to-mat-file/232430 "2014-10-09T02:59:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [October 9, 2014, 2:59am UTC](https://www.ruby-forum.com/t/saving-pmts-as-python-dictionaries-to-mat-file/232430/1 "2014-10-09T02:59:15Z")

</div>

I have a series of collected metadata files. I have taken both the  
gr\_read\_file\_metadata.py and parse\_file\_metadata.py scripts and hacked  
them  
to my own needs. What I would like to do is convert the PMT to python  
dictionary (already done in the vanilla files) and save the dicitonary  
as a  
Matlab .mat file format. SciPy has the necessary libraries and functions  
to  
save with the savemat command, the problem is, at least I believe it is  
the  
PMTs are being problematic.

For example I convert all headers to a dictionary and try to save just  
that  
and I get this error:

/usr/lib64/python2.6/site-packages/scipy/io/matlab/mio.py:165:  
FutureWarning: Using oned\_as default value (‘column’) This will change  
to  
‘row’ in future versions  
oned\_as=oned\_as)  
Traceback (most recent call last):  
File “./parser\_mat.py”, line 71, in   
main(filename, options.savefile, options.detached, options.computer)  
File “./parser\_mat.py”, line 51, in main  
scipy.io.savemat(savefile, dict(info))  
File “/usr/lib64/python2.6/site-packages/scipy/io/matlab/mio.py”, line  
168, in savemat  
MW.put\_variables(mdict)  
File “/usr/lib64/python2.6/site-packages/scipy/io/matlab/mio5.py”,  
line  
1217, in put\_variables  
mat\_writer.write()  
File “/usr/lib64/python2.6/site-packages/scipy/io/matlab/mio5.py”,  
line  
897, in write  
self.\_write\_items()  
File “/usr/lib64/python2.6/site-packages/scipy/io/matlab/mio5.py”,  
line  
941, in \_write\_items  
MW = MWG.matrix\_writer\_factory(self.file\_stream, el[f])  
File “/usr/lib64/python2.6/site-packages/scipy/io/matlab/mio5.py”,  
line  
1094, in matrix\_writer\_factory  
% (arr, type(arr)))  
TypeError: Could not convert  
\_30320b0200000000\_p\_boost\_\_intrusive\_ptrT\_pmt\_\_pmt\_base\_t (type \<type  
‘SwigPyObject’\>) to array

The snippet of code to save is this:

scip.io.savemat(savefile, dict(info))

savefile is a string that is a user set arguement. info is the  
dictionary.

I don’t know if anyone on this list has tried to do what I am doing but  
I  
would appreciate any insight on where this is going wrong, especially if  
the problem is on my end.

Thanks

Jonathan F.

---

<div class="post-metadata">

**Author:** ![jfaulkenberry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jfaulkenberry](https://www.ruby-forum.com/u/jfaulkenberry)\
**Post date:** [October 9, 2014, 10:17am UTC](https://www.ruby-forum.com/t/saving-pmts-as-python-dictionaries-to-mat-file/232430/2 "2014-10-09T10:17:20Z")

</div>

We have functions to convert PMTs to corresponding Python types. Have  
you tried those? to\_python()?

M

---

<div class="post-metadata">

**Author:** ![jfaulkenberry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jfaulkenberry](https://www.ruby-forum.com/u/jfaulkenberry)\
**Post date:** [October 9, 2014, 8:38pm UTC](https://www.ruby-forum.com/t/saving-pmts-as-python-dictionaries-to-mat-file/232430/3 "2014-10-09T20:38:14Z")

</div>

No I didn’t, I had no idea they existed, as I was depending on  
[http://gnuradio.org/doc/doxygen/page\_pmt.html](http://gnuradio.org/doc/doxygen/page_pmt.html) for information instead of  
[http://gnuradio.org/redmine/projects/gnuradio/wiki/TypePMT](http://gnuradio.org/redmine/projects/gnuradio/wiki/TypePMT) which has a  
little more info on to\_python().

My bad, I guess I wasn’t thorough in reading about PMTs. I fixed my  
problem  
now.

Thank you.

Jonathan
