.PHONY: all clean clean_notebooks clean_report

all: output/manuscript.pdf

# List of plot image targets
PLOTS = output/plots/bell_violation.png\
		output/plots/fidelity_dist.png\
		output/plots/detector_comparison.png\
		output/plots/visibility_distance.png\
		output/plots/world_map.png\
		output/plots/coincidence_rates.png\
		output/plots/temperature_effects.png

# List of table targets
TABLES = output/tables/summary.tex\
		output/tables/laboratories.tex

# Final PDF depends on manuscript source, plots, and tables
output/manuscript.pdf: report/manuscript.tex $(PLOTS) $(TABLES)
	cd report\
	&& pdflatex manuscript.tex\
	&& pdflatex manuscript.tex\
	&& mv manuscript.pdf ../output/manuscript.pdf

# Base data generation from raw data
data/base/data.csv: notebooks/make_basedata.ipynb data/raw/experimental_data.csv
	cd notebooks\
	&& papermill make_basedata.ipynb /dev/null

# Pattern rule for tables
$(TABLES): output/tables/%.tex: notebooks/tab_%.ipynb data/base/data.csv
	cd notebooks\
	&& papermill $(notdir $<) /dev/null

# Pattern rule for plots
$(PLOTS): output/plots/%.png: notebooks/plot_%.ipynb data/base/data.csv
	cd notebooks\
	&& papermill $(notdir $<) /dev/null

# Clean up generated files
clean: clean_notebooks clean_report
	rm -f data/base/data.csv data/base/data.pkl
	rm -f output/plots/*.png
	rm -f output/tables/*.tex
	rm -f output/manuscript.pdf

# Clear notebook outputs
clean_notebooks:
	jupyter nbconvert notebooks/*.ipynb --clear-output --inplace

# Clean up LaTeX auxiliary files
clean_report:
	rm -f report/manuscript.aux
	rm -f report/manuscript.log
	rm -f report/manuscript.out
	rm -f report/manuscript.bbl
	rm -f report/manuscript.blg
