PLEASE CONVERT THE FOLLOWING CODE FROM THE CURRENT MATLAB LANGUAGE TO PYTHON LAN
ID: 667659 • Letter: P
Question
PLEASE CONVERT THE FOLLOWING CODE FROM THE CURRENT MATLAB LANGUAGE TO PYTHON LANGUAGE:
threshold = 72;
ncfile = '../data/final_timeseries.nc';
tempK = squeeze(ncread(ncfile, 't2m'));
tempC = tempK - 273.15;
tempF = celsius2fahrenheit(tempC);
nday = exceed(tempF, threshold);
nday_consecutive = max(exceed_consecutive(tempF, threshold));
days = 1:length(tempF);
figure
plot(days, tempF, '.-')
hold on
plot(days, threshold*ones(size(days)), 'k--')
hold off
titletext = sprintf(['Total number of days exceeding threshold: %d. ' ...
'Longest warm period: %d days.'], ...
nday, nday_consecutive)
title(titletext)
xlabel('Day')
ylabel('Temperature (F)')
outputImageFileName = sprintf('BootCamp_PartA_Plot_Temperatures.png');
print('-dpng', outputImageFileName);
Explanation / Answer
python code converetd from the MATLAB code:
threshold = 72
ncfile = mstring('../data/final_timeseries.nc')
tempK = squeeze(ncread(ncfile, mstring('t2m')))
tempC = tempK - 273.15
tempF = celsius2fahrenheit(tempC)
nday = exceed(tempF, threshold)
nday_consecutive = max(exceed_consecutive(tempF, threshold))
days = mslice[1:length(tempF)]
figure()
plot(days, tempF, mstring('.-'))
hold(mstring('on'))
plot(days, threshold * ones(size(days)), mstring('k--'))
hold(mstring('off'))
titletext = sprintf(mcat([mstring('Total number of days exceeding threshold: %d. '), mstring('Longest warm period: %d days.')]), nday, nday_consecutive); print titletext
title(titletext)
xlabel(mstring('Day'))
ylabel(mstring('Temperature (F)'))
outputImageFileName = sprintf(mstring('BootCamp_PartA_Plot_Temperatures.png'))
_print(mstring('-dpng'), outputImageFileName)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.