Skip to content

Instantly share code, notes, and snippets.

@thespacedoctor
Last active May 5, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thespacedoctor/a030e22dab97af013e3d6828bfedbed6 to your computer and use it in GitHub Desktop.
Save thespacedoctor/a030e22dab97af013e3d6828bfedbed6 to your computer and use it in GitHub Desktop.
[Renaming ESO Fits Frames Back to Their ORIGFILE Names] Renaming the XShooter fits files back to original more informative names instead of the ESO archive name #eso #xshooter #filename #fits

Renaming ESO Fits Frames Back to Their Original Names

Once FITS frames are added to the ESO Archive they are renamed with a standardised format. The original names are often more informative. This is a bash script to rename ESO fits files back to their original names.

#!/bin/bash
# SET PATH
PATH=:/usr/local/bin/:/usr/bin/:/Library/Frameworks/Python.framework/Versions/2.7/bin/:/bin/
VERSION=0.1
display_usage() {
echo "Usage:
${0##*/} [options] <fitsfile>
-k|--keep keep original files (copy instead of rename files)
-h|--help show this message
-v|--version show version number"
}
## DEFAULT OPTIONS & VARIABLES
keep=0 # KEEP ALL BYPRODUCT FILES (USE FOR DEBUGGING)
numberArguments=1 # MINIMUM NUMBER OF COMMAND-LINE ARGUMENTS REQUIRED
# COLLECT CL-ARGUMENTS & PARSE OPTIONS
args=( "$@" )
while [[ $# > 0 ]]
do
key="$1"
case $key in
-h|--help)
display_usage
exit 0
shift
;;
-v|--version)
echo "${0##*/} version $VERSION"
exit 0
;;
-k|--keep)
keep=1
delete=($key)
args=( ${args[@]/$delete/} )
shift
;;
*)
# unknown option
;;
esac
shift
done
# IF LESS THAN THE REQUIRED ARGUMENTS SUPPLIED, DISPLAY USAGE
if [ ${#args[@]} -lt $numberArguments ]
then
display_usage
exit 1
fi
## assign cl-arguments to varibale names
fitsfile=${args[0]}
# PARSE ORIGINAL NAME FROM FITS FILE HEADERS
nameas=$(fitshdr $fitsfile | grep ORIGFILE)
nameas=$(echo $nameas | perl -pe "s/' \/ Original File Name//g")
nameas=$(echo $nameas | perl -pe "s/ORIGFILE= '//g")
# COPY OR RENAME FILES
if [[ $nameas == *".fits"* ]]
then
# cp $fitsfile $nameas
if [[ $keep == 1 ]]
then
cp $fitsfile $nameas
else
mv $fitsfile $nameas
fi
else
echo "$fitsfile header contains no ORIGFILE"
fi
# x-name-cl-argument-variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment