Ejemplo n.º 1
0
def RetrieveData(Date, args):
    """
    This function retrieves MOD9 Reflectance 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.
    """
    # Argument
    [
        output_folder, TilesVertical, TilesHorizontal, lonlim, latlim, band,
        resolution, hdf_library
    ] = args

    # 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, output_folder, band,
                     resolution, hdf_library)
    except:
        print("Was not able to download the file")

    # Define the output name of the collect data function
    name_collect = os.path.join(output_folder, 'Merged.tif')
    try:
        # Reproject the MODIS product to epsg_to
        epsg_to = '4326'
        name_reprojected = RC.reproject_MODIS(name_collect, epsg_to)

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

        # Save results as Gtiff
        ReffileName = os.path.join(
            output_folder,
            'ReflectanceBand%d_MOD09GQ_-_daily_' % band + Date.strftime('%Y') +
            '.' + Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')
        DC.Save_as_tiff(name=ReffileName,
                        data=data,
                        geo=geo,
                        projection='WGS84')

        # remove the side products
        os.remove(os.path.join(output_folder, name_collect))
        os.remove(os.path.join(output_folder, name_reprojected))
    except:
        print('data for %02d-%02d-%d is not available' %
              (Date.day, Date.month, Date.year))

    return True
Ejemplo n.º 2
0
def RetrieveData(Date, args):
    """
    This function retrieves MOD16 ET data for a given date from the
    ftp://ftp.ntsg.umt.edu/ server.

    Keyword arguments:
    Date -- 'yyyy-mm-dd'
    args -- A list of parameters defined in the DownloadData function.
    """
    # Argument
    [
        output_folder, TilesVertical, TilesHorizontal, latlim, lonlim,
        timestep, hdf_library
    ] = args

    # 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, output_folder,
                     timestep, hdf_library)
    except:
        print("Was not able to download the file")

    # 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 = RC.reproject_MODIS(name_collect, epsg_to)

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

    if timestep == 'monthly':
        ETfileName = os.path.join(
            output_folder, 'ET_MOD16A2_mm-month-1_monthly_' +
            Date.strftime('%Y') + '.' + Date.strftime('%m') + '.01.tif')
    elif timestep == '8-daily':
        ETfileName = os.path.join(
            output_folder,
            'ET_MOD16A2_mm-8days-1_8-daily_' + Date.strftime('%Y') + '.' +
            Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')

    DC.Save_as_tiff(name=ETfileName, data=data, geo=geo, projection='WGS84')

    # remove the side products
    os.remove(os.path.join(output_folder, name_collect))
    os.remove(os.path.join(output_folder, name_reprojected))

    return ()
Ejemplo n.º 3
0
def RetrieveData(Date, args):
    """
    This function retrieves MOD15 FPAR 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.
    """
    # Argument
    [
        output_folder, TilesVertical, TilesHorizontal, lonlim, latlim, unit,
        dataset, nameDownload, hdf_library
    ] = args

    # 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, output_folder,
                     nameDownload, hdf_library)
    except:
        print("Was not able to download the file")

    # 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 = RC.reproject_MODIS(name_collect, epsg_to)

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

    # Save the file as tiff
    FPARfileName = os.path.join(
        output_folder,
        '%s_MOD15_%s_8-daily_' % (dataset, unit) + Date.strftime('%Y') + '.' +
        Date.strftime('%m') + '.' + Date.strftime('%d') + '.tif')
    DC.Save_as_tiff(name=FPARfileName, data=data, geo=geo, projection='WGS84')

    # remove the side products
    os.remove(os.path.join(output_folder, name_collect))
    os.remove(os.path.join(output_folder, name_reprojected))

    return True
Ejemplo n.º 4
0
def DownloadData(Dir, Startdate, Enddate, latlim, lonlim, Type, Waitbar):
    """
    This scripts downloads ETmonitor ET data from the UNESCO-IHE ftp server.
    The output files display the total ET in mm for a period of one month.
    The name of the file corresponds to the first day of the month.

    Keyword arguments:
	 Dir -- 'C:/file/to/path/'
    Startdate -- 'yyyy-mm-dd'
    Enddate -- 'yyyy-mm-dd'
    lonlim -- [ymin, ymax] (values must be between -90 and 90)
    latlim -- [xmin, xmax] (values must be between -180 and 180)
    """
    # Check the latitude and longitude and otherwise set lat or lon on greatest extent
    if latlim[0] < -90 or latlim[1] > 90:
        print(
            'Latitude above 90N or below 90S is not possible. Value set to maximum'
        )
        latlim[0] = np.max(latlim[0], -90)
        latlim[1] = np.min(latlim[1], 90)
    if lonlim[0] < -180 or lonlim[1] > 180:
        print(
            'Longitude must be between 180E and 180W. Now value is set to maximum'
        )
        lonlim[0] = np.max(lonlim[0], -180)
        lonlim[1] = np.min(lonlim[1], 180)

# Check Startdate and Enddate
    if not Startdate:
        Startdate = pd.Timestamp('2008-01-01')
    if not Enddate:
        Enddate = pd.Timestamp('2012-12-31')

    # Creates dates library
    Dates = pd.date_range(Startdate, Enddate, freq="MS")

    # Create Waitbar
    if Waitbar == 1:
        import watools.Functions.Start.WaitbarConsole as WaitbarConsole
        total_amount = len(Dates)
        amount = 0
        WaitbarConsole.printWaitBar(amount,
                                    total_amount,
                                    prefix='Progress:',
                                    suffix='Complete',
                                    length=50)

    # Define directory and create it if not exists
    if Type == "act":
        output_folder = os.path.join(Dir, 'Evaporation', 'ETmonitor',
                                     'Monthly')
    if Type == "pot":
        output_folder = os.path.join(Dir, 'ETpot', 'ETmonitor', 'Monthly')
    if Type == "ei":
        output_folder = os.path.join(Dir, 'Ei', 'ETmonitor', 'Monthly')
    if Type == "es":
        output_folder = os.path.join(Dir, 'Es', 'ETmonitor', 'Monthly')
    if Type == "ew":
        output_folder = os.path.join(Dir, 'Ew', 'ETmonitor', 'Monthly')
    if Type == "tr":
        output_folder = os.path.join(Dir, 'Transpiration', 'ETmonitor',
                                     'Monthly')
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    for Date in Dates:

        # Define year and month
        year = Date.year
        month = Date.month

        # Define end filename and Date as printed in filename
        if Type == "act":
            Filename_in = "ET_ETmonitor_mm-month_%d_%02d_01.tif" % (year,
                                                                    month)
            Filename_out = os.path.join(
                output_folder,
                'ETa_ETmonitor_mm-month-1_monthly_%s.%02s.%02s.tif' %
                (Date.strftime('%Y'), Date.strftime('%m'),
                 Date.strftime('%d')))

        if Type == "pot":
            Filename_in = "ETpot_ETmonitor_mm-month_%d_%02d_01.tif" % (year,
                                                                       month)
            Filename_out = os.path.join(
                output_folder,
                'ETpot_ETmonitor_mm-month-1_monthly_%s.%02s.%02s.tif' %
                (Date.strftime('%Y'), Date.strftime('%m'),
                 Date.strftime('%d')))

        if Type == "ei":
            Filename_in = "Ei_ETmonitor_mm-month_%d_%02d_01.tif" % (year,
                                                                    month)
            Filename_out = os.path.join(
                output_folder,
                'Ei_ETmonitor_mm-month-1_monthly_%s.%02s.%02s.tif' %
                (Date.strftime('%Y'), Date.strftime('%m'),
                 Date.strftime('%d')))

        if Type == "es":
            Filename_in = "Es_ETmonitor_mm-month_%d_%02d_01.tif" % (year,
                                                                    month)
            Filename_out = os.path.join(
                output_folder,
                'Es_ETmonitor_mm-month-1_monthly_%s.%02s.%02s.tif' %
                (Date.strftime('%Y'), Date.strftime('%m'),
                 Date.strftime('%d')))

        if Type == "ew":
            Filename_in = "Ew_ETmonitor_mm-month_%d_%02d_01.tif" % (year,
                                                                    month)
            Filename_out = os.path.join(
                output_folder,
                'Ew_ETmonitor_mm-month-1_monthly_%s.%02s.%02s.tif' %
                (Date.strftime('%Y'), Date.strftime('%m'),
                 Date.strftime('%d')))

        if Type == "tr":
            Filename_in = "Tr_ETmonitor_mm-month_%d_%02d_01.tif" % (year,
                                                                    month)
            Filename_out = os.path.join(
                output_folder,
                'Tr_ETmonitor_mm-month-1_monthly_%s.%02s.%02s.tif' %
                (Date.strftime('%Y'), Date.strftime('%m'),
                 Date.strftime('%d')))

# Temporary filename for the downloaded global file
        local_filename = os.path.join(output_folder, Filename_in)

        # Download the data from FTP server if the file not exists
        if not os.path.exists(Filename_out):
            try:
                Download_ETmonitor_from_WA_FTP(local_filename, Filename_in,
                                               Type)

                # Reproject dataset
                epsg_to = '4326'
                name_reprojected_ETmonitor = RC.reproject_MODIS(
                    local_filename, epsg_to)

                # Clip dataset
                RC.Clip_Dataset_GDAL(name_reprojected_ETmonitor, Filename_out,
                                     latlim, lonlim)
                os.remove(name_reprojected_ETmonitor)
                os.remove(local_filename)

            except:
                print("Was not able to download file with date %s" % Date)

        # Adjust waitbar
        if Waitbar == 1:
            amount += 1
            WaitbarConsole.printWaitBar(amount,
                                        total_amount,
                                        prefix='Progress:',
                                        suffix='Complete',
                                        length=50)

    return