<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 First, I'm going to define a function that will print the power (watts per square meter)that the earth would receive from the sun if there were no atmosphere.
Step1:  Now I'm going to take the above function and do the same thing except make it print the number of Wh in one square meter for a year.
Step2:  Loading Cloud Data
The cloud cover data I am using is International Satellite Cloud Climatology Project (ISCCP). To understand this data in its raw form, visualize a map of the world overlayed by a grid of squares.  Each square is 2.5 degrees in width and height, so the grid is 144 x 72 (longitude x latitude) and has a total of 10368 squares. Each number in the data is the average annual cloud cover percentage for a single square. The first number represents average cloud cover  in the -90 degrees latitude, -180 degrees longitude box. Longitude varies first, and begins at -180 degrees and proceeds eastward to +180 degrees. Latitude begins at -90 degrees and proceeds northward to +90 degrees.
Step3:  Now, 'clouds' is a nice looking dataframe that includes lattitude, longitude, and average sun that gets through the clouds for every month and the entire world
Now I will make a function that takes lattitude and longitude as an input and returns sun_ratio for each month as an output
Step4:  Making a Plot of the Data
<ASSISTANT_TASK:>
Python Code:
def Solar_Power_Calculator(Day_Of_Year,Lattitude,Hour_of_Day):
    '''This function will tell you how much power the sun is '''
    # Calculating Theta D
    ThetaD = (2*np.pi*Day_Of_Year)/365
    # Calculating distance
    # Constants for calculating distance
    Dis_n = [0,1,2]
    Dis_an = [1.00011,0.034221,0.000719]
    Dis_bn = [0,0.00128,0.000077]
    Dis1 = Dis_an[0]*np.cos(Dis_n[0]*ThetaD)+Dis_bn[0]*np.sin(Dis_n[0]*ThetaD)
    Dis2 = Dis_an[1]*np.cos(Dis_n[1]*ThetaD)+Dis_bn[1]*np.sin(Dis_n[1]*ThetaD)
    Dis3 = Dis_an[2]*np.cos(Dis_n[2]*ThetaD)+Dis_bn[2]*np.sin(Dis_n[2]*ThetaD)
    # Calculate Distance
    Distance = Dis1+Dis2+Dis3
    # Constants for calculating declination
    Dec_n = [0,1,2,3]
    Dec_an = [0.006918,-0.399912,-0.006758,-0.002697]
    Dec_bn = [0,0.070257,0.000907,0.00148]
    Dec1 = Dec_an[0]*np.cos(Dec_n[0]*ThetaD)+Dec_bn[0]*np.sin(Dec_n[0]*ThetaD)
    Dec2 = Dec_an[1]*np.cos(Dec_n[1]*ThetaD)+Dec_bn[1]*np.sin(Dec_n[1]*ThetaD)
    Dec3 = Dec_an[2]*np.cos(Dec_n[2]*ThetaD)+Dec_bn[2]*np.sin(Dec_n[2]*ThetaD)
    Dec4 = Dec_an[3]*np.cos(Dec_n[3]*ThetaD)+Dec_bn[3]*np.sin(Dec_n[3]*ThetaD)
    # Calculate Dec_radians
    Dec_radians = Dec1+Dec2+Dec3+Dec4
    Dec_degrees = np.degrees(Dec_radians)
    # For Hour Angle
    Hour_angle = np.radians(Hour_of_Day*15)
    # For Radians and Cos Solar Zenith Angle
    radians = np.pi/180*Lattitude
    CSZA = np.sin(radians)*np.sin(Dec_radians)+np.cos(radians)*np.cos(Dec_radians)*np.cos(Hour_angle)# Cos Solar Zenith Angle
    # Calculate Energy/Area (W/m^2)
    Watts_Per_SqMeter = S0*Distance*CSZA*Atm
    return(Watts_Per_SqMeter)
Solar_Power_Calculator(17,49.7,0)
Explanation: First, I'm going to define a function that will print the power (watts per square meter)that the earth would receive from the sun if there were no atmosphere.
End of explanation
# Making a list called total of Theta D for every day of the year
year = list(range(1,366))
ThetaD_list = []
for i in year:
    ThetaD_list.append((2*np.pi*i)/365)
