Determining the daily temperature range
The daily temperature range, or diurnal temperature variation as it is called in meteorology, is not so big a deal on Earth. In desert areas on Earth or generally on different planets, the variation is greater. We will have a look at the daily temperature range for the data we downloaded in the previous example:
To analyze temperature ranges, we will need to import the NumPy package and the NumPy masked arrays:
import numpy as np import sys import numpy.ma as ma from datetime import datetime as dt
We will load a bit more data than that loaded in the previous section: dates of measurements in the YYYYMMDD format and the average daily temperature. Dates require special conversion. Firstly date strings are converted to dates and then to numbers as follows:
to_float = lambda x: float(x.strip() or np.nan) to_date = lambda x: dt.strptime(x, "%Y%m%d").toordinal() dates, avg_temp, min_temp, max_temp = np.loadtxt(sys.argv[1], delimiter=',', usecols=(1, 11, 12...