Change History 2024#

Author

Yasuhiro Inamura

Last Update

Mar 18, 2024

4.0.240318 or later#

Mar 18 2024

[update:uGao:master] Improve the retry code for the failure of the socket connection in QtCom.py on macOS

macOS上では、起動待ち時間を追加。不具合により、Mac (Intel and AppleSilicon) では一度接続に失敗するとリトライによる再接続ができないため、接続までに10秒以上の待ち時間が設けられており、MPlotのスムーズな起動が妨げられていた。 また、macOS上では特に初回起動時に時間がかかるようで、time outすることが多かった。

そこで、macOS上ではsocket接続に失敗したときは作成したsocketのインスタンスを削除し、新たに作成し直すようにしてみたところ、起動がスムーズになった。 結果として、Linuxと同様の速度で起動する(たまに遅くなる)ようになった。

Mar 14 2024

[bugfix:uGao:master] The issue that ImportError in FastPlotQt.py on scipy version 1.12.0

DATA_RDCT-265 夕顔:scipy 1.12.0問題

scipyのバージョンが1.12になった時にFastPlotQt実行時に下記のImportErrorが出るので対応した。

::
>>> scipy.__version__
'1.12.0'
>>> import uGao.FastPlotQt as fastplot
  File "/opt/mlfsoft/python-utsusemi/uGao/FastPlotQt.py", line 69, in <module>
  from scipy import sum as sp_sum
ImportError: cannot import name 'sum' from 'scipy' (/home/yinamura/dev/works/240314uGao/venv/lib/python3.10/site-packages/scipy/__init__.py)

# 加えて下記も出る。

ImportError: cannot import name ‘diag’ from ‘scipy’ (/home/yinamura/dev/works/240314uGao/venv/lib/python3.10/site-packages/scipy/__init__.py)

これら(scipy.num, scipy.diag)は、numpyのモジュールに置き換えるだけで良いので、修正した。

Feb 28 2024

[bugfix:uGao:master] The issue that the data returned from uGaoUtil::ConvertEC causes the error in latest matplotlib when the error values are less than 0.

ConvertECでerror値がマイナスの場合、強度をMASKVALUEに置き換えるが、同時にerror値もマイナスだと新しいmatplotlibではエラーが発生する。それへの対処を行なった(エラー値を0.0とした)

Feb 28 2024

[update:uGao:master] Add the function to save and load initial setting file in the current directory.

DATA_RDCT-264 夕顔:M2Plot+で起動直後の設定ダイアログのAve/Sum設定が反映されない,初期設定ファイルのローカル化

  • 初期設定ファイルをローカル(カレント)ディレクトリに保存できるようにした

  • 起動時にローカル(カレント)ディレクトリに初期設定ファイルがあれば、そちらを優先するようにした

  • 初期設定ファイルの名前をわかりやすくした( initial.upr -> m2plotp_initial.prm )

Feb 28 2024

[bugfix:uGao:master] The issue that on launching M2Plot+ the saved setting about Ave/Sum is not applied into M2PlotPlus main panel.

DATA_RDCT-264 夕顔:M2Plot+で起動直後の設定ダイアログのAve/Sum設定が反映されない,初期設定ファイルのローカル化

起動直後、保存されていたAve/Sumの設定が設定ダイアログGUIおよび、M2PlotPlusメインパネルに反映されていないにも関わらず、機能としては反映されているので混乱が生じていたのを修正した。

Feb 27 2024

[bugfix:uGao:master] The issue that on launching M2Plot+ the saved setting about Ave/Sum is not applied into parameter setting dialog.

DATA_RDCT-264 夕顔:M2Plot+で起動直後の設定ダイアログのAve/Sum設定が反映されない,初期設定ファイルのローカル化

起動直後、保存されていたAve/Sumの設定が設定ダイアログGUIに反映されていないにも関わらず、機能としては反映されているので混乱が生じていたのを修正した。

Feb 22 2024

[update:Utsusemi-DNA:4.0] Improve the codes for ElasticScan by Dr. T.Yamada

Feb 22 2024

[bugfix:Utsusemi-DNA:4.0] Typo of the name of modules

Feb 17 2024

[bugifx:Utsusemi:4.0] The issue that the script to create environment setting on macOS does not work correctly

Feb 15 2024

[update:Utsusemi-SAS:4.0devTransAng] Remove useless comments

Feb 14 2024

[update:Utsusemi:4.0] Improve do_make_Utsusemi.py with DIST_NAME is Ubuntu22

Feb 14 2024

[update:Utsusemi-SAS:4.0devTransAng] Add function to dump the calculated factor and error by a Polynominal Approximation method with the angle dependency into ElementContainer

