Change History 2024#

Author

Yasuhiro Inamura

Last Update

Jun 05, 2024

4.0.240605 or later#

Jun 5 2024

[bugfix:Utsusemi:4.0] The issue that the push of the file open button in SequenceEditor occurs error

Windows版でSequenceEditorを起動し、pmtファイルを開くためのボタンを押すとエラーが発生する問題に対処した。

Windows環境は以下の通り。

  • python : 3.11

  • PySide6 : 6.7.1

  • matplotlib : 3.9.0

エラーは下記。

Traceback (most recent call last):
  File "C:\Program Files\Utsusemi\python-utsusemi\utsusemi\ana\SequencerQ.py", line 3208, in OnOpen
    ftpl = self.sfile.OpenSequence(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Utsusemi\python-utsusemi\utsusemi\ana\SequencerQ.py", line 956, in OpenSequence
    fname = os.path.split(initFile)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen ntpath>", line 213, in split
TypeError: expected str, bytes or os.PathLike object, not bool

これまで、ボタンを押した時のイベントを受ける関数に引数が渡らないと理解していたが、以下の例の場合ではOnOpenに対して”True”の引数が渡っていた。この引数をOnOpen関数が拾って挙動がおかしくなった。

self.btOpen.clicked.connect(self.OnOpen)

そこで、イベントを受ける関数と、pmtファイルを開く関数を分けることで回避した。

May 27 2024

[update:Utsusemi:4.0] Add NBR to the choice of BL in UtsusemiSettignApp (DlgSetUtsusemi)

May 27 2024

[bugfix:Utsusemi:4.0] The issue that vector templates does not work on compiling with swig 4.2.1

DATA_RDCT-267 万葉ライブラリ:swig 4.2.x対応

swig 4.2.1では、Manyo core以外のモジュールで作成された vector<XXX> が正しく変換されず、vectorとして使用できない問題があったので、その修正を行なった。

manyo/core/Manyo.iに記述されているvector関連のテンプレートをMLF.iやUtsusemi.iにも貼り付けておくという対策である。

May 27 2024

[bugfix:manyo:0.3.4] The issue of wrong implementation of “unique” function used in MlfMatrixSlicer::GetPlaneAsDetectorMap.

MlfMatrixSlicer::GetPlaneAsDetectorMapで使用されているunique関数の使い方がおかしいので修正した。

戻り値にはuniqueの結果短くなったvectorのEndがイテレータとして戻される。よってEraceでvectorの余計な部分を削除する必要がある。しかし実際には削除する処理がなかったので修正した。

May 27 2024

[update:manyo:0.3.4] Update obsolete methods in boost::filesystem::path which cause compile error on boost v1.85.0

DATA_RDCT-273 万葉ライブラリ:Boostライブラリ1.85で起きる問題

Boostライブラリ 1.85.0の環境では、以下のメソッドが使用不可能(コンパイルエラー)となる問題に対応した。

boost::filesystem::path::normalize()
boost::filesystem::path::branch_path()
boost::filesystem::basename(...)

修正としては、それぞれほぼ同じ機能のメソッドに置き換えた。

boost::filesystem::path::normalize -> boost::filesystem::path::lexically_normal()
boost::filesystem::path::branch_path -> boost::filesystem::path::parent_path()
boost::filesystem::basename -> boost::filesystem::path::filename().generic_string()

normalizeに関しては、完全な語感はない(シンボリックリンクの処理など)と思われるが、実際に使用されるのがWriteSerializationFile::SplitSaveというメソッドで、ほどんど利用実績がないため、これ以上は不問とする。

May 27 2024

[bugfix:manyo:0.3.4] The issue that vector templates does not work on compiling with swig 4.2.1

DATA_RDCT-267 万葉ライブラリ:swig 4.2.x対応

swig 4.2.1では、Manyo core以外のモジュールで作成された vector<XXX> が正しく変換されず、vectorとして使用できない問題があったので、その修正を行なった。

manyo/core/Manyo.iに記述されているvector関連のテンプレートをMLF.iやUtsusemi.iにも貼り付けておくという対策である。

May 23 2024

[bugfix:uGao:master] The issue that “from matplotlib.cm import get_cmap” causes error in matplotlib version 3.9.0 on Windows installed by PIP.

May 22 2024

[bugfix:Utsusemi:4.0] The issue that the search path is wrong in PutLatestDataFolder with given dataDir argument

May 22 2024

[update:Utsusemi:4.0] Add new python function to get latest run number and it data folder

最新のRunNoとそのフォルダを返す関数を加えた。

import utsusemi.aan.Reduction.BaseCommands as BC

# Search in $UTSUSEMI_DATA_DIR$/$UTSUSEMI_INST_CODE$* /data/SIK, /data/SIK00, /data/SIK01, ..
runNo, dataPath = BC.PutLatestDataFolder()

# Seach in "/ace/SIK" only
runNo, dataPath = BC.PutLatestDataFolder("/ace/SIK")

第2引数には探すRunNoの範囲を指定できる(list)。

# Search in run number range from 100000, 400000.
runNo, dataPath = BC.PutLatestDataFolder("", [100000, 400000])
May 20 2024

[update:uGao:master] Add new function to give upper or lower limit in AutoScale (intensity) mode of U2IFInDark and u2dplot with the dark mode.

U2IFInDarkでSetRange(True, 0.0, 0.0)で強度の範囲をAutoにすることは可能であるが、下端や上端を固定したい。

U2IFInDark::SetRangeコマンドはparams.autoRange (bool) を制御するだけである。 またparams.rangeは、None(起動直後)か、(int, int)タプルである。

DarkModeの時、autoRange == Trueならば params.range = (None, int) や (int, None) を許可する。 タプル内でNoneの場合自動的に最大値か最小値で置き換え、intであればそれをはfixした値とみなす。

想定した仕様は以下の通り(いずれもDarkMode)。

  • 範囲の両端がAutoの場合、params.autoRange = True, params.range = None

  • 範囲の片方がAutoの場合、params.autoRange = True, params.range = (None, int) or (int, None)

  • 範囲の両端がFixの場合、params.autoRange = False, params.range = (int, int)

U2IFInDark::SetRangeでは以下のように表現する。

import uGao.U2IFInDark as UD

p=UD.U2IFInDark()
p.SetKeys(None, None, "Intensity", "TOF")    # 横軸、縦軸、強度のキー
p.SetData(DAT)                               # データをセット
#p.SetRange(True)               # 強度の範囲指定はAuto
p.SetRange(True, 0.01, None)    # 強度の範囲指定で下限値のみ固定
#p.SetRange(False, 0.05, 10e10) # 強度の範囲を指定する(先頭のFalseはAutoスケール停止の意味)
p.SetLog(True)
title = "Run No = {} @{}".format(runNo, now_dt.strftime("%y-%m-%d %H:%M"))
p.SetTitles(title, "")             # TitleとSubTitle
p.SetLabels("PSD","Pixel")         # 軸のラベル
p.SetFigureSize(8.0, 3.0)
p.SaveFile( "./graph.png" )                    # 画像ファイルとして保存
del p
May 17 2024

[bugfix:uGao:master] The issue that error occurs when ElementContainer are given in constructor of MPlotInDark, revice the docstrings

DATA_RDCT-271 夕顔:MPlotのDarkモードの作成

  • コンストラクタでElementContainerを与えるとエラーとなるのを修正した

  • Docstringsの修正

May 17 2024

[update:uGao:master] Update MPlotInDark.py to control MPlot without X server

DATA_RDCT-271 夕顔:MPlotのDarkモードの作成

Xを使用しない環境でMPlot(FastPlotQT)を制御し、画像ファイルだけを作成するためのコードに対して、コンストラクタで画像のサイズとdpiを指定できるようにした。 また、画像保存時はself.canvas.print_figure(fname, dpi=XXX)のようにdpiも引数で与えられていたが、今回は指定せずデフォルト値を使うようにした。

import uGao.MPlotInDark as FP

# コンストラクタでサイズとdpiを指定できる
p = FP.MPlotInDark(sizeX=5.0, sizeY=2.5, dpi=72)

...
May 17 2024

[update:uGao:master] Add MPlotInDark.py to control MPlot without X server

DATA_RDCT-271 夕顔:MPlotのDarkモードの作成

Xを使用しない環境でMPlot(FastPlotQT)を制御し、画像ファイルだけを作成するためのコードを新たに追加した。 ほぼ、MPlotのCUIと同じ機能が使用できるが、現状OverPlotのみである。

サンプルコードは以下の通り。

import Manyo
import uGao.MPlotInDark as FP

ec = Manyo.ElementContainer()
ec.Add("X", [1.0, 2.0, 3.0, 4.0, 5.0])
ec.Add("Y", [1.0, 2.0, 0.1, 1.0])
ec.Add("E", [1.0, 1.0, 1.0, 1.0])
ec.SetKeys("X", "Y", "E")

ec2 = ec.Mul(2.0)

p = FP.MPlotInDark()
p.AddData([ec, ec2])

p.SetYScale(False, 0.01, 10)
p.SetLog(True)
p.SetXScale(False, -1, 10)
#p.RemoveData(1)
p.SetPlotParam(0, ls="-", lc="k", lw=9)
p.SetMainTitle("Run No: 5515")
p.SetSubTitle("This is test!")
p.SetXLabel("Index X")
p.SetYLabel("Intensity")
p.Save("./test.png")

4.0.240426 or later#

Apr 26 2024

[update:Utsusemi:4.0] Enabled to give new device name of BL14 (He3TL) in devTemp and devGonio of MakeRunList commands.

MakeRunListのdevTempとdevGonioの引数に新たに”He3TL”を使えるようにした。ただし、”Shin-TL”というデバイス名はいずれ修正されるのでそのつもりで。

Apr 26 2024

[bunfix:Utsusemi:4.0] The issue that SequenceEditor’s commands list shows wrong arguments on launching with the given initial sequence script

DATA_RDCT-269 【空蝉4】Sequence Editorのスクリプト読み込み時のバグ

SequenceEditorの起動時に -file= でスクリプトを初期スクリプトとして読み込ませた場合に、コマンドリスト上で選択されているコマンドの引数ではないものが表示される現象に対処した。

なお、GUI上のボタンからスクリプトを読み込ませた時には発生しないので、修正できそう。

  • Openボタン -> OnOpen()

  • 起動時 -> LoadInitSequence()

どちらにもほとんど同じスクリプトを読み込む処理が書かれていたので統一する。 OnOpenコマンドの引数を拡張して、起動時も同じ処理を行うようにした。

  • Openボタン -> OnOpen()

  • 起動時 -> LoadInitSequence() -> OnOpen()

Apr 9 2024

[update:Utsusemi:4.0] Update WiringInfo of BL01

Apr 9 2024

[bunfix:Utsusemi:4.0] The issue that PutLatestRunNoFromDataFolder occurs core dump error when the data folder includes the file or folder with short ( lower than 9 ) name.

Apr 9 2024

[update:Utsusemi:4.0] Replace the literal value for the error value for masked point with 0 intensity with UTSUSEMIMASKERRORVALUE

Apr 9 2024

[update:Utsusemi:4.0] Add the function to reduce the NXSPE file size by reducing the precision of data values in NXSPE file(2).

DATA_RDCT-236 空蝉4:Nxspeのファイルサイズ

ファサード(SaveDataToNxspe)に、NxspeFileIOクラスのファイルサイズを減らす引数を加えた。

Apr 9 2024

[update:Utsusemi:4.0] Add the function to reduce the NXSPE file size by reducing the precision of data values in NXSPE file.

DATA_RDCT-236 空蝉4:Nxspeのファイルサイズ

Nxspeファイルを保存するNxspeFileIOクラスにファイルサイズを減らすオプションをつけた。

Nxspeファイル保存時には圧縮が自動的にかけられるが、強度やエラーの値を一旦64bit(double)から32bit(float)に変換することで有効桁数を減らすことで、圧縮率を上げられることを確認した。 精度は落ちるがファイルサイズは半分強になる。

Apr 8 2024

[bugfix:Utsusemi:4.0] The issue that CalcContainers function can not treat the masked data point correctly(2).

DATA_RDCT-268 空蟬4:BL15でのTOFマスクが効かない?

Add new global constant value UTSUSEMIMASKERRORVALUE used to mask the point with 0 intensity.

Apr 6 2024

[bugfix:Utsusemi:4.0] The issue that CalcContainers function can not treat the masked data point correctly.

DATA_RDCT-268 空蟬4:BL15でのTOFマスクが効かない?

UtsusemiCalcContainers関数が正しくマスク値(Errorが負)を扱えない問題を修正した。

Apr 6 2024

[bugfix:Utsusemi-SAS:4.0] The issue that the treatments of a masked data point in some functions are not suitable.

DATA_RDCT-268 空蟬4:BL15でのTOFマスクが効かない?

いくつかの関数の中で、データ点のエラーを計算する際にマスクされている点を正しく(masked点の計算結果もmasked)扱っていないものがあったので修正した。

  • manyo/I0LambdaCorrection.cc

  • manyo/RPMTSetMaskBy2theta.cc

  • manyo/TransmittanceCorrection.cc

Apr 6 2024

[bugfix:Utsusemi-SAS:4.0] The issue that the error calculation of Polynomial3 in GetCalcTransmittance is wrong.

Apr 6 2024

[update:Utsusemi-SAS:4.0] Fixed small typo.

Feb 12 2024

[update:manyo:0.3.4] Remove the file which was uploaded by typo

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.
         */