Skip to content

Instantly share code, notes, and snippets.

@akira093
Created February 25, 2013 11:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akira093/5029330 to your computer and use it in GitHub Desktop.
Save akira093/5029330 to your computer and use it in GitHub Desktop.
#/usr/bin/python
#coding:utf8
"""
このソフトは、日本分光(JASCO)のスペクトルを記録したファイル(.jws)から波長とintensityをcsv(波長, intensity)にエクスポートすることを目的としています。
thanks to https://sites.google.com/site/victorhr02/jwsprocessor
構造体の構造について、上記ソフトウエアにお世話になりました。
構造体の解析が完全ではありません。下のintensityデータを取得するの部分のアドレスを変更するか、もしくはバイナリエディタでintensityデータが格納されている部分の開始アドレスを探してください。恐らく最後の一つながりのデータ群が始まっているアドレスです。
このソフトの実行にはpython標準ライブラリがあれば可能なはずです。つまりpython(>=2.5)を入れただけで実行可能なはずです。
jwsが溜まっているフォルダにこのファイルをぶち込み、おもむろにこのスクリプトを実行してください。フォルダ内のjwsファイルをから(波長, intensity)という形式でdataというフォルダの中に同名のcsvファイルを作ります。
このソフトは、GPLでライセンスされています・ω・
なお、元々友人の研究結果をまとめるために作成したため、320nmと365nmでのintensityをまとめる機能がついています。必要に応じて編集・または無視をしてください。
"""
import os
import struct
# ファイル取得する
path = os.getcwd()
filelist = os.walk(path).next()[2]
filelist = [i.rsplit(".", 1)[0] for i in filelist if i.endswith(".jws")]
# データを格納するフォルダを作成する
try:
os.mkdir("data")
except:
print "dataフォルダの作成に失敗したけど多分大丈夫だ問題ない"
# 特定波長での結果を格納するリスト
specified_intensities = []
# 各ファイルごとに処理をする
for filename in filelist:
with open(filename + ".jws", "rb") as f:
# xの開始、終端、ステップをヘッダーから取得する。
f.seek(0x88)
x = f.read(24)
l = struct.unpack("ddd", x)
x_for_first_point = l[0]
x_for_last_point = l[1]
x_step = l[2]
x_point_number = (x_for_last_point - x_for_first_point) / x_step + 1
# intensityデータを取得する
f.seek(0x6f8)
#f.seek(0x740)
x = f.read(int(x_point_number * 4))
raw_data = struct.unpack("{0}f".format(int(x_point_number)), x)
# データをcsvに書きだす。
with open("data/" + filename + ".csv", "w") as expoted_data_obj:
for i in range(int(x_point_number)):
expoted_data_obj.write(
"{0:06.3f}, {1:06.6g}\n".format(x_for_first_point + i * x_step, float(raw_data[i]))
)
if x_for_first_point + i * x_step == 320:
y_at_320 = raw_data[i]
elif x_for_first_point + i * x_step == 365:
y_at_365 = raw_data[i]
specified_intensities.append((y_at_320, y_at_365))
# 特定波長でのデータをcsvに書きだす
with open("data/specified_intensities.csv", "w") as specified_intensities_obj:
for col in specified_intensities:
specified_intensities_obj.write("{0:06.3f}, {1:06.6g}\n".format(col[0], col[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment