An assistant can write 100 lines of code in a few seconds — and just as easily slip in a subtle bug that survives the first run. This session is about how to work with it on real environmental data: what to ask for, what to verify, and where not to trust it.
AI that writes code: from a formula to a water crisis
Before we open an assistant, let's see where it comes from and what it sets in motion — because this story affects us directly, the people who work with water, sediment and the delta.
0%
of the code committed on GitHub is generated or assisted by AI
0 ml
of cooling water per single 100-word query
+0%
DRAM price in a single quarter, driven by data-centre demand
🏰 The New Middle Ages — Mircea Miclea's analogy
The psychologist Mircea Miclea offers an analogy: if the industrial revolution multiplied the social classes (workers, foremen, engineers, managers), AI will collapse them back into two big categories.
Epistemic aristocrats — the minority who read, reflect, think critically. They use AI as a tool but don't depend on it: they know which questions to ask, because they already carry the knowledge.
Epistemic serfs — those who have delegated mental effort to technology. They use AI to write their essays, to do their homework, to decide for them. Cut off their access and their value drops to zero.
We're still in the window where we can choose. The only way not to become a "serf" is conscious cognitive effort: read, learn, train your mind — limit the easy entertainment. That is what the rest of this module is about.
💡 Why this matters for this module
If AI is writing more and more of the code, your value is no longer the syntax. It's the clear formulation of the problem and the verification of the result — exactly what we'll practise in the next 45 minutes. And as environmental researchers, we should be among the first to use these tools aware of their footprint.
1 Objectives
By the end of the session you will be able to
✓Understand what an LLM is and is not when it writes code — and when it's not worth using
✓Write a good prompt following the recipe Context · Data · Task · Format · Constraints
✓Apply a verification checklist to any generated code before relying on it
✓Use the iterative loop prompt → run → read the error → re-prompt for debugging
2 Session plan
How the session runs
Stage
Tools
Teaching
1
Mental model: the LLM as a fast, confident junior. When it's worth it / when not
demo
2
Anatomy of a good prompt. The recipe and the iterative loop
Claude (live)
3
Verifying results: the checklist on real Delta examples
Claude · Colab
4
Reproducibility and honesty: versions, seed, citing AI
—
Hands-on & discussion
5
Hands-on exercise with an assistant
Colab + assistant
6
Discussion and Q&A
—
3 Key concepts
Five ideas to take home
Mental model
An LLM predicts the most plausible text, not the truth. It doesn't run the code, it doesn't see your data and it doesn't know your library version. It's a very fast, very confident junior colleague — who sometimes invents things with the same conviction as when it's right.
→ Treat every answer as a proposal, not a truth.
Context > short prompt
Garbage in, garbage out. Without context the model sprays; with context it hits the target. A good prompt = Context + Data (shape, units, CRS, nodata) + Task + Format + Constraints.
→ Two minutes of context save five iterations.
The iterative loop
You rarely nail it on the first try. Prompt → run → read the error → re-prompt. Paste the full error and a fragment of the data, not a paraphrase of them.
→ Three targeted iterations beat a "perfect" prompt.
Verification is your job
Code that runs ≠ correct code. The most dangerous quadrant is "runs but wrong": no error message, but a false result. You remain the reviewer — you know the units, the CRS and the order of magnitude.
→ Silent, plausible code is the most deceptive.
Reproducibility & honesty
Pin the versions (pip freeze), set a seed, note that you used an assistant. Don't paste unpublished data in the prompt. LLMs hallucinate DOIs and references — verify every citation.
→ If you can't reproduce it, you can't publish it.
you're turning pseudocode or described steps into code
you're writing tests or generating example data
you're translating code between languages
⛔ Avoid or be careful when…
the logic is scientific, critical and subtle (model physics, sediment budgets)
you have sensitive or unpublished data in the prompt
you need an exact reference or citation
it's a small task you know by heart (faster manually)
the code goes straight to production without review
you have no way to verify the result
4 Examples
Weak prompt vs. strong prompt
🧩 The prompt recipe
Context (what you already have) · Data (shape, dtype, units, CRS, nodata) · Task (what exactly you want) · Format (what it should return) · Constraints (which libraries to use / avoid). If the task is subtle, also add an example input → output.
Context→Data→Task→Format→Constraints
The same recipe, applied to a real prompt (Sulina example):
TASKextract the series at Sulina (45.15°N, 29.65°E) by interpolation, then the monthly mean
FORMATmonthly pandas.Series + matplotlib chart with labelled axes
CONSTRAINTSonly xarray + matplotlib; no for loops; comment each step
Example 1 — monthly time series at Sulina
Write Python code to get me the temperature for Sulina and compute the monthly mean.
Why it's weak: doesn't say what data structure it has, what units, what coordinates Sulina has, or what to return. The assistant guesses — and usually wrong (it reads a non-existent CSV, invents coordinates, returns an unlabelled array).
Context: I have an xarray.Dataset `ds` with variable `t2m` (2 m air temperature,
units °C), dimensions (time, lat, lon), daily step, geographic CRS EPSG:4326.
lat increases northward, lon eastward.
Task: extract the time series at Sulina (45.15°N, 29.65°E) by bilinear
interpolation, then aggregate it to a monthly mean.
Format: return a pandas.Series indexed by month + a matplotlib chart with
the Y axis labelled "Temperature (°C)" and title "Sulina — monthly mean".
Constraints: use only xarray (.interp, .resample) and matplotlib; no for
loops over time; comment each step on one line.
Example 2 — water mask (NDWI) from a GeoTIFF
Here, exactly the pitfalls from Module 2 (CRS, nodata) are the place where an LLM can lead you nicely off a cliff.
Compute NDWI for my satellite image.
Why it's weak: it doesn't know which bands are where, what the values represent, how missing pixels are marked. You risk division by zero on nodata, NDWI computed on the wrong bands, and loss of CRS on saving.
Context: I have a Sentinel-2 GeoTIFF opened with rioxarray as DataArray `da`,
dimensions (band, y, x). Band 1 = Green (B3), band 2 = NIR (B8), reflectance in [0, 1].
CRS = EPSG:32635 (UTM 35N). Missing pixels are marked with nodata = 0.
Task: compute NDWI = (Green − NIR) / (Green + NIR) and a binary water/land mask
(NDWI > 0). Mask the nodata pixels BEFORE the division so they don't enter the calc.
Format: a DataArray `ndwi` (float32, keep CRS and transform) + a boolean DataArray
`water` + the water surface in km² (from the pixel resolution).
Constraints: preserve the rio metadata; avoid division by zero (np.where on the denominator);
only rioxarray / xarray / numpy, no direct GDAL calls.
5 Verification
Checklist for any generated code
Dimensions and units — is the shape what you expected? °C or K? m or km? degrees or metres (CRS)?
NaN and edge values — what happens on nodata, on division by zero, at the grid edge?
Invented functions/libraries — does xr.smooth() or gpd.reproject_to_utm() actually exist? (Spoiler: no.)
Plausible magnitudes — is the order of magnitude correct? A water surface of 10⁶ km² in the Delta is an alarm.
Compare with a manual computation — run it on a small, known case where you know the answer.
CRS / axis orientation pitfall (delta-specific)
GeoTIFF stores rows north → south (y decreasing). An LLM can hand you a vertically flipped map without blinking. Check .rio.crs and the direction of the y axis before any clip/reproject. If the map looks flipped: da.isel(y=slice(None, None, -1)) or origin='upper' in imshow.
resample vs isel — aggregate or select?
resample(time='1ME').mean() takes the mean of the window (correct for climatology). isel(time=slice(None, None, 30)) just selects every 30th timestamp. LLMs often confuse them — and both "run". Read what it gave you.
Ask the assistant to check itself
"Identify the assumptions you made about my data and where the code might silently go wrong." Often the LLM points out the very issue you were about to hit.
6 Pitfalls
What to avoid
⚠️ Classic mistakes
Blind vibe coding — pasting code and running it without reading it.
Accepting the first answer to a vague prompt instead of adding context and iterating.
Not stating library versions → code with an old or too-new API (xarray, pandas change).
Trusting the numbers without a sanity check of units and order of magnitude.
Functions that "sound right" but don't exist — check the official docs.
Pasting sensitive / unpublished data in the prompt (project data, unloaded measurements, GDPR).
Relying on an LLM for facts and citations — it hallucinates references and DOIs convincingly.
7 AI models
Which model? And how to code with it now
In May 2026, the "frontier" models (Claude, GPT, Gemini) are very close on coding tasks — all around 80% on SWE-bench Verified, the standard test on real GitHub issues. The differences between them matter less today than the tool (the agent) you use them in.
Indicative numbers (May 2026). Benchmarks are noisy and partially "contaminated" — read them as a direction, not a verdict.
☁️ In the cloud (API / chat)
Claude (Opus 4.7) — strong on multi-file code and agents; the workshop's anchor.
Gemini (3.1 Pro) — cheapest at frontier level + 1M context; native in Colab.
Best quality — but your code leaves for an external provider.
💻 Locally, on your machine
Qwen3-Coder-Next — designed for code agents; runs on strong consumer hardware.
Gemma 4 (Google, Apache-2.0) — the most practical local default; fits in ~8 GB VRAM.
DeepSeek V4 · GLM · Kimi — close to the frontier on well-defined tasks.
Run them with Ollama / llama.cpp / LM Studio — free, offline, data stays with you.
📈 Local models are catching up
A year ago, open-weight models were "experiments". Today they're ~10 points behind the big ones and are used in real pipelines — a local model can match the previous frontier generation, but free and private. The pace is dizzying: the complexity of tasks an agent can complete roughly doubles every ~6 months.
The best way to code with AI right now
1
The tool matters more than the model. The same model varies 20–50 points depending on the agent it's used in. Choose a good agent (Claude Code, Cursor, Codex, Gemini CLI; local: Qwen Code or Aider + Ollama), not just "the biggest model".
2
Work "agentically", not autocomplete. Let the agent read your whole project, run the code, see the error and iterate on its own — then you review.
3
Hybrid. Frontier model (cloud) for heavy tasks; local model for sensitive or unpublished data — exactly your field data from the Delta.
4
Spec + verification in a loop. Give a clear context/spec (the recipe!), let the agent iterate against the tests, and you validate the result. Tests and CI are the safety net.
5
The human stays in the loop. For research, you guarantee scientific correctness and reproducibility. The model writes; you sign.