Hi Troels, Class instances cannot be saved in the relax data store. The only exception are special objects in the data_store package which have to_xml() and from_xml() methods. These paired methods are essential for packing the data into a reasonable XML tag structure and fully recreating the special object when reading the XML. Maybe you should discuss these issues with Jonathan on the nmrglue forums (https://groups.google.com/forum/#!forum/nmrglue-discuss). You can instead store the cdp.ngdata[key].data (a numpy ndarray), the cdp.ngdata[key].dic (a Python dictionary), cdp.ngdata[key].udic (again a Python dictionary), and cdp.ngdata[key].file_path (a Python string/unicode object). But you'd need to talk to Jonathan about how this can be restored into the nmrglue data container. It might even be possible that you contribute to_xml() and from_xml() methods to nmrglue (or we monkey patch them). The class instance seems pretty basic, so this should be quite easy to handle. Look at the modules in the relax data_store package for inspiration. Oh, looking at this more closely, I can see that you have created the Assignment data container in lib/spectrum/objects.py, so this is on our side! Then you should shift this into data_store/nmrglue.py. Then you just need to add the to_xml() and from_xml() methods. This is very easy, just subclass the data_store.data_classes.Element class and you will instantly have all the required methods. You then need to modify the data_store.pipe_container to_xml() and from_xml() methods to recognise this 'cdp.ngdata' structure as a special object with these methods. Just copy the example of the 'cdp.exp_info' or 'cdp.diff_tensor' objects. Having the Assignment data container rather than using Element directly will be useful if you'd like to add more advanced data structures to cdp.ngdata. I.e. new classes that are Element instances. Regards, Edward On 3 December 2014 at 23:29, <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet Date: Wed Dec 3 23:28:59 2014 New Revision: 26954 URL: http://svn.gna.org/viewcvs/relax?rev=26954&view=rev Log: Added systemtest Nmrglue.test_save_state, which fails. This is to test saving a state after reading nmrglue data, and then reset and restore the state. This failure shows, that data cannot be saved as Class instances. 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/ 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=26954&r1=26953&r2=26954&view=diff ============================================================================== --- branches/nmrglue/test_suite/system_tests/nmrglue.py (original) +++ branches/nmrglue/test_suite/system_tests/nmrglue.py Wed Dec 3 23:28:59 2014 @@ -345,6 +345,42 @@ self.setup_plot_hist_cpmg_several(show=False) + def test_save_state(self): + """Test saving a state with numpy arrays, reset relax, and read the state again.""" + + # Read the spectrum. + fname = 'freq_real.ft2' + sp_id = 'test' + self.interpreter.spectrum.nmrglue_read(file=fname, dir=ds.ng_test, spectrum_id=sp_id) + + # Test that the spectrum id has been stored. + self.assertEqual(cdp.spectrum_ids[0], sp_id) + + # Extract the data. + dic = cdp.ngdata[sp_id].dic + udic = cdp.ngdata[sp_id].udic + data = cdp.ngdata[sp_id].data + + # Store the directory path, before reset of the controller. + dirpath = ds.tmpdir + + cdp.hello = "HELLO WORLD" + print(cdp) + print(type(cdp.ngdata)) + print(type(cdp.ngdata[sp_id])) + + # Save the results. + self.interpreter.state.save('state', dir=dirpath, compress_type=1, force=True) + + # Reset of the controller. + self.interpreter.reset() + + # Load the state again. + self.interpreter.state.load(dirpath+sep+'state') + + print(cdp.hello) + + def test_version(self): """Test version of nmrglue.""" _______________________________________________ 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