Exemple #1
0
def cc_gamma_temp(*args):

    temp = args[0]

    # make array of tempchnge from yesterday to today
    dtemp = pz.delta_temperature_from_temperature(temp)

    return cc_gamma_temp_change(dtemp, args[1])
Exemple #2
0
def cc_gamma_temp(*args):

    temp = args[0]

    # make array of tempchnge from yesterday to today
    dtemp = pz.delta_temperature_from_temperature(temp)

    return cc_gamma_temp_change(dtemp, args[1])
def makeSomeScatterPlots(stnr, startDate, endDate):

    import numpy as numpy
    import matplotlib.pyplot as plt
    from scipy.stats import gaussian_kde


    wsTemp = getMetData(stnr, 'TAM', startDate, endDate, 0, 'list')
    wsPrec = getMetData(stnr, 'RR', startDate, endDate, 0, 'list')
    wsCC = getMetData(stnr, 'NNM', startDate, endDate, 0, 'list')

    temp, date = strip_metadata(wsTemp, get_dates=True)
    prec = strip_metadata(wsPrec, False)
    clouds = strip_metadata(wsCC, False)

    dTemp = dpz.delta_temperature_from_temperature(temp)
    abs_dTemp = map(abs, dTemp)

    method = 'dTemp_with_limit_vs_clouds'

    if method == 'dTemp_with_limit_vs_clouds':

        # Calibration params
        limit_temperature = [7]

        for limit_temp in limit_temperature:

            # Mask out positions in list where temps are above and below the threshhold temp
            temp_filter_high = []
            temp_filter_low = []
            for t in temp:
                if t >= limit_temp:
                    temp_filter_high.append(1.)
                    temp_filter_low.append(0.)
                else:
                    temp_filter_high.append(0.)
                    temp_filter_low.append(1.)

            # And make lists of dTemp_abs beloning to either high or low bands relative the threshhold temp
            dTemp_low_abs = [dt*tfl for dt,tfl in zip(abs_dTemp, temp_filter_low)]
            dTemp_high_abs = [dt*tfh for dt,tfh in zip(abs_dTemp, temp_filter_high)]

            fsize = (20, 20)
            plt.figure(figsize=fsize)
            plt.clf()

            #### Generate data
            x = [round(dtla,1) for dtla in dTemp_low_abs]
            y = [round(cc,2) for cc in clouds]

            # Calculate the point density
            xy = np.vstack([x,y])
            z = gaussian_kde(xy)(xy)

            plt.subplot(2,2,1).scatter(x, y, c=z, s=100, edgecolor='')
            plt.title("dtemp vs clouds (temp < {3}C) {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7], limit_temp))

            ##### Generate data
            x = [round(dtha, 1) for dtha in dTemp_high_abs]
            y = clouds

            # Calculate the point density
            xy = np.vstack([x,y])
            z = gaussian_kde(xy)(xy)

            plt.subplot(2,2,2).scatter(x, y, c=z, s=100, edgecolor='')
            plt.title("dtemp vs clouds (temp >= {3}C) {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7], limit_temp))


            plt.subplot(2,2,3).hist(z)


            fileName = "scatter dtemp vs clouds temp_limit{3} {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7], limit_temp)
            plt.savefig("{0}{1}".format(plot_folder, fileName))

    if method == 'dTemp_density':

        # Generate  data
        x = abs_dTemp
        y = clouds

        # Calculate the point density
        xy = np.vstack([x,y])
        z = gaussian_kde(xy)(xy)

        fig, ax = plt.subplots()
        ax.scatter(x, y, c=z, s=100, edgecolor='')

        plt.title("scatter dtemp_density clouds {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7]))
        fileName = "scatter dtemp_density {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7])

        plt.savefig("{0}{1}".format(plot_folder, fileName))

    if method == 'prec':

        fsize = (10, 10)
        plt.figure(figsize=fsize)
        plt.clf()

        plt.title("scatter prec clouds {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7]))
        fileName = "scatter prec clouds {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7])

       # Generate data
        x = prec
        y = clouds

        # Calculate the point density
        xy = np.vstack([x,y])
        z = gaussian_kde(xy)(xy)

        plt.scatter(x, y, c=z, s=100, edgecolor='')

        # calc the trendline
        z = numpy.polyfit(prec, clouds, 1)
        p = numpy.poly1d(z)
        plt.plot(prec, p(prec) )

        # the line equation:
        line_equation = "clouds = %.6f*prec + %.6f"%(z[0],z[1])
        plt.text(0.0, -0.1, 'Line equation: {0}'.format(line_equation))

        plt.savefig("{0}{1}".format(plot_folder, fileName))





    return
def correlateCloudsAndTemp(stnr, startDate, endDate):
    """
    DEAD END

    This was an attempt to check different functions of temperature and how well they correlate with an observed
    cloudcover. It turned out all different functions represent different signals so a cross correlation test and
    finding wich has the highest number whont work because the correlation number wil be different from function to
    function.

    :param stnr:
    :param startDate:
    :param endDate:
    :return:

    SELECT * FROM corrCCandTemp
    where loggdate = '2015-02-09 15:57:44.287000'
    order by crossCorr desc

    """


    wsTemp = getMetData(stnr, 'TAM', startDate, endDate, 0, 'list')
    wsCC = getMetData(stnr, 'NNM', startDate, endDate, 0, 'list')

    temp = strip_metadata(wsTemp, False)
    clouds = strip_metadata(wsCC, False)

    oneMinusClouds = [1-cc for cc in clouds]
    dTemp = dpz.delta_temperature_from_temperature(temp)
    abs_dTemp = map(abs, dTemp)
    #sum = [cc + mcc for cc, mcc in zip(clouds,oneMinusClouds)]

    loggdate = datetime.datetime.now()
    period = '{0} to {1}'.format(startDate,endDate)

    tempOffset = [0] #range(-5,6,1)
    dTempOffset = [0] #range(-3,4,1)
    ccShift = range(-4,5,1)
    sign_temp_dependant = [False]
    sign_dTemp_dependant = [False]
    useOneMinusClouds = [False]  # one minus cloudcover

    estimateSimulations = len(tempOffset)*len(dTempOffset) * len(ccShift) * len(sign_temp_dependant) * len(sign_dTemp_dependant) * len(useOneMinusClouds)
    doneSimulations = 0

    for cs in ccShift:
        for to in tempOffset:
            for dto in dTempOffset:
                for depdT in sign_dTemp_dependant:
                    for depT in sign_temp_dependant:
                        for omc in useOneMinusClouds:

                            sign_dTemp = 0
                            sign_temp = 0
                            ccwithoffset = 0

                            # if dTempExpression is not dependant of the signs of temp and dTemp the expression is reduced
                            # to only the abolute value of dTemp
                            if depdT == True:
                                sign_dTemp = __getSign(dTemp, dto)
                            else:
                                sign_dTemp = [1.]*len(temp)

                            if depT == True:
                                sign_temp = __getSign(temp, to)
                            else:
                                sign_temp = [1.]*len(temp)

                            # are we looking at cloud cover or clear skies? Does it matter?
                            if omc == True: # this option would be fraction og clear skies
                                ccwithoffset = __shiftClouds(oneMinusClouds, cs)
                            else:
                                ccwithoffset = __shiftClouds(clouds, cs)

                            dTempExpression = [sdt*adt*st for sdt,adt,st in zip(sign_dTemp,abs_dTemp,sign_temp)]
                            crossCorr = np.correlate(dTempExpression, ccwithoffset)

                            a = 1
                            __writeCorrelation2database(database_location,  cs, to, dto, depdT, depT, omc, crossCorr[0], loggdate, period, stnr)

                            doneSimulations = doneSimulations + 1
                            print('beregning {0} av {1}'.format(doneSimulations, estimateSimulations))

    return
Exemple #5
0
def makeSomeScatterPlots(stnr, startDate, endDate):

    import numpy as numpy
    import matplotlib.pyplot as plt
    from scipy.stats import gaussian_kde


    wsTemp = getMetData(stnr, 'TAM', startDate, endDate, 0, 'list')
    wsPrec = getMetData(stnr, 'RR', startDate, endDate, 0, 'list')
    wsCC = getMetData(stnr, 'NNM', startDate, endDate, 0, 'list')

    temp, date = strip_metadata(wsTemp, get_dates=True)
    prec = strip_metadata(wsPrec, False)
    clouds = strip_metadata(wsCC, False)

    dTemp = dpz.delta_temperature_from_temperature(temp)
    abs_dTemp = map(abs, dTemp)

    method = 'dTemp_with_limit_vs_clouds'

    if method == 'dTemp_with_limit_vs_clouds':

        # Calibration params
        limit_temperature = [7]

        for limit_temp in limit_temperature:

            # Mask out positions in list where temps are above and below the threshhold temp
            temp_filter_high = []
            temp_filter_low = []
            for t in temp:
                if t >= limit_temp:
                    temp_filter_high.append(1.)
                    temp_filter_low.append(0.)
                else:
                    temp_filter_high.append(0.)
                    temp_filter_low.append(1.)

            # And make lists of dTemp_abs beloning to either high or low bands relative the threshhold temp
            dTemp_low_abs = [dt*tfl for dt,tfl in zip(abs_dTemp, temp_filter_low)]
            dTemp_high_abs = [dt*tfh for dt,tfh in zip(abs_dTemp, temp_filter_high)]

            fsize = (20, 20)
            plt.figure(figsize=fsize)
            plt.clf()

            #### Generate data
            x = [round(dtla,1) for dtla in dTemp_low_abs]
            y = [round(cc,2) for cc in clouds]

            # Calculate the point density
            xy = np.vstack([x,y])
            z = gaussian_kde(xy)(xy)

            plt.subplot(2,2,1).scatter(x, y, c=z, s=100, edgecolor='')
            plt.title("dtemp vs clouds (temp < {3}C) {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7], limit_temp))

            ##### Generate data
            x = [round(dtha, 1) for dtha in dTemp_high_abs]
            y = clouds

            # Calculate the point density
            xy = np.vstack([x,y])
            z = gaussian_kde(xy)(xy)

            plt.subplot(2,2,2).scatter(x, y, c=z, s=100, edgecolor='')
            plt.title("dtemp vs clouds (temp >= {3}C) {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7], limit_temp))


            plt.subplot(2,2,3).hist(z)


            fileName = "scatter dtemp vs clouds temp_limit{3} {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7], limit_temp)
            plt.savefig("{0}{1}".format(plot_folder, fileName))

    if method == 'dTemp_density':

        # Generate  data
        x = abs_dTemp
        y = clouds

        # Calculate the point density
        xy = np.vstack([x,y])
        z = gaussian_kde(xy)(xy)

        fig, ax = plt.subplots()
        ax.scatter(x, y, c=z, s=100, edgecolor='')

        plt.title("scatter dtemp_density clouds {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7]))
        fileName = "scatter dtemp_density {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7])

        plt.savefig("{0}{1}".format(plot_folder, fileName))

    if method == 'prec':

        fsize = (10, 10)
        plt.figure(figsize=fsize)
        plt.clf()

        plt.title("scatter prec clouds {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7]))
        fileName = "scatter prec clouds {0} {1} {2}.png".format(stnr, startDate[0:7], endDate[0:7])

       # Generate data
        x = prec
        y = clouds

        # Calculate the point density
        xy = np.vstack([x,y])
        z = gaussian_kde(xy)(xy)

        plt.scatter(x, y, c=z, s=100, edgecolor='')

        # calc the trendline
        z = numpy.polyfit(prec, clouds, 1)
        p = numpy.poly1d(z)
        plt.plot(prec, p(prec) )

        # the line equation:
        line_equation = "clouds = %.6f*prec + %.6f"%(z[0],z[1])
        plt.text(0.0, -0.1, 'Line equation: {0}'.format(line_equation))

        plt.savefig("{0}{1}".format(plot_folder, fileName))





    return
Exemple #6
0
def correlateCloudsAndTemp(stnr, startDate, endDate):
    """
    DEAD END

    This was an attempt to check different functions of temperature and how well they correlate with an observed
    cloudcover. It turned out all different functions represent different signals so a cross correlation test and
    finding wich has the highest number whont work because the correlation number wil be different from function to
    function.

    :param stnr:
    :param startDate:
    :param endDate:
    :return:

    SELECT * FROM corrCCandTemp
    where loggdate = '2015-02-09 15:57:44.287000'
    order by crossCorr desc

    """


    wsTemp = getMetData(stnr, 'TAM', startDate, endDate, 0, 'list')
    wsCC = getMetData(stnr, 'NNM', startDate, endDate, 0, 'list')

    temp = strip_metadata(wsTemp, False)
    clouds = strip_metadata(wsCC, False)

    oneMinusClouds = [1-cc for cc in clouds]
    dTemp = dpz.delta_temperature_from_temperature(temp)
    abs_dTemp = map(abs, dTemp)
    #sum = [cc + mcc for cc, mcc in zip(clouds,oneMinusClouds)]

    loggdate = datetime.datetime.now()
    period = '{0} to {1}'.format(startDate,endDate)

    tempOffset = [0] #range(-5,6,1)
    dTempOffset = [0] #range(-3,4,1)
    ccShift = range(-4,5,1)
    sign_temp_dependant = [False]
    sign_dTemp_dependant = [False]
    useOneMinusClouds = [False]  # one minus cloudcover

    estimateSimulations = len(tempOffset)*len(dTempOffset) * len(ccShift) * len(sign_temp_dependant) * len(sign_dTemp_dependant) * len(useOneMinusClouds)
    doneSimulations = 0

    for cs in ccShift:
        for to in tempOffset:
            for dto in dTempOffset:
                for depdT in sign_dTemp_dependant:
                    for depT in sign_temp_dependant:
                        for omc in useOneMinusClouds:

                            sign_dTemp = 0
                            sign_temp = 0
                            ccwithoffset = 0

                            # if dTempExpression is not dependant of the signs of temp and dTemp the expression is reduced
                            # to only the abolute value of dTemp
                            if depdT == True:
                                sign_dTemp = __getSign(dTemp, dto)
                            else:
                                sign_dTemp = [1.]*len(temp)

                            if depT == True:
                                sign_temp = __getSign(temp, to)
                            else:
                                sign_temp = [1.]*len(temp)

                            # are we looking at cloud cover or clear skies? Does it matter?
                            if omc == True: # this option would be fraction og clear skies
                                ccwithoffset = __shiftClouds(oneMinusClouds, cs)
                            else:
                                ccwithoffset = __shiftClouds(clouds, cs)

                            dTempExpression = [sdt*adt*st for sdt,adt,st in zip(sign_dTemp,abs_dTemp,sign_temp)]
                            crossCorr = np.correlate(dTempExpression, ccwithoffset)

                            a = 1
                            __writeCorrelation2database(database_location,  cs, to, dto, depdT, depT, omc, crossCorr[0], loggdate, period, stnr)

                            doneSimulations = doneSimulations + 1
                            print('beregning {0} av {1}'.format(doneSimulations, estimateSimulations))

    return