DATA_RDCT-262 BL15:透過率補正の角度依存性を実装する

角度依存性を考慮したPolynominal Approximation手法の計算補正値(factor)を可視化するために、ElementContainerMatrixの強度として取り出せるようにした。

Feb 14 2024

[bugfix:Utsusemi-SAS:4.0] The issue that the histogram creation of RPMT data does not find the RPMT data file

GetHistogramSAS(…, Bank=”RPMT”, …)で、ConvertFromRPMTK2Psd内でRPMTのファイルが見つからない問題に対処した。

/data/SASxxのフォルダをglobで探しにゆく際に、見つけたデータフォルダの最初のフォルダしかファイルを探さない問題に対処した。 globで見つけたSASxx/SASxxxxxxxx_YYYYMMDDを全て検索するようにした。

元々はACEに全て入っていたので、「最初のフォルダ」でも問題がなかったが、現在は分散して保存しているので、このエラーが発現した。

Feb 11 2024

[update:Utsusemi-SAS:4.0devTransAng] Add new method for transmittance correction using “Polynominal Approximation”

DATA_RDCT-262 BL15:透過率補正の角度依存性を実装する

透過率補正の角度依存性処理をTransmittanceCorrectionクラスに加えた。

従来の処理(exp, poly3)と変わらないが、ループの中でif文を増やすのはよろしくないので、PolynominalApproximationによる補正処理は、 _ExecutePolyApproximation を新たに作成した。なおポインタの活用などで高速化しているはず。

また従来の Execute の中身(exp, poly3)は _Execute に移動し(メソッド名の変更) ExecutefuncType でそれぞれの方式にあった処理コードを実行するようにした。

Feb 10 2024

[update:Utsusemi-SAS:4.0] Delete the unusual file

Feb 9 2024

[update:Utsusemi-SAS:4.0devTransAng] Add new fitting function for the transmittance correction using “Polynominal Approximation”

DATA_RDCT-262 BL15:透過率補正の角度依存性を実装する

厚みを含めた形の関数 Polynominal Approximation を作成し、それでフィッティングできるようにした。

透過率補正の流れ

# I/I_0の計算
Trs = GetTransNormByMonTs(...)

# Trsに対してフィッテイング
Trans.FitPolynominal3(dat=Trs)
# -> TransBaseCommands::FitPlynominal3(dat=Trs)
# -> TransBaseCommands::Fit()

# 戻り値として ( フィッティング結果値, フィッテイング結果標準偏差, 関数コード)
# 同時にTrsのヘッダに "TransmittanceParameter", "TransmittanceParameterError", "TransmittanceFitFunc"の情報を追加

# プロット用Trs_calcを作成
Trs_calc = Trans.GetCalcTransmittance(dat=Trs)
# この結果は表示するだけに使用

# データ補正
# 戻り値PyObjsを受けて、サンプルデータを補正する
Trans .TransmittanceCorrection(dat=DATs, params=PyObjs)
新たなフィッティング関数

フィッティング関数を以下のように定義する。 ここでTはthickness of sample、これはフィッティング中は固定。

S = p0 + p1 * lamb + p2 * lamb^2 + p3 lamb^3
f = exp( -S*T)

ただし、実際にフィッティングを行うPythonコード TransBaseCommands::Fit() においては、Thicknessをパラメータの一つとしてscipy.optimizeleastsqに渡すと固定できないので、別途フィッティング関数 TransBaseCommands::FitPolyApprox() を作成した。

fitfunc = lambda p, x, t: np.exp(-(p[0] + (p[1] * x) + (p[2] * x * x) + (p[3] * x * x * x)) * t)
errfunc = lambda p, x, y, sigma, t: fitfunc(p, x, t) - y
scipy.optimize.leastsq(errfunc, iniVal, args=(lambda, intensity, error, thick)...)
TransmittanceCorrectionの改変

PyObjsに含まれる情報を利用して、サンプルデータを補正する class manyo::SAS::TransmittanceCorrection で、 TransmittanceCorrection::PolynominalApproximation を作成し、内部で補正対象データのヘッダからThickness情報を取り出して補正用factorを計算するようにした。

また、フィッティング関数コードの統一のため、TransmittanceCorrection::TRANSMIT_TYPE_POLYAPPROX を定義した。

処理の流れ

結果として、 Polynominal Approximation を用いた補正は、下記のような流れとなる。

# I/I_0の計算
Trs = GetTransNormByMonTs(...)

