Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update calib management scripts based on MagAO-X practices #48

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 99 additions & 10 deletions AOloopControl/scripts/cacao-calib-apply
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
#!/usr/bin/env bash

#######################################################################################
# Script to apply a CACAO loop calibration previously saved with cacao-calib-archive.
#
# Usage: cacao-calib-apply cal_name
#
# This script must be run in `loop-name-rootdir`. Here cal_name corresponds to a directory
# in `../loop-name-calibs`. Note this is not the whole path, just the directory name including
# the timestamp appended by cacao-calib-archive.
#
# The following steps are performed:
# 1. The loop is turned off
# 2. The loop processes are shutdown, in each case both run and conf:
# mvalC2dm
# mfilt
# wfs2cmodeval
# acquWFS
# 3. The script `./scripts/pre-calib-apply` is run, if it exists. This is a user script
# that can be used for any other desired pre-apply actions on your system. The calib name
# and path (relative to rootdir) are passed as arguments.
# 4. The calibration is loaded into shared memory. This means the files:
# CMmodesDM/CMmodesDM.fits
# CMmodesWFS/CMmodesWFS.fits
# RMmodesWFS/zrespM-H.fits
# wfsref.fits
# wfsmask.fits
# dmmask.fits
# 5. The loop processes, conf and run, are started in the correct order to be initialized:
# acquWFS
# wfs2cmodeval
# mfilt
# mvalC2dm
# 6. The script `./scripts/post-calib-apply` is run, if it exists. This is a user script
# that can be used for any other desired post-apply actions on your system (e.g. zero all gains).
# The calib name and path (relative to rootdir) are passed as arguments.
# 7. The following files are created:
# $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_source.txt [contains the directory to calibration files]
# $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_loaded.txt [contains the time calibration was loaded]
# 8. A log entry is made.
############################################################################################################

MSdescr="Apply AO calibration"

Expand Down Expand Up @@ -39,23 +78,73 @@ echo "Loop ${CACAO_LOOPNUMBER}: Loading calibration from ${ARCHDIR}"

if [[ -d "${ARCHDIR}" ]]; then

# Load CM to shared memory
milk-FITS2shm "${ARCHDIR}/CMmodesWFS/CMmodesWFS.fits" aol${CACAO_LOOPNUMBER}_modesWFS
milk-FITS2shm "${ARCHDIR}/CMmodesDM/CMmodesDM.fits" aol${CACAO_LOOPNUMBER}_DMmodes
#open the loop
echo "setval mfilt-${CACAO_LOOPNUMBER}.loopON OFF" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo

#Shutdown processes
echo "runstop mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
echo "confstop mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo

echo "runstop mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
echo "confstop mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo

milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsref.fits" aol${CACAO_LOOPNUMBER}_wfsref
milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsrefc.fits" aol${CACAO_LOOPNUMBER}_wfsrefc
echo "runstop wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
echo "confstop wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo

milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsmask.fits" aol${CACAO_LOOPNUMBER}_wfsmask
milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsmap.fits" aol${CACAO_LOOPNUMBER}_wfsmap
echo "runstop acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
echo "confstop acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo

milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_dmmask.fits" aol${CACAO_LOOPNUMBER}_dmmask
milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_dmmap.fits" aol${CACAO_LOOPNUMBER}_dmmap
#run pre-apply script if it exists.
if [ -d "scripts" ]; then
cd scripts
if [ -f "pre-calib-apply" ]; then
echo "running pre-calib-apply"
./pre-calib-apply ${calib} ${ARCHDIR}
fi
cd ..
fi

# Load CM to shared memory
milk-FITS2shm "${ARCHDIR}/CMmodesWFS/CMmodesWFS.fits" aol${CACAO_LOOPNUMBER}_CMmodesWFS
milk-FITS2shm "${ARCHDIR}/CMmodesDM/CMmodesDM.fits" aol${CACAO_LOOPNUMBER}_CMmodesDM

milk-FITS2shm "${ARCHDIR}/RMmodesWFS/zrespM-H.fits" aol${CACAO_LOOPNUMBER}_zrespM

milk-FITS2shm "${ARCHDIR}wfsref.fits" aol${CACAO_LOOPNUMBER}_wfsref
milk-FITS2shm "${ARCHDIR}wfsref.fits" aol${CACAO_LOOPNUMBER}_wfsrefc

milk-FITS2shm "${ARCHDIR}wfsmask.fits" aol${CACAO_LOOPNUMBER}_wfsmask

milk-FITS2shm "${ARCHDIR}dmmask.fits" aol${CACAO_LOOPNUMBER}_dmmask

#Startup processes
echo "confstart acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "runstart acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "confstart wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "runstart wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "confstart mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "runstart mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "confstart mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo
sleep 1
echo "runstart mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo

