Ejemplo n.º 1
0
def check_pre_download(mirror, uname, pword, concurrent):
    error_code = 200
    from ost.helpers import scihub, asf, peps
    # check if uname and pwrod are correct
    if int(mirror) == 1:
        error_code = scihub.check_connection(uname, pword)
    elif int(mirror) == 2:
        error_code = asf.check_connection(uname, pword)
        if concurrent > 10:
            logger.debug('INFO: Maximum allowed parallel downloads \
                  from Earthdata are 10. Setting concurrent accordingly.')
            concurrent = 10
    elif int(mirror) == 3:
        error_code = peps.check_connection(uname, pword)
    from ost.helpers import scihub, asf, peps
    # check if uname and pwrod are correct
    if int(mirror) == 1:
        error_code = scihub.check_connection(uname, pword)
    elif int(mirror) == 2:
        error_code = asf.check_connection(uname, pword)
        if concurrent > 10:
            logger.debug('INFO: Maximum allowed parallel downloads \
                      from Earthdata are 10. Setting concurrent accordingly.')
            concurrent = 10
    elif int(mirror) == 3:
        error_code = peps.check_connection(uname, pword)
    if error_code == 401:
        raise ValueError('ERROR: Username/Password are incorrect')
    elif error_code != 200:
        raise ValueError(
            'ERROR: Some connection error. Error code {}.'.format(error_code)
        )
Ejemplo n.º 2
0
def download_sentinel1(
        inventory_df,
        download_dir,
        mirror=None,
        concurrent=2,
        uname=None,
        pword=None
):
    """Function to download Sentinel-1 with choice of data repository

    :param inventory_df: OST inventory dataframe
    :type inventory_df: GeoDataFrame
    :param download_dir: high-level download directory
    :type download_dir: Path
    :param mirror: number of data repository \n
                1 - Scihub \n
                2 - ASF \n
                3 - PEPS \n
                4 - ONDA \n
    :type mirror: int
    :param concurrent: number of parallel downloads
    :type concurrent: int
    :param uname: username for respective data repository
    :type uname: str
    :param pword: password for respective data repository
    :type pword: str
    """

    if not mirror:
        print(' Select the server from where you want to download:')
        print(' (1) Copernicus Apihub (ESA, rolling archive)')
        print(' (2) Alaska Satellite Facility (NASA, full archive)')
        print(' (3) PEPS (CNES, 1 year rolling archive)')
        print(
            ' (4) ONDA DIAS (ONDA DIAS full archive for SLC -'
            ' or GRD from 30 June 2019)'
        )
        # print(' (5) Alaska Satellite Facility (using WGET - '
        # 'unstable - use only if 2 does not work)')
        mirror = input(' Type 1, 2, 3, or 4: ')

    if not uname:
        print(' Please provide username for the selected server')
        uname = input(' Username:'******' Please provide password for the selected server')
        pword = getpass.getpass(' Password:'******'Maximum allowed parallel downloads from Earthdata are 10. '
                'Setting concurrent accordingly.'
            )
            concurrent = 10
    
    elif int(mirror) == 3:
        error_code = peps.check_connection(uname, pword)
    elif int(mirror) == 4:
        error_code = onda.check_connection(uname, pword)
    # elif int(mirror) == 5:
    #    error_code = asf_wget.check_connection(uname, pword)
    # hidden option for downloading from czech mirror
    elif int(mirror) == 321:
       error_code = scihub.check_connection(
           uname, pword, base_url='https://dhr1.cesnet.cz/'
       )
    else:
        raise ValueError('No valid mirror selected')

    if error_code == 401:
        raise ValueError('Username/Password are incorrect')
    elif error_code != 200:
        raise ValueError(f'Some connection error. Error code {error_code}.')
    
    # download in parallel
    if int(mirror) == 1:    # scihub
        scihub.batch_download(inventory_df, download_dir,
                              uname, pword, concurrent)
    elif int(mirror) == 2:    # ASF
        asf.batch_download(inventory_df, download_dir,
                           uname, pword, concurrent)
    elif int(mirror) == 3:   # PEPS
        peps.batch_download(inventory_df, download_dir,
                            uname, pword, concurrent)
    elif int(mirror) == 4:   # ONDA DIAS
        onda.batch_download(inventory_df, download_dir,
                            uname, pword, concurrent)
    if int(mirror) == 321:    # scihub czech mirror
        scihub.batch_download(inventory_df, download_dir,
                              uname, pword, concurrent,
                              base_url='https://dhr1.cesnet.cz/')
Ejemplo n.º 3
0
def download_sentinel1(inventory_df,
                       download_dir,
                       mirror=None,
                       concurrent=2,
                       uname=None,
                       pword=None):
    '''Main function to download Sentinel-1 data

    This is an interactive function

    '''

    if not mirror:
        print(' Select the server from where you want to download:')
        print(' (1) Copernicus Apihub (ESA, rolling archive)')
        print(' (2) Alaska Satellite Facility (NASA, full archive)')
        print(' (3) PEPS (CNES, 1 year rolling archive)')
        print(
            ' (4) ONDA DIAS (ONDA DIAS full archive for SLC - or GRD from 30 June 2019)'
        )
        mirror = input(' Type 1, 2, 3 or 4: ')

    if not uname:
        print(' Please provide username for the selected server')
        uname = input(' Username:'******' Please provide password for the selected server')
        pword = getpass.getpass(' Password:'******' INFO: Maximum allowed parallel downloads \
                  from Earthdata are 10. Setting concurrent accordingly.')
            concurrent = 10

    elif int(mirror) == 3:
        error_code = peps.check_connection(uname, pword)
    elif int(mirror) == 4:
        error_code = onda.check_connection(uname, pword)

    if error_code == 401:
        raise ValueError(' ERROR: Username/Password are incorrect')
    elif error_code != 200:
        raise ValueError(
            ' ERROR: Some connection error. Error code {}.'.format(error_code))

    # download in parallel
    if int(mirror) == 1:
        scihub.batch_download(inventory_df, download_dir, uname, pword,
                              concurrent)  # scihub
    elif int(mirror) == 2:  # ASF
        asf.batch_download(inventory_df, download_dir, uname, pword,
                           concurrent)
    elif int(mirror) == 3:  # PEPS
        peps.batch_download(inventory_df, download_dir, uname, pword,
                            concurrent)
    elif int(mirror) == 4:  # ONDA DIAS
        onda.batch_download(inventory_df, download_dir, uname, pword,
                            concurrent)
Ejemplo n.º 4
0
def download_sentinel1(inventory_df,
                       download_dir,
                       mirror=None,
                       concurrent=2,
                       uname=None,
                       pword=None):
    '''Main function to download Sentinel-1 data

    This is an interactive function

    '''

    if not mirror:
        print(' INFO: One or more of your scenes need to be downloaded.')
        print(' Select the server from where you want to download:')
        print(' (1) Copernicus Apihub (ESA, rolling archive)')
        print(' (2) Alaska Satellite Facility (NASA, full archive)')
        print(' (3) PEPS (CNES, 1 year rolling archive)')
        mirror = input(' Type 1, 2 or 3: ')

    if not uname:
        print(' Please provide username for the selected server')
        uname = input(' Username:'******' Please provide password for the selected server')
        pword = getpass.getpass(' Password:'******' INFO: Maximum allowed parallel downloads \
                  from Earthdata are 10. Setting concurrent accordingly.')
            concurrent = 10
    elif int(mirror) == 3:
        error_code = peps.check_connection(uname, pword)

    if int(mirror) == 1:
        # check response
        if error_code == 401:
            raise ValueError(' ERROR: Username/Password are incorrect.')
        elif error_code != 200:
            raise ValueError(
                ' Some connection error. Error code: {}'.format(error_code))

        # check if all scenes exist
        scenes = inventory_df['identifier'].tolist()

        download_list = []

        for scene_id in scenes:
            scene = S1Scene(scene_id)
            filepath = scene._download_path(download_dir, True)

            uuid = (inventory_df['uuid'][inventory_df['identifier'] ==
                                         scene_id].tolist())

            # create list objects for download
            download_list.append([uuid[0], filepath, uname, pword])

        # download in parallel
        if int(mirror) == 1:  # scihub
            pool = multiprocessing.Pool(processes=2)
            pool.map(scihub.s1_download, download_list)
    elif int(mirror) == 2:  # ASF
        asf.batch_download(inventory_df, download_dir, uname, pword,
                           concurrent)
    elif int(mirror) == 3:  # PEPS
        peps.batch_download(inventory_df, download_dir, uname, pword,
                            concurrent)