Пример #1
0
def curtain_for_line(data, X, Y, coords, day=0, numk=0):
    """
    extracts curtain data from a grid given pairs of lon, lat

    input:  H (a pf.Header with a FD data object from H.read_grid)
            if the read_grid method has not been called, we'll call
            it below.

            flighttrack
            (a numpy array with datetime, lon, lat, elv values)

            nspec: is optional for reference to the FD dict.

            index: is optional in case numpointspec > 1

            get_track: if True extracts the points along the flight
            track rather than the curtain.

    output: curtain (a 2-d array with shape (len(flighttrack), len(H.outheight)

    TODO::
        add interpolation, extract a track, not curtain (e.g. z points)

    """
    grid = data.data_cube
    grid = grid[:, :, :, day, numk]

    curtain = np.zeros((len(coords), grid.shape[2]))
    for i, (x, y) in enumerate(coords):
        I = closest(x, X)
        J = closest(y, Y)
        curtain[i] = grid[I, J, :]
        curtain = np.nan_to_num(curtain)
        # curtain = np.ma.fix_invalid(np.array(curtain,dtype=float))

    return curtain.T
Пример #2
0
def curtain_for_line(data, X, Y, coords, day=0, numk=0):
    """
    extracts curtain data from a grid given pairs of lon, lat

    input:  H (a pf.Header with a FD data object from H.read_grid)
            if the read_grid method has not been called, we'll call
            it below.

            flighttrack
            (a numpy array with datetime, lon, lat, elv values)

            nspec: is optional for reference to the FD dict.

            index: is optional in case numpointspec > 1

            get_track: if True extracts the points along the flight
            track rather than the curtain.

    output: curtain (a 2-d array with shape (len(flighttrack), len(H.outheight)

    TODO::
        add interpolation, extract a track, not curtain (e.g. z points)

    """
    grid = data.data_cube
    grid = grid[:, :, :, day, numk]

    curtain = np.zeros((len(coords), grid.shape[2]))
    for i, (x, y) in enumerate(coords):
        I = closest(x, X)
        J = closest(y, Y)
        curtain[i] = grid[I, J, :]
        curtain = np.nan_to_num(curtain)
        # curtain = np.ma.fix_invalid(np.array(curtain,dtype=float))

    return curtain.T
Пример #3
0
    def closest_date(self, dateval, fmt=None):
        """
        given a datestring or datetime, tries to find the closest date.
        if passed a list, assumes it is a list of datetimes
        """

        if isinstance(dateval, str):
            if not fmt:
                if len(dateval) == 8:
                    fmt = '%Y%m%d'
                if len(dateval) == 14:
                    fmt = '%Y%m%d%H%M%S'
                else:
                    raise IOError("no format provided for datestring")
            print("Assuming date format: {0}".format(fmt))
            dateval = dt.datetime.strptime(dateval, fmt)

        return closest(dateval, self['available_dates_dt'])