len(ThetaD_list)
def Solar_Energy_Calculator(lattitude, panel_efficiency, area):
    '''This function calculates the energy that can be generated in any given place in the 
    world over one year sans clouds.  
    Inputs: lattitude, panel_efficiency (a number between 0 and 1), and area (of solar panels
    in square meters).'''
    # Making Distance and Dec_radians lists for each day of the year
    radians = np.pi/180*lattitude
    Hours = [12,11,10,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,11] # A list of all the hours of the day
    Solar_Flux = 0 # Energy generated from given area of solar panels in one hour
    Watts_Every_Hour = [] # A list that will become the Wh/m^2 every hour for a year
    kWh = 0 # A number that will become the total kWh in one place in one year.
    for i in ThetaD_list:
        # Calculate the Distance
        Dis1 = Dis_an[0]*np.cos(Dis_n[0]*i)+Dis_bn[0]*np.sin(Dis_n[0]*i)
        Dis2 = Dis_an[1]*np.cos(Dis_n[1]*i)+Dis_bn[1]*np.sin(Dis_n[1]*i)
        Dis3 = Dis_an[2]*np.cos(Dis_n[2]*i)+Dis_bn[2]*np.sin(Dis_n[2]*i)
        Distance = Dis1+Dis2+Dis3
        # Calculate the Declination
        Dec1 = Dec_an[0]*np.cos(Dec_n[0]*i)+Dec_bn[0]*np.sin(Dec_n[0]*i)
        Dec2 = Dec_an[1]*np.cos(Dec_n[1]*i)+Dec_bn[1]*np.sin(Dec_n[1]*i)
        Dec3 = Dec_an[2]*np.cos(Dec_n[2]*i)+Dec_bn[2]*np.sin(Dec_n[2]*i)
        Dec4 = Dec_an[3]*np.cos(Dec_n[3]*i)+Dec_bn[3]*np.sin(Dec_n[3]*i)
        Dec_radians = Dec1+Dec2+Dec3+Dec4
        Dec_degrees = (np.degrees(Dec_radians))
        for i in Hours:
            Hour_angle = np.radians(i*15)
            CSZA = (np.sin(radians)*np.sin(Dec_radians)) + (np.cos(radians)*np.cos(Dec_radians)*np.cos(Hour_angle))
            if CSZA < 0:
                CSZA = 0
            Solar_Flux = (S0)*Distance*CSZA*Atm*panel_efficiency*area
            Watts_Every_Hour.append(Solar_Flux)
    kWh = sum(Watts_Every_Hour)/1000
    return(Watts_Every_Hour)
Explanation: Now I'm going to take the above function and do the same thing except make it print the number of Wh in one square meter for a year.
End of explanation
# First, I'm loading the raw cloud cover data.
cloud_dat = pd.read_csv('../data/weather.txt',sep='\s+')
cloud_dat
# Right now the data is in 1 row and 10368 columns, so it requires some 
# cleaning up
cloud_dat.shape
# After transposing, the data is in 1 column and 10368 rows
cloud_dat = cloud_dat.transpose()
cloud_dat.shape
# Now I will change the name of the column of data and reset the index
cloud_dat = cloud_dat.reset_index()
cloud_dat.columns=['cloud_ratio']
# Here is a glimpse of what the data looks like now
cloud_dat
# Next, I load a dataframe that I created in excel with three columns 
# (month, lattitude, and longitude) that have been filled in to line up 
# with the 'data' object.  
clouds = pd.read_excel('../../data/blank_weather.xlsx',sep='\s+')
clouds
# Now, we will add a fourth column to 'clouds' that is our data
clouds['cloud_ratio'] = cloud_dat['cloud_ratio']
clouds
Explanation: Loading Cloud Data
The cloud cover data I am using is International Satellite Cloud Climatology Project (ISCCP). To understand this data in its raw form, visualize a map of the world overlayed by a grid of squares.  Each square is 2.5 degrees in width and height, so the grid is 144 x 72 (longitude x latitude) and has a total of 10368 squares. Each number in the data is the average annual cloud cover percentage for a single square. The first number represents average cloud cover  in the -90 degrees latitude, -180 degrees longitude box. Longitude varies first, and begins at -180 degrees and proceeds eastward to +180 degrees. Latitude begins at -90 degrees and proceeds northward to +90 degrees.
End of explanation
Watts = Solar_Energy_Calculator(49.7,.16,1.68)
def find_sun(lat,long):
    '''This function finds the ratio of clouds for any lattitude and longitude and converts
    it into the ratio of radiation that reaches the earth.
    inputs: lattitude, longitude
    output: radiation ratio'''
    x = clouds.loc[(clouds['lattitude'] <= lat) & (clouds['lattitude'] > (lat-2.5)) & (clouds['longitude'] <= long) & (clouds['longitude'] > (long-2.5))]
    radiation_ratio = 1-((float(x.iloc[0,2])*0.6)/100)
    return(radiation_ratio)
radiation = find_sun(49,-123)
radiation
def apply_clouds(watts,radiation):
    '''This function takes a list of watts without clouds and radiation ratio due to clouds
    and gives you a list of the real solar generation prediction.'''
    energy = []
    for i in watts:
        energy.append(i*radiation)
    return(energy)
final = apply_clouds(Watts,radiation)
sum(final)/1000
final = pd.DataFrame(final)
final = final.reset_index()
final.columns=['Day','Power']
final['Day'] = final['Day']/24
final
jan = sum(final.Power[0:1000])
Explanation: Now, 'clouds' is a nice looking dataframe that includes lattitude, longitude, and average sun that gets through the clouds for every month and the entire world
Now I will make a function that takes lattitude and longitude as an input and returns sun_ratio for each month as an output
End of explanation
plt.plot(final)
# change figure size
plt.figure(figsize=(12,9))
# add data to plot (x-axis, y-axis, )
plt.plot(final['Day'],final['Power'],color='b',linestyle='-')
# add title
plt.title('Power Output',fontsize=24)
# modify axis limits
plt.xlim(0,365)
# add axis labels
plt.ylabel('Average Power Generation (Watts)',fontsize=16)
plt.xlabel('Day of Year',fontsize=16)
# save figure to graphs directory
plt.savefig('TEST.pdf')
pylab.savefig("/home/username/Desktop/myfig.png")
# show plot
plt.show()
Explanation: Making a Plot of the Data
End of explanation
<END_TASK>