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.
Last active
May 5, 2021 16:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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