Skip to content

Commit 0bf181f

Browse files
Quarto output
1 parent 7ee47d5 commit 0bf181f

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

notebooks/courses/environmental-remote-sensing/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ exclude = [
2626
"dist",
2727
"site-packages",
2828
"venv",
29+
"*_homework_exercise.ipynb"
2930
]
3031
line-length = 88
3132
indent-width = 4

notebooks/courses/environmental-remote-sensing/src/envrs/corr_plots.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
"""Conda path solver for ffmpeg and functions to plot correlations.
2+
3+
Returns
4+
-------
5+
Conda path : str
6+
Correlation animation plot: IPython.display
7+
R-squared plot: matplotlib.pyplot
8+
9+
"""
10+
111
import json
2-
import os
312
import subprocess
413
from pathlib import Path
514

@@ -14,29 +23,35 @@
1423
def get_git_repo_name():
1524
try:
1625
toplevel_path = subprocess.check_output(
17-
["git", "rev-parse", "--show-toplevel"],
26+
["git", "rev-parse", "--show-toplevel"], # noqa
1827
stderr=subprocess.DEVNULL,
1928
text=True,
2029
).strip()
2130

22-
return os.path.basename(toplevel_path)
31+
return Path(toplevel_path).name
2332
except subprocess.CalledProcessError:
2433
return None
2534

2635

2736
def get_conda_env_path():
37+
conda_prefix = Path("../.conda_envs")
2838
result = subprocess.run(
29-
["conda", "info", "--json"], check=False, capture_output=True, text=True
39+
["conda", "info", "--json"], # noqa
40+
check=False,
41+
capture_output=True,
42+
text=True,
3043
)
3144
info = json.loads(result.stdout)
3245
envs = [s for s in info.get("envs") if "environmental-remote-sensing" in s]
33-
if get_git_repo_name() is None:
34-
return envs[0]
35-
# when cached on GH actions
36-
if envs == []:
37-
ROOT_GH_CACHE = "/home/runner/work/eo-datascience/eo-datascience/"
38-
return ROOT_GH_CACHE + ".conda_envs/environmental-remote-sensing"
39-
return [s for s in envs if f"{get_git_repo_name()}/.conda_envs" in s][0]
46+
if len(envs) == 0:
47+
# when cached on GH actions
48+
root_gh_cache = "/home/runner/work/eo-datascience/eo-datascience/"
49+
return root_gh_cache + ".conda_envs/environmental-remote-sensing"
50+
if conda_prefix.is_dir():
51+
conda_prefix_path = f"{get_git_repo_name()}/{conda_prefix.name}"
52+
envs_with_prefix = [s for s in envs if conda_prefix_path in s]
53+
return next(iter(envs_with_prefix), None)
54+
return next(iter(envs), None)
4055

4156

4257
ffmpeg_path = Path(get_conda_env_path()) / Path("bin/ffmpeg")
@@ -61,8 +76,8 @@ def _plot_predicted_values(ax, df, variable, res, suffix):
6176
iv_l = pred_ols.summary_frame()["obs_ci_lower"]
6277
iv_u = pred_ols.summary_frame()["obs_ci_upper"]
6378
fitted = res.fittedvalues
64-
x = df[variable].values
65-
y = df["ndvi"].values
79+
x = df[variable].to_numpy()
80+
y = df["ndvi"].to_numpy()
6681
ax.set_title(f"{variable} {suffix}")
6782
ax.plot(x, y, "o", label="data", alpha=0.5)
6883
ax.plot(x, fitted, label="OLS")

0 commit comments

Comments
 (0)