Пример #1
0
def downloadLandsat(startDate, endDate, GCP):
    #find all path/rows associates with GCP
    s = Search()
    scenes = s.search(lat=GCP[0],
                      lon=GCP[1],
                      limit=100,
                      start_date=startDate,
                      end_date=endDate,
                      cloud_max=5)
    print '%d scenes found' % scenes['total_returned']
    if len(scenes) == 3:
        print 'no cloud free scenes found'
        return
    sceneIDlist = []
    for i in xrange(len(scenes['results'])):
        sceneID = np.str(scenes['results'][i]['sceneID'])
        if sceneID.startswith('LO'):  #OLI only
            continue
        #sceneIDlist.append(sceneID)
        filelist = glob.glob(os.path.join(landsatDN, sceneID))
        if not filelist:
            d = Downloader(download_dir=landsatDN)
            d.download([sceneID], ['10'])
            path = os.path.join(landsatDN, sceneID)
            if not os.path.exists(path):
                tarFN = os.path.join(landsatDN, '%s.tar.bz' % sceneID)
                if os.path.exists(tarFN):
                    try:
                        if not os.path.exists(path):
                            os.makedirs(path)
                        untar(tarFN, path)
                        sceneIDlist.append(sceneID)
                        continue
                    except Exception:
                        print 'something wrong with tar file'
                        os.remove(tarFN)
                        shutil.rmtree(path)
                        continue
                elif os.path.exists(
                        os.path.join(landsatDN, '%s.tar.gz' % sceneID)):
                    tarFN = os.path.join(landsatDN, '%s.tar.gz' % sceneID)
                    try:
                        if not os.path.exists(path):
                            os.makedirs(path)
                        untar(tarFN, path)
                        sceneIDlist.append(sceneID)
                        continue
                    except Exception:
                        print 'something wrong with tar file'
                        os.remove(tarFN)
                        shutil.rmtree(path)
                        continue
                else:
                    print 'no files exist on AWS or google'
                    continue
            sceneIDlist.append(sceneID)
        else:
            sceneIDlist.append(sceneID)
    return sceneIDlist
Пример #2
0
def download_and_set(job, PATH_DOWNLOAD):
    """Download the image file."""
    UserJob_Model.set_job_status(job['job_id'], 1)
    b = Downloader(verbose=False, download_dir=PATH_DOWNLOAD)
    scene_id = str(job['scene_id'])
    bands = [job['band_1'], job['band_2'], job['band_3']]
    b.download([scene_id], bands)
    input_path = os.path.join(PATH_DOWNLOAD, scene_id)
    return input_path, bands, scene_id
Пример #3
0
def download_and_set(job):
    """Download 3 band files for the given sceneid"""
    # set worker instance id for job
    UserJob_Model.set_worker_instance_id(job['job_id'], INSTANCE_ID)

    scene_id = str(job['scene_id'])
    input_path = os.path.join(PATH_DOWNLOAD, scene_id)
    # Create a subdirectory
    if not os.path.exists(input_path):
        os.makedirs(input_path)
        print 'Directory created.'

    try:
        b = Downloader(verbose=False, download_dir=PATH_DOWNLOAD)
        bands = [job['band_1'], job['band_2'], job['band_3']]
        b.download([scene_id], bands)
        print 'Finished downloading.'
    except:
        raise Exception('Download failed')
    return bands, input_path, scene_id
        os.makedirs(dest_path)
    dwner = Downloader(verbose=False,
                       download_dir='{}\\{}'.format(data_dir, dest_path))

    if tile in [('032', '037'), ('033', '037')]:
        print 'already have this tile'
    else:
        candidate_scenes = srcher.search(paths_rows="{},{},{},{}".format(
            path, row, path, row),
                                         start_date=s_date,
                                         end_date=e_date,
                                         cloud_min=0,
                                         cloud_max=max_cloud_prcnt,
                                         limit=return_scenes)
        print 'total images for tile {} is {}'.format(
            tile, candidate_scenes['total_returned'])

        x = 0
        if candidate_scenes["status"] == "SUCCESS":
            for scene_image in candidate_scenes["results"]:
                print "Downloading:", (str(scene_image['sceneID']))
                print 'Downloading tile {} of {}'.format(
                    x, candidate_scenes['total_returned'])
                dwner.download([str(scene_image['sceneID'])])
                Simple(
                    join('{}\\{}'.format(data_dir, dest_path),
                         str(scene_image['sceneID']) + ".tar.bz"))
                x += 1
        else:
            print 'nothing'
print 'done'
Пример #5
0
results = s.search(lat=site.y, lon=site.x, limit=100)
scene_id = results['results'][1]['sceneID']


# In[11]:

landsat_dname = os.path.join(output_dir, 'Landsat')
if not os.path.exists(landsat_dname):
    os.makedirs(landsat_dname)


# In[11]:

from landsat.downloader import Downloader
d = Downloader(download_dir=landsat_dname)
result = d.download([str(scene_id)])


# In[12]:

import tarfile
scene_dname = os.path.join(landsat_dname, scene_id)
tar_fname = os.path.join(landsat_dname, scene_id + ".tar.bz")
tar = tarfile.open(tar_fname)
tar.extractall(path=scene_dname)
tar.close()

os.unlink(tar_fname)


# In[12]: