Covert the following Matlab program to Python language. The Program must be able
ID: 668080 • Letter: C
Question
Covert the following Matlab program to Python language. The Program must be able to work in Python.
----------------------------------------------------------------------------------------------------------------------------------------------------
threshold = 86;
ncfile = '../data/final.nc';
tempK = ncread(ncfile, 't2m');
latitude = double(ncread(ncfile, 'latitude'));
longitude = double(ncread(ncfile, 'longitude'));
[nlon, nlat, nt] = size(tempK);
tempC = tempK - 273.15;
tempF = celsius2fahrenheit(tempC);
nday = zeros(nlon, nlat);
nday_consecutive = zeros(nlon, nlat);
for ii = 1:nlon
for jj = 1:nlat
nday(ii,jj,:) = exceed(tempF(ii,jj,:), threshold);
nday_consecutive(ii,jj,:) = max(...
exceed_consecutive(tempF(ii,jj,:), threshold));
end
end
plot_map(latitude, longitude, nday, threshold, 0);
plot_map(latitude, longitude, nday_consecutive, threshold, 1);
Explanation / Answer
Python code: