Exemplo n.º 1
0
def threshold(
    data, threshold=-7.6, cloud=-5, returnfield=False, binsize=0, inTime=True, continuous=False, vertbin=5, **kwargs
):
    """
    for a formatted backsctter dataset, determine a timeseries of the lowest incidence
    of the specified backscatter value, regardless of mathematical base.
    
    Parameters
    ----------
    threshold: float, optional
        specify the cutoff value for the threshold to be determined from the bottom up
        
    data: numpy 2-d array
        the dataset from which the thresholds are determined 
    """
    if data == "about":
        "Then something just wants an info string about the method, so spit it out"
        return "010Threshold"
    if binsize == 0:
        "no binning or averaging or whatnot is to be done."
        z = data["height"]
        t = data["time"]
        data = data["bs"]
    else:
        data, t, z = u._ComputeFieldMeans(data, binsize, inTime=inTime, continuous=continuous, vertbin=vertbin)
    if returnfield:
        return (data, t, z)
    depth = u._ThresholdLT(data, z, threshold, limit=1200)
    del data
    return (depth, t)
Exemplo n.º 2
0
def idealized_multiple(
    data,
    binsize=300,
    returnfield=False,
    inTime=True,
    savebin=False,
    continuous=False,
    guessmean=False,
    guessheight=False,
    vertbin=5,
    limit=1000,
    background=-8.2,
    threshold=-7.6,
    **kwargs
):
    """
    Use the idealized backscatter method to identify the top of the aerosol layer.
    
    This routine will use the -7.6 threshold method as a first guess, and will 
    then minimize the defined function to determine the function coefficients 
    
    This is from the method proposed by Eresmaa et al 2012
    
    Parameters
    ----------
    
    data: list
        The produced output from the slice for ceilometer data for the time 
        period analyzed
    binsize: int, optional
        the length in SECONDS for bins to be produced. Longer bins increase 
        the chance of success
    returnfield: bool, optional
        return only the field analyzed, not very useful for this operation.
    inTime: bool, optional
        specify if the provided time dimension is actually epoch time stamps, 
        or just bin numbers
    savebin: str, optional
        only save a demonstrative figure of a single bin. A possibly useful 
        demonstration operation. 
    background: float, optional
        set the background (low value) approximation. The current value is -8.2,
        which is sufficient for Vaisala CL31 ceilometer backscatter in (m*sr)^-1
        units.
   
    """
    l.warning("The mutli-layer idealized profile method has not been implemented")
    exit()
    if data == "about":
        "Then something just wants an info string about the method, so spit it out"
        return "100Idealized Profile"
    from scipy import optimize, special

    bs, times, z = u._ComputeFieldMeans(data, binsize, inTime=inTime, continuous=continuous, vertbin=vertbin)
    bs, z = bs[:, : limit / 10], z[: limit / 10]
    "no, this method will not use power"
    if returnfield:
        return (bs, times, z)
    if guessmean and guessheight:
        "A fixed guess mean has been assigned"
        first_guesses = [guessheight for x in times]
        first_guess_mean = [guessmean for x in times]
    else:
        print "Applying threshold theory"
        first_guesses = u._ThresholdLT(bs, z, threshold)
        "compute the low-level means from the 5th ob up to the guess height"
        guess_mean_func = lambda x: np.mean(bs[x][z <= first_guesses[x]])
        first_guess_mean = map(guess_mean_func, range(len(first_guesses)))

    "now, for each time bin, we will run the optimization"
    outH = np.zeros(len(times))
    outdH = np.zeros(len(times))
    for i in range(len(times)):
        """
        make first guesses and fix the two variables
        """
        b = bs[i]  # the backscatter profile
        h = first_guesses[i]  # first guess height (a very good guess)]
        dh = 100.0  # guess value of dh, based on observation
        "for now we are always assuming a 100m transition layer until told otherwise"
        p0 = [h, dh]
        if h == 0:
            continue
        bm = first_guess_mean[i]  # approximation for boundary layer intensity
        bu = background  # approximation for free atmosphere intensity
        "There are two coefficients, A1 and A2, and one is fixed for the fitting"
        a1 = (bm + bu) / 2.0
        a2 = (bm - bu) / 2.0
        fitfunc = lambda p, z: a1 - a2 * special.erf((z - p[0]) / p[1])
        errfunc = lambda p, z, bs: np.sum((fitfunc(p, z) - bs) ** 2)
        # print errfunc(p0,height,b)
        p1 = optimize.fmin(errfunc, p0, args=(z, b))
        print p1
        outH[i] = p1[0]
        outdH[i] = p1[1]

        if savebin:
            "this code can just save an example bin plot."
            import matplotlib.pyplot as plt

            plt.plot(fitfunc(p1, z), z)
            plt.plot(b, z)
            plt.xlabel("Bakscatter ($m^{-1}sr^{-1}$)")
            plt.ylabel("Height AGL (m)")
            plt.savefig(savebin)
            "in this case, this is the only operation engaged by the code."
            return True
    "this can solve to some bizzaro solutions, so we need to filter realistic values"
    outH[(outH > limit) | (outH < 0)] = 0
    outdH[(outdH > limit) | (outdH < -limit)] = 0
    return (outH, times, outdH, first_guess_mean)