Commit 8c2e62e9 authored by Zhang, Yuanpeng's avatar Zhang, Yuanpeng
Browse files

updated to trials of calib

parent 18dfc157
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@
.cache/*
utils/finddata/__pycache__/*
.token
.notes
 No newline at end of file

.vscode/settings.json

0 → 100644
+13 −0
Original line number Diff line number Diff line
{
    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/.DS_Store": true,
        "**/Thumbs.db": true,
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    }
}
 No newline at end of file
+6 −6
Original line number Diff line number Diff line
{
    "Diamond": "/SNS/NOM/IPTS-31346/nexus/NOM_235407.nxs.h5",
    "Diamond": "/SNS/NOM/IPTS-36186/nexus/NOM_237357.nxs.h5",
    "Instrument": "NOM",
    "Date": "2026-03-17",
    "SampleEnv": "furnace",
    "Date": "2026-03-30",
    "SampleEnv": "shifter",
    "OutputDir": "/SNS/NOM/shared/autoreduce/calibration",
    "GenShadowMask": "shadow_mask_furnace_235407.in",
    "DiaLattParam": 3.5671299351,
    "GenShadowMask": "shadow_mask_furnace_237357.in",
    "DiaLattParam": 3.567129935100,
    "GroupMethod": "KMEANS_ED",
    "SaveInitCalTable": true,
    "Quiet": true,
+105 −112
Original line number Diff line number Diff line
#!/bin/bash

MAX_ATTEMPTS=5

run_calibration() {
    set -e

    working_dir="/SNS/NOM/shared/CALIBRATION/"
    cd $working_dir

@@ -53,46 +58,17 @@ if [ -d "tmp" ]; then
        rm -rf tmp
    fi

# cp autogrouping_config_template.json autogrouping_config.json
# sed -i "s%TO_REPLACE_CALIBRANT%${dia_file}%" autogrouping_config.json
# sed -i "s%TO_REPLACE_GM%${group_method}%" autogrouping_config.json
# sed -i "s%TO_REPLACE_MF%mask_combined_cache.in%" autogrouping_config.json

# # Grouping
# # In case the `dev` environment is not working properly,
# # one can roll back to the `prod` version by switching
# # the commented line below.
# conda activate mantidtotalscattering-dev
# # conda activate mantidtotalscattering
# 
# echo "[Info] Grouping..."
# python autogrouping.py
# 
# conda deactivate
# 
# if [ "$group_method" = "KMEANS_ED" ]; then
# 	sed -i '3d' outputgrouping.xml
# 	sed -i '4d' outputgrouping.xml
# 	ex -s -c 3m4 -c w -c q outputgrouping.xml
# fi

    # External call to translate the mask file in plain text form to
    # its XML form.
#. /opt/anaconda/etc/profile.d/conda.sh
# conda activate ~y8z/miniconda/envs/nom_calib
    echo "[Info] Converting shadow mask file..."
    ~y8z/miniconda/envs/nom_calib/bin/python group_calib_prep.py
    echo "[Info] Done with shadow mask converting."
# conda deactivate

    cd $working_dir

    # Calibration
    echo "[Info] calibrating..."
    mantidpython $working_dir/utils/nom_cal.py $working_dir
# mantidpythonnightly $working_dir/utils/nom_cal.py $working_dir
# ~y8z/miniconda/envs/mantid-developer-v6.13.1.2/bin/python /SNS/users/y8z/pd_utils/mantid_v6p13p1p2/build/bin/AddPythonPath.py
# ~y8z/miniconda/envs/mantid-developer-v6.13.1.2/bin/python $working_dir/utils/nom_cal_local.py $working_dir $local_cc_file
    echo "[Info] Done with calibrating."

    if [ ! -d $out_dir/input_configs ] ; then
@@ -112,3 +88,20 @@ echo "Info> Calibration job done!"
    echo "Info> h5 file written to $out_dir"
    echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
    echo ""
}

for attempt in $(seq 1 $MAX_ATTEMPTS); do
    echo "[Info] Attempt $attempt of $MAX_ATTEMPTS..."
    if run_calibration; then
        exit 0
    else
        echo "[Warning] Attempt $attempt failed."
        if [ $attempt -lt $MAX_ATTEMPTS ]; then
            echo "[Info] Retrying..."
        fi
    fi
done

echo "[Error] Calibration failed after $MAX_ATTEMPTS attempts."
mantidpython $working_dir/utils/cal_fail_slack.py $working_dir/cal_config.json
exit 1
+10 −0
Original line number Diff line number Diff line
import sys
sys.path.append("/SNS/users/y8z/miniconda/envs/slack/lib/python3.13/site-packages")
from slack_sdk import WebClient

slack_msg = "Calibration failed after 5 trials.\n"
slack_msg += f"Check the calibration configuration file at "
slack_msg += f"at, `{sys.argv[1]}`.\n"
sltk = "xoxb-970229573620-6616766768435-KI4xnOfT7roQo9fUpLSSAVjn"
client = WebClient(token=sltk)
client.chat_postMessage(channel="nomad-monitor", text=slack_msg)