summaryrefslogtreecommitdiff
path: root/siril-cli-multisession
diff options
context:
space:
mode:
Diffstat (limited to 'siril-cli-multisession')
-rwxr-xr-xsiril-cli-multisession321
1 files changed, 321 insertions, 0 deletions
diff --git a/siril-cli-multisession b/siril-cli-multisession
new file mode 100755
index 0000000..ecf0593
--- /dev/null
+++ b/siril-cli-multisession
@@ -0,0 +1,321 @@
+#!/bin/sh
+
+# Shell script to stack the data from multiple EKOS sessions.
+# It is intended to be used on data from a cooled camera,
+# and uses a common set of darks and biases for all sessions.
+#
+# It assumes dithering and uses the drizzle algorithm.
+#
+# Required directory structure:
+#
+# [Working Directory]
+#
+# \ Master Master dark and bias frames, if they already exists, they take precedence over dark and bias frames.
+# If the masters are absent, they are created from the dark end bias frames.
+# \ Dark Dark calibration frames, used for all sessions
+# \ Bias Biases calibration frames, used for all sessions
+#
+# \ Session[name]
+# \ Flat Flat frames for this sessions
+# \ Light Light frames for this session
+# \ Master (optional) Master dark and bias frames for this session,
+# if found they take precendence over the global masters.
+#
+# Output:
+#
+# \ Process
+# \ Calibrated Calibrated light frames created from all sessions
+# \ Session[name] Per-session preprocessed files
+#
+# result_xxx.fits Stacked output
+
+# ------------------------------------------------------------------
+# CONFIGURATION
+
+# Directory names
+LIGHTDIR=Light
+FLATDIR=Flat
+DARKDIR=Dark
+BIASDIR=Bias
+MASTERDIR=Master
+CALIBRATEDDIR=Calibrated
+PROCESSDIR=Process
+
+# Output file names
+MASTERDARK=master_dark
+MASTERBIAS=master_bias
+MASTERFLAT=master_flat
+
+# Framing style
+# --framing=[cog|max|min]
+OPT_FRAMING=min
+
+# ------------------------------------------------------------------
+# COMMAND LINE OPTIONS
+
+while [ ! -z "$1" ]; do
+
+ case "$1" in
+ -f | --framing)
+ shift
+ OPT_FRAMING=$1
+ echo "Framing ${OPT_FRAMING}"
+ shift
+ ;;
+ *)
+ echo "Invalid option $1"
+ exit 1;
+ ;;
+ esac
+done
+
+# ------------------------------------------------------------------
+# SAFETY CHECK
+
+if [ -d "${PROCESSDIR}" ]; then
+ echo "${PROCESSDIR} directory already exists!"
+ exit 1
+fi
+
+# ------------------------------------------------------------------
+# CREATE MASTER DARK
+
+masterdarkdir="${MASTERDIR}/${DARKDIR}"
+masterdarkfile="${MASTERDIR}/${MASTERDARK}.fits"
+
+echo "------------------------------------------------------------------"
+if [ -r "${masterdarkfile}" ]; then
+ echo "Using master dark ${masterdarkfile}"
+else
+ if [ ! -d "${masterdarkdir}" ]; then
+ echo "Couldn't find ${masterdarkdir}";
+ exit 1
+ fi
+
+ echo "Creating master dark ${masterdarkfile}"
+ #notify-send "${NOTIFICATIONTITLE}" "Creating master dark ${masterdarkfile}"
+
+ siril-cli -d . -s - <<ENDSIRILDARK
+requires 1.2.0
+
+# Convert Dark Frames to .fit files
+cd ${masterdarkdir}
+convert dark -out=../../${PROCESSDIR}
+cd ../../${PROCESSDIR}
+
+# Stack Dark Frames to master_dark.fit
+stack dark rej 3 3 -nonorm -out=../${MASTERDIR}/${MASTERDARK}
+cd ..
+
+close
+
+ENDSIRILDARK
+
+fi
+
+# ------------------------------------------------------------------
+# CREATE MASTER BIAS
+
+masterbiasdir="${MASTERDIR}/${BIASDIR}"
+masterbiasfile="${MASTERDIR}/${MASTERBIAS}.fits"
+
+echo "------------------------------------------------------------------"
+if [ -r "${masterbiasfile}" ]; then
+ echo "Using master bias ${masterbiasfile}"
+else
+ if [ ! -d "${masterbiasdir}" ]; then
+ echo "Couldn't find ${masterbiasdir}";
+ exit 1
+ fi
+
+ echo "Creating master bias ${masterbiasfile}"
+ #notify-send "${NOTIFICATIONTITLE}" "Creating master bias ${masterbiasfile}"
+
+ siril-cli -d . -s - <<ENDSIRILBIAS
+requires 1.2.0
+
+# Convert Bias Frames to .fit files
+cd ${masterbiasdir}
+convert bias -out=../../${PROCESSDIR}
+cd ../../${PROCESSDIR}
+
+# Stack Bias Frames to master_bias.fit
+stack bias rej 3 3 -nonorm -out=../${MASTERDIR}/${MASTERBIAS}
+cd ..
+
+close
+
+ENDSIRILBIAS
+
+fi
+
+# ------------------------------------------------------------------
+# CREATE OUTPUT DIRECTORY
+
+mkdir -p "${PROCESSDIR}/${CALIBRATEDDIR}"
+
+# ------------------------------------------------------------------
+# CREATE SESSION FLAT
+# CALIBRATE SESSIONS LIGHTS
+
+# Create calibrated light frames for each session
+for session in `find -maxdepth 1 -type d -iname "session*"`; do
+
+ sessionname=`basename "${session}"`
+
+ echo "------------------------------------------------------------------"
+ echo "Preprocessing session ${sessionname}"
+ #notify-send "${NOTIFICATIONTITLE}" "Preprocessing session ${sessionname}"
+
+ sessionlightdir="${sessionname}/${LIGHTDIR}"
+ sessionflatdir="${sessionname}/${LIGHTDIR}"
+
+ if [ ! -d "${sessionlightdir}" ]; then
+ echo "Couldn't find ${sessionlightdir}"
+ exit 1;
+ fi
+
+ if [ ! -d "${sessionflatdir}" ]; then
+ echo "Couldn't find ${sessionflatdir}"
+ exit 1;
+ fi
+
+ cd "${sessionname}"
+
+ SESSIONDARK="${MASTERDIR}/${MASTERDARK}"
+ if [ -r "${SESSIONDARK}.fits" ]; then
+ SESSIONDARK="../../${sessionname}/${SESSIONDARK}"
+ echo "Using session master dark for ${sessionname}"
+
+ else
+ SESSIONDARK="../../${MASTERDIR}/${MASTERDARK}"
+ fi
+
+ SESSIONBIAS="${MASTERDIR}/${MASTERBIAS}"
+ if [ -r "${SESSIONBIAS}.fits" ]; then
+ SESSIONBIAS="../../${sessionname}/${SESSIONBIAS}"
+ echo "Using session master bias for ${sessionname}"
+ else
+ SESSIONBIAS="../../${MASTERDIR}/${MASTERBIAS}"
+ fi
+
+ SESSIONFLAT="${MASTERDIR}/${MASTERFLAT}"
+ if [ -r "${SESSIONFLAT}.fits" ]; then
+ SESSIONFLAT="../../${sessionname}/${SESSIONFLAT}"
+ echo "Using session master flat for ${sessionname}"
+ else
+ echo "------------------------------------------------------------------"
+ echo "Creating master flat for session ${sessionname}"
+
+ siril-cli -d . -s - <<ENDSIRILFLAT
+
+requires 1.2.0
+
+# Convert Flat Frames to .fit files
+cd ${FLATDIR}
+convert flat -out=../../${PROCESSDIR}/${sessionname}
+cd ../../${PROCESSDIR}/${sessionname}
+
+# Pre-process Flat Frames
+calibrate flat -bias=${SESSIONBIAS}
+
+# Stack Flat Frames to session_flat.fits
+stack pp_flat rej 3 3 -norm=mul -out=${MASTERFLAT}
+
+cd ../../${sessionname}
+close
+
+ENDSIRILFLAT
+
+ SESSIONFLAT="../../${sessionname}/${SESSIONFLAT}"
+
+ if [ ! -d "${MASTERDIR}" ]; then
+ mkdir "${MASTERDIR}"
+ fi
+
+ cp -v "../${PROCESSDIR}/${sessionname}/${MASTERFLAT}.fits" "${MASTERDIR}"
+ fi
+
+ echo "------------------------------------------------------------------"
+ echo "Calibrating lights for session ${sessionname}"
+
+ siril-cli -d . -s - <<ENDSIRILLIGHT
+
+requires 1.2.0
+
+# Convert Light Frames to .fit files
+cd ${LIGHTDIR}
+convert light -out=../../${PROCESSDIR}/${sessionname}
+cd ../../${PROCESSDIR}/${sessionname}
+
+# Calibrate light frames
+calibrate light -dark=${SESSIONDARK} -flat=${SESSIONFLAT} -cfa -cc=dark -equalize_cfa -prefix=${sessionname}_pp_
+
+cd ../../${sessionname}
+close
+
+ENDSIRILLIGHT
+
+ # move calibrated files
+
+ echo "------------------------------------------------------------------"
+ cd ..
+ mv -v ${PROCESSDIR}/${sessionname}/${sessionname}_pp_*.fits ${PROCESSDIR}/${CALIBRATEDDIR}/
+done
+
+# ------------------------------------------------------------------
+# REGISTER LIGHTS
+
+echo "------------------------------------------------------------------"
+echo "Registering calibrated lights"
+#notify-send "${NOTIFICATIONTITLE}" "Registering calibrated lights"
+
+siril-cli -d . -s - <<ENDSIRILREGISTER
+
+requires 1.2.0
+
+# Convert Light Frames to .fit files
+cd ${PROCESSDIR}/${CALIBRATEDDIR}
+convert preprocess -out=../
+cd ../
+
+# Register lights
+
+# extra options: -2pass -nostarlist (find reference image)
+register preprocess -drizzle -2pass -nostarlist
+# extra options --framing=[cog|max|min]
+seqapplyreg preprocess -drizzle -framing=${OPT_FRAMING}
+
+cd ..
+close
+
+ENDSIRILREGISTER
+
+# ------------------------------------------------------------------
+# STACK LIGHTS
+
+echo "------------------------------------------------------------------"
+echo "Stacking calibrated lights"
+#notify-send "${NOTIFICATIONTITLE}" "Stacking calibrated lights"
+
+siril-cli -d . -s - <<ENDSIRILSTACK
+
+requires 1.2.0
+
+cd ${PROCESSDIR}
+
+# Stack calibrated lights to result.fits
+stack r_preprocess rej 3 3 -norm=addscale -output_norm -rgb_equal -out=result
+
+# mirror the result
+load result
+mirrorx -bottomup
+save ../result_drizzle_${OPT_FRAMING}_\$LIVETIME:%d\$s
+
+cd ..
+close
+
+ENDSIRILSTACK
+
+notify-send -a "Siril" "Stacking (Finished)"
+