Exemple #1
0
    def generate_temporal_sampling(S2_dir, start_date=False, last_date=False, day_interval=5, save_csv=False):
        """
        Generate sample time for gap-filling of Time Series

        Parameters
        -----------
        S2_dir : str
            path of the folder where zip or unzipped S2 tiles are.
        start_date : False str or int, default false.
            If str or int, use %Y%m%d format, e.g. '20180130'.
        end_date : False, str or int, default False.
            If str or int, use %Y%m%d format, e.g. '20181230'.
        day_interval : int, default 5
            The delta days interval from the first acquistion to the last
        save_csv : False or str, default False
            If str, path where the csv file will be saved.
        """
        # =============================================================================
        #     List all subfolders which begins with SENTINEL2
        #     if no last_date and start_date given
        # =============================================================================
        AcquisitionDates = [start_date, last_date]
        if last_date is False or start_date is False:
            S2 = glob.glob(glob.os.path.join(S2_dir, 'SENTINEL2*/'))

            # if no folder, looking for zip files
            if S2 == []:
                S2 = glob.glob(glob.os.path.join(S2_dir, 'SENTINEL2*.zip'))

            else:
                S2 = [glob.os.path.basename(glob.os.path.dirname(S2Folder))
                      for S2Folder in S2]

            # ==========================================================================
            #     Detecting YYYYMMDD date format
            # ==========================================================================

            import re
            regexYYYYMMDD = r"(?<!\d)(?:(?:20\d{2})(?:(?:(?:0[13578]|1[02])31)|(?:(?:0[1,3-9]|1[0-2])(?:29|30)))|(?:(?:20(?:0[48]|[2468][048]|[13579][26]))0229)|(?:20\d{2})(?:(?:0?[1-9])|(?:1[0-2]))(?:0?[1-9]|1\d|2[0-8]))(?!\d)"
            p = re.compile(regexYYYYMMDD)

            AcquisitionDates = sorted(
                [p.findall(S2folder)[0] for S2folder in S2])

        if start_date is False:
            start_date = AcquisitionDates[0]
        if last_date is False:
            last_date = AcquisitionDates[-1]

        from museopheno.time_series import generate_temporal_sampling

        return generate_temporal_sampling(AcquisitionDates[0], AcquisitionDates[-1], day_interval=day_interval, save_csv=save_csv)
Exemple #2
0
######################
# import library
# ---------------

from museopheno.time_series import generate_temporal_sampling

###############################
# Generate acquistion date file
# ----------------------------------

start_date = '20171120'
last_date = '20180505'
delta = 5
acquisition_dates = generate_temporal_sampling(start_date='20171120',
                                               last_date='20180505',
                                               day_interval=delta)

print(
    'There are {} dates between {} and {} using an interval of {} days'.format(
        len(acquisition_dates), start_date, last_date, delta))

delta = 10
acquisition_dates = generate_temporal_sampling(start_date='20171120',
                                               last_date='20180505',
                                               day_interval=delta)

print(
    'There are {} dates between {} and {} using an interval of {} days'.format(
        len(acquisition_dates), start_date, last_date, delta))
Exemple #3
0
from museopheno import time_series

###############################
# Create example values
# ----------------------------------------------------

#######################################
# Initially these values came from the LCHloC spectral index
x = np.asarray([3.4825737, 4.27786  , 5.0373, 4.7196426, 4.1233397, 4.0338645,2.7735472])    

dates = [20180429, 20180513, 20180708, 20180815, 20180915, 20181015, 20181115]

#########################################
# Resample to every 5 days
# ----------------------------
dates_5days = time_series.generate_temporal_sampling(dates[0],dates[-1],5)
    
ts = time_series.SmoothSignal(dates=dates,output_dates = dates_5days)

#######################
# savitzski golay
# ----------------------------

# Savitzski golay can use several interpolation type before smoothing the trend

#######################
# Savitzski golay from linear interpolation

x_savgol_linear = ts.savitzski_golay(x,window_length=9,polyorder=1,interpolation_params=dict(kind='linear'))

#######################