if [ -d "scripts" ]; then
cd scripts
if [ -f "post-calib-apply" ]; then
echo "running post-calib-apply"
./post-calib-apply ${calib} ${ARCHDIR}
fi
cd ..
fi

# record this calib as applied
echo $(pwd)/../${ARCHDIR} > $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_source.txt
echo $(pwd)/${ARCHDIR} > $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_source.txt

DATESTRING="$(date -u --iso-8601=seconds)"

Expand Down
68 changes: 46 additions & 22 deletions AOloopControl/scripts/cacao-calib-archive
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#!/usr/bin/env bash

#######################################################################################
# Script to archive a CACAO loop calibration.
#
# Usage: cacao-calib-arhchive cal_name
#
# This script must be run in `loop-name-rootdir`. Here cal_name corresponds to a descriptive name
# of the calibration. A timestamp will be apended to it, and the result is used to create a directory
# in ``../loop-name-calibs`.
#
# The time stamp appendage can be suppressed with -u for update.
#
# The following files are copied to the cal directory.
# conf/CMmodesDM/CMmodesDM.fits
# conf/CMmodesWFS/CMmodesWFS.fits
# conf/RMmodesWFS/zrespM-H.fits
# conf/wfsref.fits
# conf/wfsmap.fits
# conf/wfsmask.fits
# conf/dmmap.fits
# conf/dmmask.fits
# LOOPNAME
#
# Additionally a file named calib_dir.txt is created which holds the directory path (useful for
# dereferencing symlinks).
#
# The file calib_archived.txt is updated with the current time, and a log entry is made.
#
##########################################################################################################

MSdescr="Archive AO calibration"

MSextdescr="Copy current filesystem calibration to ../CACAO_LOOPNAME-AOcalibs/<calibname>/ directory
Expand All @@ -16,8 +45,6 @@ RequiredFiles=()

RequiredDirs=(conf)



MSarg+=( "calibname:string:calibration name" )
MSopt+=( "u:update:setupdate::update existing, do not append timestamp" )

Expand Down Expand Up @@ -62,37 +89,34 @@ ARCHDIR="${BASEARCHDIR}${calib}/"


mkdir -p ${ARCHDIR}
mkdir -p ${ARCHDIR}/RMmodesDM
mkdir -p ${ARCHDIR}/RMmodesWFS
mkdir -p ${ARCHDIR}/CMmodesDM
mkdir -p ${ARCHDIR}/CMmodesWFS

echo "Saving to DIRECTORY ${ARCHDIR}"



CONFDIR="conf"

for f in $CONFDIR
do
if [ -d "$f" ]
then
for ff in $f/*
do
#if this is a broken symlink, ignore it
if [ -L $ff ] && [ ! -e $ff ]
then
continue
fi

cp -L -r $ff ${ARCHDIR}"$(basename $ff)"
done
else
cp -L -r $ff ${ARCHDIR}
fi
done
cp ${CONFDIR}/RMmodesWFS/zrespM-H.fits ${ARCHDIR}/RMmodesWFS/zrespM-H.fits
cp ${CONFDIR}/CMmodesDM/CMmodesDM.fits ${ARCHDIR}/CMmodesDM/CMmodesDM.fits
cp ${CONFDIR}/CMmodesWFS/CMmodesWFS.fits ${ARCHDIR}/CMmodesWFS/CMmodesWFS.fits
cp ${CONFDIR}/RMmodesDM/RMmodesDM.fits ${ARCHDIR}/RMmodesDM/RMmodesDM.fits
cp ${CONFDIR}/RMmodesWFS/RMmodesWFS.fits ${ARCHDIR}/RMmodesWFS/RMmodesWFS.fits
cp ${CONFDIR}/wfsref.fits ${ARCHDIR}/wfsref.fits
cp ${CONFDIR}/wfsmask.fits ${ARCHDIR}/wfsmask.fits
cp ${CONFDIR}/wfsmap.fits ${ARCHDIR}/wfsmap.fits
cp ${CONFDIR}/dmmask.fits ${ARCHDIR}/dmmask.fits
cp ${CONFDIR}/dmmap.fits ${ARCHDIR}/dmmap.fits

cp LOOPNAME ${ARCHDIR}/LOOPNAME

# write out complete path so someone following a symlink can easily track where we are
echo $(pwd)/${ARCHDIR} > ${ARCHDIR}/aol${CACAO_LOOPNUMBER}_calib_dir.txt
echo $(pwd)/${ARCHDIR} > ${ARCHDIR}/calib_dir.txt

# append timestamp
echo ${DATESTRING} >> ${ARCHDIR}/aol${CACAO_LOOPNUMBER}_calib_archived.txt
echo ${DATESTRING} >> ${ARCHDIR}/calib_archived.txt

echo "${DATESTRING} ARCHIVED ${calib}" >> ${BASEARCHDIR}/aol${CACAO_LOOPNUMBER}_archive-log.txt
Loading