# Trsに対してフィッテイング
Trans.FitPolyApproximation(dat=Trs)
# -> TransBaseCommands::FitPlyApproximation(dat=Trs)
# -> TransBaseCommands::FitPolyApprox()

# 戻り値として ( フィッティング結果値, フィッテイング結果標準偏差, Thickness, 関数コード)とThicknessを増やした
# 同時にTrsのヘッダに "TransmittanceParameter", "TransmittanceParameterError", "TransmittanceFitFunc"の情報を追加
# さらにThicknessを "TransmittancePolyApproxThick" のキーで与える

# プロット用Trs_calcを作成、この中でTrsのヘッダThicknessを利用する。ように改変
Trs_calc = Trans.GetCalcTransmittance(dat=Trs)
# この結果は表示するだけに使用

# データ補正
# 戻り値PyObjsを受けて、サンプルデータを補正する
Trans .TransmittanceCorrection(dat=DATs, params=PyObjs)
# -> TransBaseCommands::TransmittanceCorrPolyApproximation()
# 内部でPyObjs->paramsからThicknessを取り出し、補正対象のデータのヘッダに埋め込み
# manyo.SAS.TransmittanceCorrectionで使用するように変更
Feb 8 2024

[update:Utsusemi:4.0] Update BL01 WiringInfo

Feb 5 2024

[update:manyo:0.3.4] Improve do_make_Manyo.py

以下の点でコンパイル用スクリプト do_make_Manyo.py を改良した。

  • 引数解析を argparse モジュールを利用するようにした

  • MANYO_REVを新しく設定し、gitのlog情報から最終日付をMANYO_REVとして指定するようにした

他のコードも修正した。

  • Makefile 内でMANYO_REVを利用して core/.__init__.py にRevision番号(日付)を加えるようにした。

__version__ = "0.3.4.240205"
Feb 5 2024

[update:manyo:0.3.4] Add T0TreatToolsBase::DumpInfo to show the information included in event data

T0TreatToolsに下記のような情報を表示するDumpInfo()メソッドを追加した。引数に目的のイベントデータファイルへのパスを与えることが可能だが、空の場合、すでに読み込まれているイベントデータから情報を引き出す。

  • 測定開始・終了時刻

  • T0イベントが抜けているかを確認した結果(T0 IDが+1ずつIncrementしているかどうか)

他に、publicメソッドとして、 EncodePidClockEventDecodePidClockEvent を追加した。 (ダミーのイベントデータを作成するのに便利かも)

Feb 3 2024

[update:Utsusemi:4.0] Change the order of options on executing do_make_Utsusemi.py with –help

Feb 3 2024

[bugfix:Utsusemi:4.0] The issue of the wrong treatment of flags –with-para and –without-para at do_make_Utsusemi.py

Feb 3 2024

[update:Utsusemi:4.0] Improve do_make_Utsusemi.py to use argparse module

  • コンパイルに使用する do_make_Utsusemi.py の引数解析を argparse モジュールを使用するようにした

  • 不要なhelpメッセージをコメントとした

  • 古いデフォルト値を現在のものに変更した

Feb 3 2024

[bugfix:uGao:master] The issue that change the backend to Agg does not work in FastPlotQt.py

DATA_RDCT-261 夕顔:U2IFInDarkがX serverがない時に動作しない

Ubuntu 22.04LTS の時(matplotlib ‘3.7.1’ and PySide6 ‘6.5.2’)にバックエンドを変更するコマンド matplotlib.use(‘Qt5Agg’) 実行時に下記のようなエラーが出る。

ImportError: Cannot load backend ‘Qt5Agg’ which requires the ‘qt’ interactive framework, as ‘headless’ is currently running

これまでは、これを利用してバックエンドをX非使用設定 use(‘Agg’) を実行していた。

しかし、Ubuntu 18.04LTS(matplotlib ‘3.7.1’ and PySide6 ‘6.5.2’)でのバックエンド変更コマンドではエラーは発生せず、バックエンドの切り替えができていなかった。

ただし下記の部分で別途ImortErrorが発生したので、そこでも use(‘Agg’) を設定するようにした。

from pylab import setp, getp

Jun 29 2023

[update:Utsusemi-DNA:4.0] Delete bashrc.manyo.release

4.0.240119 or later#

Jan 19 2024

[bugfix:uGao:master] The issue that plotting-in-dark mode (U2IFInDark.py) causes the error on sst access without launching Xserver (X-forwarding).

DATA_RDCT-261 夕顔:U2IFInDarkがX serverがない時に動作しない

