From 0a0b52b6cfb27a6b13c14cf9b5b980e5c61e0e74 Mon Sep 17 00:00:00 2001
From: Martin Schobben <martin.schobben@geo.tuwien.ac.at>
Date: Mon, 25 Nov 2024 10:35:42 +0100
Subject: [PATCH] update dependencies

---
 .gitignore                      |  3 +-
 Makefile                        |  3 +-
 environment.yml                 |  2 +-
 notebooks/01_classification.yml | 23 +++++++++++++
 notebooks/02_floodmapping.yml   | 17 ++++++++++
 notebooks/Makefile              | 60 +++++++++++++++++++++++++++++++++
 6 files changed, 104 insertions(+), 4 deletions(-)
 create mode 100644 notebooks/01_classification.yml
 create mode 100644 notebooks/02_floodmapping.yml
 create mode 100644 notebooks/Makefile

diff --git a/.gitignore b/.gitignore
index 3af1206..1cf4ba6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,7 @@
 _book/
 data/
 _freeze/
-notebooks/
+notebooks/*.ipynb
 *_files/
 .jupyter_cache/
 *~
@@ -22,6 +22,7 @@ __pycache__/*
 .cache/*
 .*.swp
 .ipynb_checkpoints/*
+/**/.ipynb_checkpoints/*
 .DS_Store
 
 # Project files
diff --git a/Makefile b/Makefile
index 22b8b3b..7f2dd6f 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,7 @@ REQ = $(basename $(notdir $(YML)))
 BASENAME = $(CURDIR)
 
 CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate
-PREFIX = $(BASENAME)/.conda_envs
-CONDA_ENV_DIR := $(foreach i,$(REQ),$(PREFIX)/$(i))
+CONDA_ENV_DIR := $(foreach i,$(REQ),$(shell conda info --base)/envs/$(i))
 KERNEL_DIR := $(foreach i,$(REQ),$(shell jupyter --data-dir)/kernels/$(i))
 
 help:
diff --git a/environment.yml b/environment.yml
index 3728b1f..5e8a76d 100644
--- a/environment.yml
+++ b/environment.yml
@@ -2,7 +2,7 @@ name: eo-datascience
 channels:
   - conda-forge
 dependencies:
-  - python=3.10
+  - python=3.12
   - pip
   - mamba
   - jupyter
diff --git a/notebooks/01_classification.yml b/notebooks/01_classification.yml
new file mode 100644
index 0000000..73b8806
--- /dev/null
+++ b/notebooks/01_classification.yml
@@ -0,0 +1,23 @@
+name: 01_classification
+channels:
+  - conda-forge
+dependencies:
+  - python=3.12
+  - pip
+  - mamba
+  - jupyter
+  - cmcrameri
+  - dask
+  - geopandas
+  - matplotlib
+  - nbformat
+  - numpy
+  - odc-stac
+  - openssl
+  - rasterio
+  - rioxarray
+  - scikit-learn
+  - seaborn
+  - stackstac
+  - xarray
+  - pystac-client
\ No newline at end of file
diff --git a/notebooks/02_floodmapping.yml b/notebooks/02_floodmapping.yml
new file mode 100644
index 0000000..f2d39ae
--- /dev/null
+++ b/notebooks/02_floodmapping.yml
@@ -0,0 +1,17 @@
+name: 02_floodmapping
+channels:
+  - conda-forge
+dependencies:
+  - python=3.12
+  - pip
+  - mamba
+  - jupyter
+  - eomaps
+  - numpy
+  - scipy
+  - xarray
+  - zarr
+  - netcdf4
+  - ipympl 
+  - ipywidgets
+  - datashader
\ No newline at end of file
diff --git a/notebooks/Makefile b/notebooks/Makefile
new file mode 100644
index 0000000..7f2dd6f
--- /dev/null
+++ b/notebooks/Makefile
@@ -0,0 +1,60 @@
+.ONESHELL:
+SHELL = /bin/bash
+.PHONY: help clean environment kernel teardown post-render data
+
+YML = $(wildcard notebooks/*.yml)
+QMD = $(wildcard chapters/*.qmd)
+REQ = $(basename $(notdir $(YML)))
+BASENAME = $(CURDIR)
+
+CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate
+CONDA_ENV_DIR := $(foreach i,$(REQ),$(shell conda info --base)/envs/$(i))
+KERNEL_DIR := $(foreach i,$(REQ),$(shell jupyter --data-dir)/kernels/$(i))
+
+help:
+	@echo "Makefile for setting up environment, kernel, and pulling notebooks"
+	@echo ""
+	@echo "Usage:"
+	@echo "  make environment  - Create Conda environments"
+	@echo "  make kernel       - Create Conda environments and Jupyter kernels"
+	@echo "  "
+	@echo "  make teardown     - Remove Conda environments and Jupyter kernels"
+	@echo "  make clean        - Removes ipynb_checkpoints"
+	@echo "  make help         - Display this help message"
+
+clean:
+	rm --force --recursive .ipynb_checkpoints/ **/.ipynb_checkpoints/ _book/ \
+		_freeze/ .quarto/
+
+teardown:
+	$(foreach f, $(REQ), \
+		$(CONDA_ACTIVATE) $(f); \
+		jupyter kernelspec uninstall -y $(f); \
+		conda deactivate; \
+		conda remove -n $(f) --all -y ; \
+		conda deactivate; )
+
+$(CONDA_ENV_DIR): $(YML)
+	- conda update -n base -c conda-forge conda -y
+	$(foreach f, $^, conda env create --file $(f); )
+
+environment: $(CONDA_ENV_DIR)
+	@echo -e "conda environments are ready."
+
+$(KERNEL_DIR): $(CONDA_ENV_DIR)
+	$(foreach f, $(REQ), \
+		$(CONDA_ACTIVATE) $(f); \
+		python -m ipykernel install --user --name $(f) --display-name $(f); \
+		conda deactivate; )
+
+kernel: $(KERNEL_DIR)
+	@echo -e "conda jupyter kernel is ready."
+
+post-render:
+	- mv chapters/*.ipynb notebooks/ >/dev/null 2>&1
+	- for f in chapters/*.quarto_ipynb ; do mv -- "$f" "${f%.quarto_ipynb}.ipynb"  >/dev/null 2>&1; done
+	cp Makefile notebooks/
+
+data:
+	wget -q -P ./data https://cloud.geo.tuwien.ac.at/s/AezWMFwmFQJsKyr/download/floodmap.zip
+	cd data && unzip -n floodmap.zip && rm floodmap.zip
\ No newline at end of file