jjhelmus / nmrglue

A module for working with NMR data in Python
BSD 3-Clause "New" or "Revised" License
209 stars 86 forks source link

Writing processed data back into Bruker format #88

Closed kaustubhmote closed 5 years ago

kaustubhmote commented 5 years ago

This PR adds a write_pdata function to the fileio/bruker.py module that can write externally processed data from a numpy.ndarray into Bruker processed-data format. The real part of the dataset is written by default, but imaginary datasets can be written out by manually specifying the binary filename (eg '1i', '2ii', etc) and selecting out the appropriate data structure. Writing 2D slices of a 3D data and 1D slices of 2D datasets are also supported.

If a Bruker dictionary is supplied (eg 'procs', 'proc2s', etc ), data can be written in a format that can be automatically read by Topspin. This includes things like making appropriate folders inside the standard pdata folder.

Two examples in the examples/bruker_write_pdata folder show how this can be achieved for 1D and 2D datasets. Data with higher dimensions can be written in a smilar manner.

A major caveat:

  1. The procNs files no longer reflect the actual parameters that has gone into the processing the data. Since the main use case of function is likely to be reading back the data into Topspin, writing of procNs files is unavoidable (but still set to False by default). If this is desired, appropriate parameters should be manually put into the procNs files. The only place where this is done currently is when writing out slices of a higher dimensional dataset, where the value of the PPARMOD parameter in the procNs directories is updated to reflect the dimension of the data being written out.

A minor caveat:

  1. 1D and 2D data processed using nmrglue has a 1-point shift in the scale, probably due to the convenstions for shifting the zero-frequency to the centre (See #54). An option to move the spectrum by 1-point is provided in the write_pdata function, but is set to False by default.
kaustubhmote commented 5 years ago

The tests are failing since I seem to have completely missed that the test data for these new functions (to be placed in fileio/tests/data directory) is not checked in. This is because data has been included in the .gitignore). I could check it into the tests directory instead of data, but it is probably better to have it in a folder where the rest of the data is located. @jjhelmus , what do you recommend?

kaustubhmote commented 5 years ago

Not sure why the Travis-CI still cannot see the fileio/bruker_test_data folder. Anyways, it is now available in my master branch for testing and/or copying to the correct location.

jjhelmus commented 5 years ago

@kaustubhmote Thanks for putting this together. Sorry it took so long to review. The bruker test files were not being copied into the correct location when the package was installed. The changes in 597853f42bc9eb6739acf2c17c94bfcca869e26d and ae1aa047d7d25e6ea6e357ce31dfc085b341f4a7 took care of this.