>>> import uGao.U2IFInDark as UD
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/mlfsoft/python-utsusemi/uGao/U2IFInDark.py", line 11, in <module>
    from uGao.u2dplot import U2Params, D2Chart
  File "/opt/mlfsoft/python-utsusemi/uGao/u2dplot.py", line 19, in <module>
    import uGao.MPlot as mp
  File "/opt/mlfsoft/python-utsusemi/uGao/MPlot.py", line 12, in <module>
    from uGao.uGaoUtil import TempFile, TraceAtt, ConvertEC, STRING_TO_REPLACE_SPACE
  File "/opt/mlfsoft/python-utsusemi/uGao/uGaoUtil.py", line 38, in <module>
    matplotlib.use('Qt5Agg')
  File "/home/yinamura/.local/lib/python3.10/site-packages/matplotlib/__init__.py", line 1233, in use
    plt.switch_backend(name)
  File "/home/yinamura/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 279, in switch_backend
    raise ImportError(
ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt' interactive framework, as 'headless' is currently running

修正の過程#

  1. matplotlib.use(“Qt5Agg”)がエラーなのでmatplotlib.use(“Agg”)にする

  2. FigureCanvasも from matplotlib.backends.backend_agg import FigureCanvasAgg から持ってくる

  3. FigureCanvasQTAggにあるsize()メソッドは、FigureCanvasAggにはないので、関連するコマンドは削除する

    • 削除ではなくD2Chartのインスタンス作成時の引数 isDarkModeTrue にして、内部で上記のブロックをスキップするようにした

matplotlib.use(“Agg”)#

  • 画面にウィンドウを開いて動作させるプログラムは対話型バックエンド(interactive backend)

  • パラメータだけで画像ファイルを生成するようなプログラムは非対話型バックエンド(non-interactive backend)

Xserverがないのは非対話型バックエンドである必要があるため、対話型バックエンドを使用するとエラーとなるようだ。

try:
    matplotlib.use("Qt5Agg")
except:
    matplotlib.use('Agg')

この結果、別のエラーが発生した。

Traceback (most recent call last):
  File "/home/yinamura/dev/works/UtsusemiTest240117.py", line 45, in <module>
    p=UD.U2IFInDark()
  File "/opt/mlfsoft/python-utsusemi/uGao/U2IFInDark.py", line 49, in __init__
    self.canvas = FigCanvas(self.fig)
  File "/home/yinamura/.local/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py", line 204, in __init__
    _create_qApp()
  File "/home/yinamura/.local/lib/python3.10/site-packages/matplotlib/backends/backend_qt.py", line 110, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

FigureCanvasのインスタンス作成時エラー#

U2IFInDark.pyでは、non-intaractive backend、use(“agg”)なのに、backend_qt5aggを使用していた

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigCanvas の部分を from matplotlib.backends.backend_agg import FigureCanvasAgg as FigCanvas に変更することで回避。

この結果、別のエラーが発生。

Traceback (most recent call last):
  File "/home/yinamura/dev/works/UtsusemiTest240117.py", line 52, in <module>
    p.SaveFile( "TestData.png" )                    # 画像ファイルとして保存
  File "/opt/mlfsoft/python-utsusemi/uGao/U2IFInDark.py", line 326, in SaveFile
    self.d2 = D2Chart(self, self.canvas, self.ndata, True)
  File "/opt/mlfsoft/python-utsusemi/uGao/u2dplot.py", line 5113, in __init__
    self.PlotD2Chart()
  File "/opt/mlfsoft/python-utsusemi/uGao/u2dplot.py", line 5497, in PlotD2Chart
    _canvas_size = self.canvas.size()
AttributeError: 'FigureCanvasAgg' object has no attribute 'size'. Did you mean: 'resize'?

FigureCanvasAggにないメソッドでエラー#

FigureCanvasQTAggで使用できたメソッドがFigureCanvasAggにないのでエラーとなる。 その部分をD2Chartクラスの引数のisDarkMode=True指定時にスキップするように改変。

# ウィンドウサイズ指定の反映
_canvas_size = self.canvas.size()

から

logging.debug("D2Chart::PlotD2Chart new_size {0}".format(_new_size))
self.canvas.window().resize(*_new_size)

まで。

Jan 17 2024

[update:Utsusemi:4.0] Add new WiringInfo for SIK.

4.0.240116 or later#

Jan 16 2024

[update:Utsusemi:4.0] Update environ_ana.xml for SIK.

Jan 16 2024

[update:Utsusemi:4.0] Add an argument of DetEffi in PowderSQE to do the detector efficiency correction

PowderSQEに検出器効率補正を選択できる引数を追加し、処理するようにした。

  • python-utsusemi/ana/Reduction/BaseCommandsInEla.py

  • python-utsusemi-SIK/facade/DR.py

def PowderSQE(runNo="0", Ei=0.0, deltaE=0.0, Erange="0.0 0.0", deltaQ=0.1, Qrange="-1.0 -1.0", TimeSlice="-1.0 -1.0", MaskFile="default", NormFactor=1000000.0, TimeDepBack="TOF:None", Vpath="/home/sikuser/user/template/vanadium_correction/", Vfile="None", VintegRange="All", VpixelRange="2:97", DetEffi="SIK-SUS304-3He-PSD.dat"):
    """
    Load EventData and convert to powder-averaged S(Q,E) with the vanadium correction. This includes:
    - GetDataOfMonoChroEi3(): convert to histogram
    - LadDataFromDump(): load vanadium data
    - RadialCollimatorCorrect(): correct intensity unevenness due to the radial collimator
    - ToPowder(): powder average
    @param runNo    (string) Run Number(s) "<run1>[,<run2>,...]"(delimitor is comma or space)
    @param Ei       (double) Incident Energy [meV]
    @param deltaE   (double) Delta Energy Transfer [meV]
    @param Erange   (string) min and max of Energy Transfer [meV] "<min>,<max>"(delimitor is comma or space)
    @param deltaQ   (double) binning of Q
    @param Qrange   (string) min and max of Q "<min>,<max>"(delimitor is comma ro space)
    @param TimeSlice(string) start time and end time [seconds] "<min>,<max>"(delimitor is comma or space)
    @param MaskFile (string) file name for masking
    @param NormFactor (double) normalize factor data*factor/beamCurrent. if 0, do nothing.
    @param TimeDepBack (string) Subtruct time-independent-background "TOF:34000-36000" or "DARK:20717"
    @param Vpath    (string) path containing the vanaidum Manyo Binay (mdb) file
    @param Vfile    (string) name of vanadium Manyo Binay (mdb) file. If None, the vanadium correction is skipped
    @param VintegRange (string) Integrate range "All" or "<start>:<end>"
    @param VpixelRange (string) Pixel range to be used "All" or "<start>:<end>"
    @param DetEffi (string) File name of the detector efficiency correction data. "None" : do not correction
    @retval ECM     (ElementCotainerMatix)
    """

    mu.UtsusemiMessage('DR.PowderSQE("{}",{},{},"{}",{},"{}","{}","{}",{},"{}","{}","{}","{}","{}","{}")'.format(runNo, Ei, deltaE, Erange, deltaQ, Qrange, TimeSlice, MaskFile, NormFactor, TimeDepBack, Vpath, Vfile, VintegRange, VpixelRange, DetEffi))
    return BaseCom.PowderSQE(runNo, Ei, deltaE, Erange, deltaQ, Qrange, TimeSlice, MaskFile, NormFactor, TimeDepBack, Vpath, Vfile, VintegRange, VpixelRange, DetEffi)
Jan 16 2024

[bugfix:Utsusemi:4.0] Fixed the issues around the function of DumpAsText.

D4Mat2SlicerのDumpAsTextに関するバグを修正した。

  • プルダウンを選択した時にボタンがONにならない

  • 保存ダイアログで表示するファイルの拡張子が .txt でない

  • テキスト保存のメソッド呼び出しの引数を少しわかりやすくした

  • テキスト保存のメソッド呼び出し時にコメントを表示した

Jan 16 2024

[bugfix:Utsusemi:4.0] The issue that ImportError happends on import BaseCommands without the connection to X server.

Xサーバーへのアクセスができない状態で、utsusemi.ana.Reduction.BaseCommandsを直接間接問わずimportすると、下記のようなエラーが出る。

>>> import DR
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/mlfsoft/python-utsusemi/utsusemi/SIK/facade/DR.py", line 4, in <module>
    import utsusemi.ana.Reduction.BaseCommandsInEla as BaseCom
  File "/opt/mlfsoft/python-utsusemi/utsusemi/ana/Reduction/BaseCommandsInEla.py", line 12, in <module>
    from utsusemi.ana.Reduction.BaseCommands import *
  File "/opt/mlfsoft/python-utsusemi/utsusemi/ana/Reduction/BaseCommands.py", line 13, in <module>
    from utsusemi.ana.Reduction import PutSum
  File "/opt/mlfsoft/python-utsusemi/utsusemi/ana/Reduction/PutSum.py", line 12, in <module>
    import uGao.MPlot as mp
  File "/opt/mlfsoft/python-utsusemi/uGao/MPlot.py", line 12, in <module>
    from uGao.uGaoUtil import TempFile, TraceAtt, ConvertEC, STRING_TO_REPLACE_SPACE
  File "/opt/mlfsoft/python-utsusemi/uGao/uGaoUtil.py", line 38, in <module>
    matplotlib.use('Qt5Agg')
  File "/home/yinamura/.local/lib/python3.10/site-packages/matplotlib/__init__.py", line 1233, in use
    plt.switch_backend(name)
  File "/home/yinamura/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 279, in switch_backend
    raise ImportError(
ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt' interactive framework, as 'headless' is currently running

import uGao.MPlot as mp が強制的にDISPLAY関連の設定が必要となるらしい。 幸いPutSum.pyではMPlotは不要なので、削除するにとどめた。

Jan 15 2024

[update:Utsusemi:4.0devD4Mat2Dump] Remove some output lines for debug (Only shown on DebugMode)

DATA_RDCT-230 空蝉4:D4Mat2Slicer要望・バグ2023

デバッグ用に追加した出力をデバッグモードの時だけ表示するようにした。

Jan 15 2024

[update:Utsusemi:4.0devD4Mat2Dump] Add new flag in BaseCommands:InEla::LoadRunListToExtract because the angle calculations between D4Mat and D4Mat2 are differnt.

DATA_RDCT-230 空蝉4:D4Mat2Slicer要望・バグ2023

D4Mat用のExtractファイルにおける角度計算とD4Mat2用では異なる。RunListを読み込んで処理するルーチンで、D4Mat2用の処理を行うためにフラグを追加し、処理を分けるようにした。

Jan 15 2024

[bugfix:Utsusemi:4.0devD4Mat2Dump] The issue that the average treatment does not included in UtsusemiD4Matrix2::PutSlicedD4MatrixToVectors

DATA_RDCT-230 空蝉4:D4Mat2Slicer要望・バグ2023

UtsusemiD4Matrix2::PutSlicedD4MatrixToVectorsで、データ点を加算した時に平均化する処理が抜けていたので修正した。

  • 引数にbool isAveを加えた

  • 関数内で、isAveに応じた処理を行うように改変した

  • エラーの取り出しに間違いがあったので修正した(eArray4には err^2 が入っているため)

  • 加算が全くなかったデータ点はマスク値(エラー値を-1e-10)とした(暫定)

サンプルコード

isAve = False
if D4M.MakeSllicedD4MatrixInner(ax1range, ax2range, ax3range, ax4range, folding):
    ...
    if D4M.PutSlicedD4MatrixToVectors(ax1v, ax2v, ax3v, ax4v, intv, errv, isAve):
        print(" ------------ Output to vectors : succeeded.")
        D4M.ClearSlicedD4MatrixInner()
    ...

fo = open(outFile2, "w")
ind = 0
for i1 in range(ax1v.size()):
    for i2 in range(ax2v.size()):
        for i3 in range(ax3v.size()):
            for i4 in range(ax4v.size()):
                a_line = "{:g}, {:g}, {:g}, {:g}, {:g}, {:g}\n".format(ax1v[i1], ax2v[i2], ax3v[i3], ax4v[i4], intv[ind], errv[ind])
                fo.write(a_line)
                ind += 1
fo.close()
Jan 15 2024

[update:Utsusemi:4.0devD4Mat2Dump] Change the order of values in the intensity vector produced from UtsusemiD4Matrix::DumpD4MatIntoVect()

UtsusemiD4Matrix::DumpD4MatIntoVectで取り出される強度vectorの値の並びをわかりやすいように 変更した。

結果として、D4Matrix2のPutSlicedD4MatrixToVectorsと同じ並びとなった。

並び定義

intensity[ind]
ind = ((ix * ax1size + iy) * ax2size + iz) * ax3size + ihw

サンプルコード

DM.DumpD4MatIntoVect(ax1[:-1], ax2[:-1], ax3[:-1], hwr[:-1], ["X", "Y", "Z", "T"], [], False, ax1v, ax2v, ax3v, ax4v, intv, errv)
...
for i in range(ax1v.size()):
    for j in range(ax2v.size()):
        for k in range(ax3v.size()):
            for l1 in range(ax4v.size()):
                a_line = "{:g}, {:g}, {:g}, {:g}, {:g}, {:g}".format(ax1v[i], ax2v[j], ax3v[k], ax4v[l1], intv[ind], errv[ind])
                fo.write(a_line + "\n")
                ind += 1
Jan 12 2024

[update:Utsusemi:4.0devD4Mat2Dump] Add new methods to output D4matrix2 data sliced by given axes ranges into vectors

DATA_RDCT-230 空蝉4:D4Mat2Slicer要望・バグ2023

D4Mat2の4次元データを与えられた軸の範囲でスライスした結果をvectorで取り出すため(Pythonのメモリ上で扱うため)に必要となるメソッドを追加した。 その際に、同様のデータをテキストファイルに出力するメソッドと共通する部分を MakeSlicedD4MatrixInner として定義し利用している。

bool PutSlicedD4MatrixToVectors(vector<Double> *ax1, vector<Double> *ax2, vector<Double> *ax3, vector<Double> *ax4, vector<Double> *intensity, vector<Double> *error);
bool MakeSllicedD4MatrixInner(vector<Double> ax1range, vector<Double> ax2range,
                              vector<Double> ax3range, vector<Double> ax4range,
                              vector<Double> folding, bool isAve=true);
void ClearSlicedD4MatrixInner();

使い方

D4M = mu.UtsusemiD4Matrix2()

# Import Data into vectors
isAve = False
if D4M.MakeSllicedD4MatrixInner(ax1range, ax2range, ax3range, ax4range, folding, isAve):
    ax1v = Manyo.MakeDoubleVector()
    ax2v = Manyo.MakeDoubleVector()
    ax3v = Manyo.MakeDoubleVector()
    ax4v = Manyo.MakeDoubleVector()
    intv = Manyo.MakeDoubleVector()
    errv = Manyo.MakeDoubleVector()
    if D4M.PutSlicedD4MatrixToVectors(ax1v, ax2v, ax3v, ax4v, intv, errv):
        print(" ------------ Output to vectors : succeeded.")
    else:
        print(" ERROR: failed to open output to vectors")
        sys.exit(-1)

D4M.ClearSlicedD4MatrixInner()
del D4M

# Save vectors as a text file
fo = open(outFile, "w")
ind = 0
for i1 in range(ax1v.size()):
    for i2 in range(ax2v.size()):
        for i3 in range(ax3v.size()):
            for i4 in range(ax4v.size()):
                a_line = "{:g}, {:g}, {:g}, {:g}, {:g}, {:g}\n".format(ax1v[i1], ax2v[i2], ax3v[i3], ax4v[i4], intv[ind], errv[ind])
                fo.write(a_line)
                ind += 1
fo.close()
Jan 12 2024

[update:Utsusemi:4.0devD4Mat2Dump] Add new methods to put D4Mat data into vectors on UtsusemiD4Matrix class

DumpD4MatToFileは、読み込んだD4Matデータをテキストファイルにして書き出す処理であるが、それをPython上でVectorとして取り出せるように新たに関数を加えた。

bool  DumpD4MatIntoVect( PyObject* a1range, PyObject* a2range, PyObject* a3range, PyObject* a4range, PyObject* def_axes, PyObject* foldings,  bool isAve,
                        vector<Double> *ax1, vector<Double> *ax2, vector<Double> *ax3, vector<Double> *ax4, vector<Double> *intensity, vector<Double> *error);

Int4 DumpD4MatIntoVect( vector<Double> a1r, vector<Double> a2r, vector<Double> a3r, vector<Double> a4r, vector<string> def_axes, vector<Double> foldings, bool isAve,
                        vector<Double> *ax1, vector<Double> *ax2, vector<Double> *ax3, vector<Double> *hws, vector<Double> *intensity, vector<Double> *error);
   //!< Put D4Matrix into given vectors on memory.
    /*!< The order of intensity ::
     *   for ihw in range(hws.size()):
     *       for i1 in range(ax1.size()):
     *           for i2 in range(ax2.size()):
     *               for i3 in range(ax3.size()):
     *                   ind = i3 + (ax3.size() * i2) + (ax3.size() * ax2.size() * i1) + (ax3.size() * ax2.size() * ax1.size() * ihw)
     *                   i1, i2, i3, ihw, intensity[ind], error[ind]
     *
     *   DumpD4MatToFile( a1r, a2r, a3r, a4r, def_axes, foldings, isAve,
     *                    ax1, ax2, ax3, hws, intensity, error );
     *   @param a1r (vector<Double>)  first axis range  [min, max]
     *   @param a2r (vector<Double>)  second axis range [min, max]
     *   @param a3r (vector<Double>)  third axis range  [min, max]
     *   @param a4r (vector<Double>)  fourth axis range [min, max]
     *   @param def_axes (vector<string>)   role of each axis, for example [ "X", "Y", "T", "T" ]
     *   @param foldings (vector<Double>) folding values, [] means [ -1, -1, -1, -1]
     *   @param isAve  (bool) If False, the intensity of a bin is the summation of the counts.
     *   @param ax1 (vector<Double>*) ax1 vector imported from D4Matrix data
     *   @param ax2 (vector<Double>*) ax2 vector imported from D4Matrix data
     *   @param ax3 (vector<Double>*) ax3 vector imported from D4Matrix data
     *   @param hws (vector<Double>*) hw vector imported from D4Matrix data
     *   @param intensity (vector<Double>*) intensity vector imported from D4Matrix data
     *   @param error (vector<Double>*) error vector imported from D4Matrix data
     *   @retval 0 No trouble.
     *   @retval -1 Failes to calculate the ranges for the axes.
     */

使用例

DM = mu.UtsusemiD4Matrix()
...
if DM.OpenMat(data_dir, pFile): # D4Matデータを無事に開けたら
    #if DM.DumpD4MatToFile(ax1[:-1], ax2[:-1], ax3[:-1], hwr[:-1], ["X", "Y", "Z", "T"], [], str(Output_File), True, False):
    ax1v = Manyo.MakeDoubleVector()
    ax2v = Manyo.MakeDoubleVector()
    ax3v = Manyo.MakeDoubleVector()
    ax4v = Manyo.MakeDoubleVector()
    intv = Manyo.MakeDoubleVector()
    errv = Manyo.MakeDoubleVector()
    if DM.DumpD4MatIntoVect(ax1[:-1], ax2[:-1], ax3[:-1], hwr[:-1], ["X", "Y", "Z", "T"], [], False, ax1v, ax2v, ax3v, ax4v, intv, errv):
        print(" Output 4D as text succeeded.")
    else:
        print("#### ERROR at output #####")
else:
    print("#### ERROR at Opening #####")
    sys.exit(-1)

###############
fo = open("Conv3.txt", "w")

ind = 0
for l1 in range(ax4v.size()):
    for i in range(ax1v.size()):
        for j in range(ax2v.size()):
            for k in range(ax3v.size()):
                a_line = "{:g}, {:g}, {:g}, {:g}, {:g}, {:g}".format(ax1v[i], ax2v[j], ax3v[k], ax4v[l1], intv[ind], errv[ind])
                fo.write(a_line + "\n")
                ind += 1
Jan 12 2024

[bugfix:Utsusemi:4.0devD4Mat2Dump] The issue that the bin-width correction function are executed on doing data reduction without any correction.

D4Matrix(D4MatSlicer)でのデータ処理に使用するExtract.pyで.vbinファイルを作成する時に、ビン幅最適化計算で必要となる補正を全く行わない処理をUtsusemiSqeCalc::ConvertToD4Matで行った場合、bin幅補正(bin幅で強度を割る)処理が実行されていた。 その処理を実行しないようにするフラグを引数に加え、処理を書き直した。

UtsusemiSqeCalc::ConvertToD4Mat(string filepath, bool isAverageMode, bool useBinCorr)

使用例:

sqe = mu.UtsusemiSqeCalc()
sqe.SetTarget(DAT)
sqe.LoadXtalParam(XtalParam)
sqe.SetRotationSteps("Y:%g"%(PhiValue))
sqe.Projection()
# vbin作成時に平均化処理とbin幅補正を行わない
sqe.ConvertToD4Mat(savePath, False, False)
Jan 10 2024

[update:Utsusemi:4.0devD4Mat2Dump] Add new methods to output D4matrix data sliced by given axes ranges as a text file

DATA_RDCT-230 空蝉4:D4Mat2Slicer要望・バグ2023

D4Mat2SlicerのSlicingの各軸の範囲設定に応じたテキストデータの書き出しを可能とした。 それに応じて、D4Mat2Slicerの”Data Conversion”における”DumpAsText”で使用する関数名を修正した。

UtsusemiD4Matrix2

bool UtsusemiD4Matrix2::PutSlicedD4MatrixToText(string filepath,
                                                vector<Double> ax1range, vector<Double> ax2range,
                                                vector<Double> ax3range, vector<Double> ax4range,
                                                vector<Double> folding, bool isAve=true);
        //!< Put sliced (matrix) data points into the text file
        /*!<
         *   @param filepath (string) The path of the file.
         *   @param ax1range (vector<Double>) Ax1 range [<min>, <max>, <bin>]
         *   @param ax2range (vector<Double>) Ax2 range
         *   @param ax3range (vector<Double>) Ax3 range
         *   @param ax4range (vector<Double>) Ax4(hw) range
         *   @param folding  (vector<Double>) Folding information [<ax1_fold>, <ax2_fold>,...]
         *   @param isAve (bool) true means that the calculated intensity is normalized by the number of data.
         *   @retval true succeeded.
         *   @retval false failed.
         */