示例#1
0
def RetrieveData(Date, args):
    """
    This function retrieves MOD13 NDVI data for a given date from the
    http://e4ftl01.cr.usgs.gov/ server.

    Keyword arguments:
    Date -- 'yyyy-mm-dd'
    args -- A list of parameters defined in the DownloadData function.
    """

    # WAPOR modules
    import pyWAPOR.Functions.Processing_Functions as PF

    # Argument
    [
        output_folder, TilesVertical, TilesHorizontal, latlim, lonlim,
        username, password, hdf_library
    ] = args

    # Define output file
    NDVIfileName = os.path.join(
        output_folder, 'NDVI_MYD13Q1_-_16-daily_' + Date.strftime('%Y') + '.' +
        Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')

    if not os.path.exists(NDVIfileName):

        # Collect the data from the MODIS webpage and returns the data and lat and long in meters of those tiles
        try:
            Collect_data(TilesHorizontal, TilesVertical, Date, username,
                         password, output_folder, hdf_library)

            # Define the output name of the collect data function
            name_collect = os.path.join(output_folder, 'Merged.tif')

            # Reproject the MODIS product to epsg_to
            epsg_to = '4326'
            name_reprojected = PF.reproject_MODIS(name_collect, epsg_to)

            # Clip the data to the users extend
            data, geo = PF.clip_data(name_reprojected, latlim, lonlim)

            # Save results as Gtiff
            PF.Save_as_tiff(name=NDVIfileName,
                            data=data,
                            geo=geo,
                            projection='WGS84')

            # remove the side products
            os.remove(name_collect)
            os.remove(name_reprojected)

        except:
            print("Was not able to download the file")

    return True
示例#2
0
def RetrieveData(Date, args):
    """
    This function retrieves MYD11 LST data for a given date from the
    https://e4ftl01.cr.usgs.gov/ server.

    Keyword arguments:
    Date -- 'yyyy-mm-dd'
    args -- A list of parameters defined in the DownloadData function.
    """
    
    # WAPOR modules
    import pyWAPOR.Functions.Processing_Functions as PF
    
    # Argument
    [output_folder, TilesVertical, TilesHorizontal,lonlim, latlim, username, password, hdf_library] = args
    
    # Define output names
    LSTfileName = os.path.join(output_folder, 'LST_MYD11A1_K_daily_' + Date.strftime('%Y') + '.' + Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')
    TimefileName = os.path.join(output_folder, 'Time_MYD11A1_hour_daily_' + Date.strftime('%Y') + '.' + Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')    
    OnsangfileName = os.path.join(output_folder, 'Angle_MYD11A1_degrees_daily_' + Date.strftime('%Y') + '.' + Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')    

    if not (os.path.exists(LSTfileName) and os.path.exists(TimefileName)):

        # Collect the data from the MODIS webpage and returns the data and lat and long in meters of those tiles
        try:
            Collect_data(TilesHorizontal, TilesVertical, Date, username, password, output_folder, hdf_library)
        
            # Define the output name of the collect data function
            name_collect = os.path.join(output_folder, 'Merged.tif')
            name_collect_time = os.path.join(output_folder, 'Merged_Time.tif')
            name_collect_obsang = os.path.join(output_folder, 'Merged_Obsang.tif')
            
            # Reproject the MODIS product to epsg_to
            epsg_to ='4326'
            name_reprojected = PF.reproject_MODIS(name_collect, epsg_to)
            name_reprojected_time = PF.reproject_MODIS(name_collect_time, epsg_to)
            name_reprojected_obsang = PF.reproject_MODIS(name_collect_obsang, epsg_to)
            
            # Clip the data to the users extend
            data, geo = PF.clip_data(name_reprojected, latlim, lonlim)
            data_time, geo = PF.clip_data(name_reprojected_time, latlim, lonlim)
            data_obsang, geo = PF.clip_data(name_reprojected_obsang, latlim, lonlim)
            
            # remove wrong values
            data[data==0.] = -9999
            data_time[data_time==25.5] = -9999
           
            # Save results as Gtiff 
            PF.Save_as_tiff(name=LSTfileName, data=data, geo=geo, projection='WGS84')
            PF.Save_as_tiff(name=TimefileName, data=data_time, geo=geo, projection='WGS84')
            PF.Save_as_tiff(name=OnsangfileName, data=data_obsang, geo=geo, projection='WGS84')
             
            # remove the side products
            os.remove(name_collect)
            os.remove(name_reprojected)
            os.remove(name_collect_time)
            os.remove(name_reprojected_time) 
            os.remove(name_collect_obsang)
            os.remove(name_reprojected_obsang)             
        except:
            print("Was not able to download the file")

    return True