Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote