示例#1
0
    def test_get_min_max_from_file(self):
        mi, ma = readers.get_min_max_timestamp(
            self.filename_format_header_values)
        assert mi == datetime(2007, 1, 1, 1)
        assert ma == datetime(2007, 1, 31, 23)

        mi, ma = readers.get_min_max_timestamp(
            self.filename_format_ceop_sep)
        assert mi == datetime(2007, 1, 1, 1)
        assert ma == datetime(2007, 1, 31, 23)

        mi, ma = readers.get_min_max_timestamp(
            self.filename_format_ceop)
        assert mi == datetime(2010, 10, 21, 1)
        assert ma == datetime(2010, 10, 22, 19)
示例#2
0
    def get_min_max_obs_timestamp(self, variable="soil moisture", min_depth=None, max_depth=None):
        """
        goes throug the filenames associated with a station
        and reads the date of the first and last observation to get
        and approximate time coverage of the station.
        This is just an overview. If holes have to be detected the
        complete file must be read.

        Parameters
        ----------
        self: type
            description
        variable: string, optional
            one of
                * 'soil moisture',
                * 'soil temperature',
                * 'soil suction',
                * 'precipitation',
                * 'air temperature',
                * 'field capacity',
                * 'permanent wilting point',
                * 'plant available water',
                * 'potential plant available water',
                * 'saturation',
                * 'silt fraction',
                * 'snow depth',
                * 'sand fraction',
                * 'clay fraction',
                * 'organic carbon',
                * 'snow water equivalent',
                * 'surface temperature',
                * 'surface temperature quality flag original'
        min_depth : float, optional
            depth_from of variable has to be >= min_depth in order to be
            included.
        max_depth : float, optional
            depth_to of variable has to be <= max_depth in order to be
            included.
        Returns
        -------
        start_date: datetime
        end_date: datetime
        """
        start_date = None
        end_date = None

        if min_depth is None:
            min_depth = np.min(self.depth_from)
        if max_depth is None:
            max_depth = np.max(self.depth_to)

        for var, d1, d2, filename in zip(self.variables, self.depth_from, self.depth_to, self.filenames):

            if var == variable and ((d1 >= min_depth) & (d2 <= max_depth)):
                sdate, edate = readers.get_min_max_timestamp(filename)
                if start_date is None or start_date > sdate:
                    start_date = sdate
                if end_date is None or end_date < edate:
                    end_date = edate

        return start_date, end_date