I wrote this script to search for fits images by RA/Dec because I found that searching for object names is inconsistent, in my case. Also I don't save all of my images to object name folders, which I suppose I could do too. It does require the Observatory app from the App Store, which isn't free, but this app has a lot of features that I find useful. For example adding fits header data to spotlight metadata, which makes searching very fast using the mdfind command.
The script copies matching images so I can process them all at once.
ra_dec_search_copy.sh [options]
Options:
--ra VALUE Right Ascension target value (required)
--dec VALUE Declination target value (required)
--output DIR Output directory (default: ./grouped_images)
--search VALUE Search distance (default: 0.5)
--help Show this help message
#!/bin/bash # Default values SEARCH_DISTANCE=0.5 OUTPUT_DIR="./grouped_images" RA="" DEC="" # Function to display usage usage() { echo "Usage: $0 [options]" echo "Options:" echo " --ra VALUE Right Ascension target value (required)" echo " --dec VALUE Declination target value (required)" echo " --output DIR Output directory (default: ./grouped_images)" echo " --search VALUE Search distance (default: 0.5)" echo " --help Show this help message" echo echo "Example:" echo " $0 --ra 128.2 --dec 45.5 --output /path/to/output --search 0.3" exit 1 } # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in --ra) RA="$2" shift 2 ;; --dec) DEC="$2" shift 2 ;; --output) OUTPUT_DIR="$2" shift 2 ;; --search) SEARCH_DISTANCE="$2" shift 2 ;; --help) usage ;; *) echo "Unknown option: $1" usage ;; esac done # Check required parameters if [ -z "$RA" ] || [ -z "$DEC" ]; then echo "Error: RA and DEC values are required" usage fi # Create output directory if it doesn't exist mkdir -p "$OUTPUT_DIR" # Display initial settings echo "Settings:" echo " Right Ascension: $RA" echo " Declination: $DEC" echo " Search Distance: $SEARCH_DISTANCE" echo " Output Directory: $OUTPUT_DIR" echo # Function to check if a number is within specified distance of target check_within_range() { local value=$1 local target=$2 local distance=$3 awk -v val="$value" -v target="$target" -v dist="$distance" 'BEGIN { diff = val - target if (diff < 0) diff = -diff if (diff <= dist) exit 0 exit 1 }' } # Count total number of .fit files echo "Counting files..." total_files=$(find . -name "*.fit" | wc -l) echo "Found $total_files .fit files to process" # Create a temporary file to store copy count temp_count_file=$(mktemp) echo "0" > "$temp_count_file" # Process files and maintain accurate count find . -name "*.fit" | while read -r file; do # Update and display progress printf "Processing: %s\r" "$(basename "$file")" # Get both RA and DEC with a single mdls call metadata=$(mdls -n "com_codeobsession_RightAscension" -n "com_codeobsession_Declination" "$file") file_ra=$(echo "$metadata" | grep "RightAscension" | awk '{print $3}') file_dec=$(echo "$metadata" | grep "Declination" | awk '{print $3}') # Check if both values are within range if check_within_range "$file_ra" "$RA" "$SEARCH_DISTANCE" && \ check_within_range "$file_dec" "$DEC" "$SEARCH_DISTANCE"; then echo -e "\nMatched: $file" echo "RA: $file_ra (target: $RA)" echo "DEC: $file_dec (target: $DEC)" cp "$file" "$OUTPUT_DIR/" echo "Copied to $OUTPUT_DIR" echo "----------------------------------------" # Increment copy counter in temporary file curr_count=$(<"$temp_count_file") echo "$((curr_count + 1))" > "$temp_count_file" fi done # Get final copy count copied=$(<"$temp_count_file") rm "$temp_count_file" echo -e "\nProcessing complete!" echo "Processed $total_files files" echo "Copied $copied matching files to $OUTPUT_DIR" echo "Search distance used: $SEARCH_DISTANCE"