#################################################################################
# Spectral confusion matrices (Figs. 1-2).
# Run `make help` for the targets.
#################################################################################
PYTHON_INTERPRETER ?= $(if $(wildcard ./venv/bin/python),./venv/bin/python,python)
save_type = svg

## Install Python dependencies (into the active environment)
requirements:
	$(PYTHON_INTERPRETER) -m pip install -U pip setuptools wheel
	$(PYTHON_INTERPRETER) -m pip install -r requirements.txt

## Use the bundled demo data (CIPIC 017, frog + knocking) as data/raw
demo_data:
	@test -e data/raw || (mkdir -p data && ln -s demo data/raw && echo "data/raw -> data/demo")

## Figs. 1-2: confusion matrices (mono/prior/binaural/motion), frog vs knocking, CIPIC 017
confusion_matrices:
	$(PYTHON_INTERPRETER) src/visualization/all_elevation_spectra_maps/confusion_matrices.py \
		--save_figs=true --save_type=$(save_type) --exp_name=paper --participant_number=17 \
		--azimuth=12 --snr=0.2 --freq_bands=512 --min_freq=4000 --max_freq=12000 --elevations=19 \
		--stim1=007 --stim2=027 --clean

## Demo: confusion matrices on the bundled demo data
demo: demo_data confusion_matrices

## All figures of this repository
all: confusion_matrices

## Delete compiled Python files and cached spectra
clean:
	find . -type f -name "*.py[co]" -delete
	find . -type d -name "__pycache__" -delete
	rm -rf data/processed__*

.PHONY: requirements demo_data confusion_matrices demo all clean help
.DEFAULT_GOAL := help
help:
	@grep -B1 -E '^[a-z_]+:' Makefile | grep -E '^## ' -A1 | grep -v -- '--' | paste - - | sed -E 's/^## (.*)\t([a-z_]+):.*/\2\t\1/'
