示例#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
 def setUpClass(cls):
     cls.d = Downloader()
     cls.temp_folder = mkdtemp()
     cls.scene = 'LT81360082013127LGN01'
     cls.scene_2 = 'LC82050312014229LGN00'
     cls.scene_s3 = 'LC80010092015051LGN00'
     cls.scene_s3_2 = 'LC82050312015136LGN00'
     cls.scene_size = 59204484
示例#4
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
path = None
row = None
s_date = '2013-02-11'
e_date = '2016-05-14'
return_scenes = 100
max_cloud_prcnt = 20
data_dir = "F:\EOS\Landsat_Images\Landsat_8"

for tile in image_index:
    path, row = tile[0], tile[1]
    srcher = Search()
    dest_path = 'd_{}_{}'.format(path, row)
    os.chdir(data_dir)
    if not os.path.exists(dest_path):
        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
示例#6
0
s = Search()
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)