nzhagen / jcamp

A set of Python utilities for reading JCAMP-DX files.
MIT License
52 stars 31 forks source link

Writing JCAMP-DX files? #28

Open sumpfralle opened 1 year ago

sumpfralle commented 1 year ago

At the moment the jcamp module offers only the ability to parse JCAMP-DX files.

Would you consider it to be within the scope of the project to export to a file, too?

In this case I would be willing to propose an initial implementation.

nzhagen commented 1 year ago

Yes, it is certainly within the scope of the project, and there must be some users who would welcome having a JCAMP writer.. If you have a proposal, I'd be glad to add it in.

andychase commented 1 year ago

I was able to find two libraries that implement this:

https://github.com/spectrochempy/spectrochempy/blob/2d21c1b8b109389e7b4871bdb32680d7b7061210/spectrochempy/core/writers/write_jcamp.py

https://github.com/r-hyperspec/pyspc-write-jdx

I think @nzhagen if you wanted to incorporate one of these modules (since they are both freely licensed) that would be nice. Your package is much easier to find then those two

frenchytheasian commented 1 year ago

Bumping this issue because this is something that I would find useful as well. I can try and work on a PR to pull in one of the libraries that @andychase mentioned to write out dx files from a dictionary.

nzhagen commented 1 year ago

@frenchytheasian - thanks for raising the issue again. Seeing that there is more need for this than I expected, I went ahead and adapted some code to write JCAMP-DX files. I tried it out using a couple of the infrared spectra in the repo's data folder, but if you are interested, please give it a try and test it out. Let me know if there are any issues!

frenchytheasian commented 1 year ago

Hey @nzhagen! Thanks for the response and the PR. I noticed that the new function does not work on infrared spectra that contain multiple blocks of spectra. I looked at some of the existing infrared files and noticed that they only contain one long block of data. I tested it on data/hnmr_spectra/ethanol_nmr.jdx which also failed with the same error. I can try adding onto the function you've built to handle blocks of data.

nzhagen commented 1 year ago

@frenchytheasian - Yeah, I saw that I could quickly implement a function to create a standardized fixed-format single spectrum, but the JCAMP-DX format has so many options that I decided to start with a minimalist approach and work from there. If you are willing to give it a try to add functionality to handle multiple blocks, that would be great! I'd be glad to add that to the codebase.

frenchytheasian commented 1 year ago

@nzhagen - Ahh I see. I haven't dove too deep into the official spec. There are just some specific DX files that I'm trying to parse. I'll write code that can handle those and then possibly go on from there.