Exerciseschevron_rightChapter 2chevron_right2.3
fitness_center

Exercise 2.3

Temperature Gradient

Level 2
Chapter 2: Python Essentials
descriptionProblem

Temperature increases with depth at the geothermal gradient, typically 1.0 to 1.8 °F per 100 ft in sedimentary basins. The bottomhole temperature (BHT) follows:

BHT=Tsurface+GT×TVDBHT = T_{surface} + G_T \times TVD

where GTG_T is the gradient in °F/ft.

Build a temperature profile for a Niger Delta well:

  • Surface temperature: 80 °F
  • Gradient: 1.4 °F per 100 ft (so 0.014 °F/ft)
  • Depths from 0 to 15,000 ft in 500-ft steps

Compute and plot:

  1. depths: a NumPy array of those depths (31 points from 0 to 15,000).
  2. temps_f: temperature at each depth in °F.
  3. temps_c: same temperatures converted to °C using C=(F32)×5/9C = (F - 32) \times 5/9.
  4. depth_300f: the depth at which the temperature first reaches 300 °F

(compute analytically: solve the linear equation, don't search).

  1. A matplotlib chart showing temperature vs. depth with depth on the

inverted y-axis (petroleum convention). Label the axes, add a title, and draw a horizontal reference line at 300 °F where downhole electronics start to fail.

> Think about it: what changes about your drilling fluid choice, your > elastomer selection, and your downhole-tool budget once you cross 300 °F?

lightbulbHints (0/5)

Stuck? Reveal hints one at a time — they progress from nudge to near-solution.

codeYour solution
main.py
visibilityReveal reference solutionexpand_more

Try solving it yourself first — the hints walk you through it. The solution below is one valid approach; yours may differ and still be correct.

import numpy as np
import matplotlib.pyplot as plt

t_surface_f = 80
gradient_f_per_ft = 0.014

depths     = np.arange(0, 15001, 500)                  # 0, 500, ..., 15000  (31 pts)
temps_f    = t_surface_f + gradient_f_per_ft * depths
temps_c    = (temps_f - 32) * 5 / 9
depth_300f = (300 - t_surface_f) / gradient_f_per_ft   # analytic inverse

# Plot
fig, ax = plt.subplots(figsize=(6, 7))
ax.plot(temps_f, depths, "o-", color="#CC4444", label="Temperature (°F)")

ax.axhline(depth_300f, color="#888", linestyle="--", linewidth=1,
           label=f"300 °F threshold  (≈ {depth_300f:,.0f} ft)")

ax.invert_yaxis()
ax.set_xlabel("Temperature (°F)")
ax.set_ylabel("True vertical depth (ft)")
ax.set_title("Geothermal profile - Niger Delta well "
             "(Tₛ = 80 °F, Gᴛ = 1.4 °F/100 ft)")
ax.legend(loc="lower left")
ax.grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

print(f"BHT at TD (15,000 ft):  {temps_f[-1]:.0f} °F  ({temps_c[-1]:.1f} °C)")
print(f"300 °F reached at:       {depth_300f:,.0f} ft")

lockCopying code is a Full Access feature.