Chapter 2 — Spatial Raster Data in Python cont.
3 min readJan 18, 2023
Objectives are:
- Create new raster objects.
- Assign the correct projection or CRS.
A raster data model is an array of cells, or pixels, to represent real-world objects.
Raster datasets are commonly used for representing and managing imagery, surface temperatures, digital elevation models, and numerous other entities.
Here we create an example of two ndarray
objects one X
spans [-90°,90°] longitude, and Y
covers [-90°,90°] latitude.
import numpy as np
x = np.linspace(-90, 90, 6)
y = np.linspace(90, -90, 6)
X, Y = np.meshgrid(x, y)
X
array([[-90., -54., -18., 18., 54., 90.],
[-90., -54., -18., 18., 54., 90.],
[-90., -54., -18., 18., 54., 90.],
[-90., -54., -18., 18., 54., 90.],
[-90., -54., -18., 18., 54., 90.],
[-90., -54., -18., 18., 54., 90.]])
Let’s generate data representing temperature (Z
)
import matplotlib.pyplot as plt
Z1 = np.abs(((X - 10) ** 2 + (Y - 10) ** 2) / 1 ** 2)
Z2 = np.abs(((X + 10) ** 2 + (Y + 10) ** 2) / 2.5 ** 2)
Z = (Z1 - Z2)
plt.imshow(Z)
plt.title("Temperature")
plt.show()