Location>code7788 >text

Finding missing, incoherent imaging dates in a large number of time-series remote sensing files: a Python code

Popularity:397 ℃/2024-10-14 11:26:37

  This paper describes the batch download of a large number of multi-temporal remote sensing image files based on thePythonlanguage with the file name of each view's remote sensing image file, for theseDownloaded image filesChecks for deficiencies are added and are automatically counted and listed.No images downloadedThe method of the corresponding temporal phase.

  batch downloadLarge number of remote sensing image filesinsofar asRSStudents and practitioners can be very common. In our previous paper, we introduced a method to count the unsuccessful remote sensing images and automatically filter out the download links of unsuccessful remote sensing images, also based on the file name; in this paper, we also based on thePythonWith the raster file'sName of the documentThe need for similar requirements has been realized.

  First of all, the requirements of this article are slightly different from the previously mentioned articles. Here, we have downloaded a good amount of it,Remote sensing data imaging time as file nameof the raster file, as shown below.

image

  Among other things, it is easy to see that the remote sensing imagery data we have here is taken from each year's001Starting on the day, every8The name of each scene image is followed by the name of the scene image.3The number of digits is001009017The format for expressing the number of days in this way; in addition, the former4The digits indicate the year, and we have here from2020initial2022End, total3Remote sensing image data for the year.

  Now, we would like to check the above documents to see what is going on in this3In the middle of the year, whether there are any remote sensing image files that were not successfully downloaded; if so, it is also desired to output the number of files that failed to be downloaded and the corresponding file names (i.e., the imaging time of the corresponding files).

  After clarifying the requirements, we can start the specific operation. First of all, the code required for this article is as follows.

# -*- coding: utf-8 -*-
"""
Created on Sat Dec 30 23:32:54 2023

@author: fkxxgis
"""

import os

def check_missing_dates(folder_path):
    start_year = 2020
    end_year = 2022
    days_per_file = 8

    missing_dates = []

    for year in range(start_year, end_year + 1):
        for day in range(1, 366, days_per_file):
            file_name = str(year) + "{:03d}".format(day) + ".tif"
            file_path = (folder_path, file_name)
            
            if not (file_path):
                missing_dates.append(file_name[:-4])

    return missing_dates

folder_path = "F:/Data_Reflectance_Rec/NDVI"
missing_dates = check_missing_dates(folder_path)

print("Total missing dates:", len(missing_dates))
print("Missing dates:")
for date in missing_dates:
    print(date)

  The overall idea of this code is also clear.

  First, we import the required modules. Here.osmodule for file path operations.

  Next, we define a file namedcheck_missing_datesfunction that takes a folder path as an argument; this function is used to check for missing dates. In this function, we define the starting yearstart_yearand end yearend_yearand the date interval between each documentdays_per_file; subsequently, create an empty listmissing_dates, used to store missing dates.

  We then iterate through each year and each day using nested loops. In each day's loop, construct filenames such as"", and build the full path to the file. Next, use the()function checks if the file path exists - if the file does not exist, the date is added to the list of missing datesmissing_datesin. At the end of the loop, the list of missing dates is returnedmissing_dates

  Outside of the function, we define the path to the folder to be examinedfolder_path, and then you can call thecheck_missing_datesfunction, passed a folder path argument, performs a date check and assigns the returned list of missing dates to themissing_dates

  Finally, we print the total number of missing dateslen(missing_dates), and print each specific missing date.

  Execute the above code to get the result as shown below. That is, in my case, there are currently8The remote sensing image files for the dates were not downloaded successfully, and we then checked against this8The date of the remote sensing image can be downloaded by going back to the relevant website.

  At this point, the job is done.