mailRe: r27012 - /branches/nmrglue/test_suite/system_tests/nmrglue.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on December 08, 2014 - 13:59:
Hi Troels,

I didn't notice that the shape was not preserved.  To store the numpy
shape, this is also not a problem as XML has attributes.  For example
'type' is the attribute already used to determine what we do with the
data in relax.  We simply add a new 'shape' attribute and read this
then reshape when loading the data.  If at any point you need help for
implementing any of the XML stuff, just say and I can do a few things
in your branch.

Regards,

Edward


On 8 December 2014 at 13:40,  <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet
Date: Mon Dec  8 13:40:52 2014
New Revision: 27012

URL: http://svn.gna.org/viewcvs/relax?rev=27012&view=rev
Log:
Try to decode the numpy array as base64 string.

This shows, that the shape of the data is lost after decoding.

Task #7873 (https://gna.org/task/index.php?7873): Write wrapper function to 
nmrglue, to read .ft2 files and process them.
Homepage: http://www.nmrglue.com/
Link to nmrglue discussion: 
https://groups.google.com/forum/#!forum/nmrglue-discuss
The code is develop at Github: https://github.com/jjhelmus/nmrglue/
Google code: https://code.google.com/p/nmrglue/
Documentation: http://nmrglue.readthedocs.org/en/latest/index.html

Modified:
    branches/nmrglue/test_suite/system_tests/nmrglue.py

Modified: branches/nmrglue/test_suite/system_tests/nmrglue.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/nmrglue/test_suite/system_tests/nmrglue.py?rev=27012&r1=27011&r2=27012&view=diff
==============================================================================
--- branches/nmrglue/test_suite/system_tests/nmrglue.py (original)
+++ branches/nmrglue/test_suite/system_tests/nmrglue.py Mon Dec  8 13:40:52 
2014
@@ -21,7 +21,8 @@
 
###############################################################################

 # Python module imports.
-from numpy import concatenate, save
+import base64
+from numpy import concatenate, float32, float64, frombuffer, save
 from os import path, sep
 from tempfile import mkdtemp

@@ -364,6 +365,9 @@
         dic  = cdp.nmrglue_dic[sp_id]
         udic  = cdp.nmrglue_udic[sp_id]
         data = cdp.nmrglue_data[sp_id]
+        s = base64.b64encode(data)
+        cdp.nmrglue_data[sp_id] = s
+        print("Type of encoding is:", type(cdp.nmrglue_data[sp_id]))

         # Try storing the numpy array, and print size
         data_numpy = ds.tmpdir + sep + 'data.npy'
@@ -379,6 +383,8 @@
         dirpath = ds.tmpdir

         print("Shape of data is %ix%i"%(data.shape[0], data.shape[1]))
+        print("dtype of data is", data.dtype)
+        print("Type of data[0][0]: ", type(data[0][0]))

         # Save the results.
         self.interpreter.state.save('state', dir=dirpath, compress_type=1, 
force=True)
@@ -393,6 +399,20 @@
         # Load the state again.
         self.interpreter.state.load(dirpath+sep+'state')

+        # Decode
+        print("Decoding")
+        r = base64.decodestring(cdp.nmrglue_data[sp_id])
+        q = frombuffer(r,dtype=float32)
+        cdp.nmrglue_data[sp_id] = q
+        print("Type of decoded is:", type(cdp.nmrglue_data[sp_id]))
+        print("Shape of numpy array is:", cdp.nmrglue_data[sp_id].shape)
+
+        # Test data.
+        print("Testing data array.")
+        print("Shape of data is %ix%i, and of cdp.nmrglue_data is 
%ix%i"%(data.shape[0], data.shape[1], cdp.nmrglue_data[sp_id].shape[0], 
cdp.nmrglue_data[sp_id].shape[1]))
+        self.assertEqual(data, cdp.nmrglue_data[sp_id])
+
+        print("Testing dics.")
         # Make tests that they are the same.
         self.assertEqual(dic, cdp.nmrglue_dic[sp_id])
         for id in dic:


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits



Related Messages


Powered by MHonArc, Updated Mon Dec 08 18:20:14 2014