KバンドFITS画像(1024×1024 pix)から、NIRカメラのシャッターステータス(正常3状態・リニアドライブ途中停止2状態・異常)を自動判別するPythonスクリプトです。
CLIからの状態監視に加え、他のPythonスクリプト(シャッター位置補正処理など)からモジュールとして import して利用できます。
| ステータス | 分類 | 終了コード | 画像上の特徴・意味 |
| open | 正常 | 0 | シャッター全開(全面が HIGH) |
| dark | 正常 | 0 | シャッター全閉(全面が LOW) |
| pol | 正常 | 0 | 偏光モード(2つのスリット窓 x=[565:710], [730:880] が HIGH) |
| open-dark | 中間停止 | 1 | open と dark の中間状態(左側 low-X が HIGH、右側 high-X が LOW に二分) |
| dark-pol | 中間停止 | 1 | dark と pol の中間状態(pol 窓が1つまたは2つ、正常位置より右側 high-X にシフトして出現) |
| unknown | 異常 | 2 | 上記のいずれにも該当しないパターン(途中異常停止など) |
右端に pol 窓が数%だけ覗いている dark-pol などを誤って dark や open に分類しないよう、以下の順序で判定を行います。
python3 nic_shutter_status.py obsmon/static/fits/latest/k.fits
| オプション | デフォルト | 説明 |
| -n, --n-splits | 256 | X方向の分割数(1024の約数を推奨) |
| -t, --threshold | 100.0 | HIGH / LOW 判定の中央値閾値 |
| -o, --output | なし | 判定結果をJSONファイルとして保存するパス |
| --json | False | 標準出力にJSON形式の結果のみを出力 |
| -q, --quiet | False | 標準出力にステータス文字列のみを出力(シェルスクリプト連携用) |
| -v, --verbose | False | 全チャンク(256分割)のX範囲・中央値・判定結果を表示 |
# ステータス文字列のみ取得し、終了コードで分岐する例 STATUS=$(python3 nic_shutter_status.py obsmon/static/fits/latest/k.fits -q) EXIT_CODE=$? # 判定結果をJSONファイルに出力 python3 nic_shutter_status.py obsmon/static/fits/latest/k.fits -o /tmp/shutter_status.json
別スクリプトから check_shutter() を呼び出すと、判定結果と位置補正用の座標情報を格納した ShutterResult データクラスが返ります。
from nic_shutter_status import check_shutter
res = check_shutter("obsmon/static/fits/latest/k.fits")
if res.needs_correction:
if res.status == "open-dark":
print(f"open-dark: boundary at x = {res.boundary_x} pix")
# res.boundary_x をもとに open または dark 方向へ駆動
elif res.status == "dark-pol":
print(f"dark-pol: shifted +{res.pol_shift_x} pix from nominal pol")
# res.pol_shift_x 分だけ左側(low-X方向)へ位置補正
elif not res.is_nominal:
print(f"Unexpected status: {res.status}, runs={res.runs}")
| 属性名 | 型 | 内容 |
| status | str | 判別されたステータス名(open / dark / pol / open-dark / dark-pol / unknown) |
| is_nominal | bool | 正常状態(open / dark / pol)であれば True |
| needs_correction | bool | 中間停止状態(open-dark / dark-pol)であれば True |
| boundary_x | int / None | open-dark 時の明暗境界のX座標 [pix] |
| pol_shift_x | int / None | dark-pol 時の正常 pol 位置(x=565)からの右方向シフト量 [pix] |
| runs | list[list[int]] | 検出された連続 HIGH 区間の [開始X, 終了X] リスト |
| high_ratio | float | 全チャンクに対する HIGH チャンクの割合(0.0〜1.0) |
| diagnostics | dict | 各窓の HIGH 率・中央値・ギャップ中央値などの詳細診断データ |