def __download(self):
     if self.products is not None and self.years is not None and self.countries is not None:
         for p in self.products:
             for y in self.years:
                 days = c.list_days(p, y)
                 for d in days:
                     print 'DOWNLOADING ' + p + ' FOR ' + y + ', DAY: ' + d['code']
                     layers = c.list_layers_countries_subset(p, y, d['code'], self.countries)
                     my_downloader = Downloader('modis',
                                                self.root,
                                                {'product': p, 'year': y, 'day': d['code']},
                                                layers)
                     my_downloader.download()
                     download_in_progress = True
                     while download_in_progress:
                         try:
                             current = my_downloader.progress(layers[0]['file_name'])['download_size']
                             total = my_downloader.progress(layers[0]['file_name'])['total_size']
                             download_in_progress = current != total
                         except TypeError:
                             pass
                         except KeyError:
                             pass
                     print 'Layer downloaded.'
     else:
         if self.products is None:
             raise Exception('Please provide a valid "products" array.')
         if self.years is None:
             raise Exception('Please provide a valid "years" array.')
         if self.countries is None:
             raise Exception('Please provide a valid "countries" comma separated string.')
Exemplo n.º 2
0
def list_layers_countries_subset_service(product_name, year, day, countries):
    """
    List available layers for the given filters.
    @param year: Year.
    @type year: str|int
    @param day: Day.
    @type day: str|int
    @param countries: Comma separated list of country code: GAUL, ISO2 or ISO3.
    @type countries: str
    @return: List of code/label objects.
    """
    out = m.list_layers_countries_subset(product_name, year, day, countries)
    return Response(json.dumps(out), content_type='application/json; charset=utf-8')
    def __process2(self, product_code):
        if self.products is not None and self.years is not None and self.countries is not None:
            for p in self.products:
                for y in self.years:
                    days = c.list_days(p, y)
                    for d in days:
                        my_processing = copy.deepcopy(processing)
                        my_processing[product_code][0]['source_path'] = None
                        for tmp_out in my_processing[product_code]:
                            tmp_out['output_path'] = None
                        if os.path.isdir(self.root + p + '/' + y + '/' + d['code'] + '/PROCESSED/'):
                            shutil.rmtree(self.root + p + '/' + y + '/' + d['code'] + '/PROCESSED/')
                        layers = c.list_layers_countries_subset(p, y, d['code'], self.countries)
                        for l in layers:
                            try:
                                my_processing[product_code][0]['source_path'].append(self.root +
                                                                                     p + '/' +
                                                                                     y + '/' +
                                                                                     d['code'] + '/' +
                                                                                     l['file_name'])
                            except AttributeError:
                                my_processing[product_code][0]['source_path'] = []
                                my_processing[product_code][0]['source_path'].append(self.root +
                                                                                     p + '/' +
                                                                                     y + '/' +
                                                                                     d['code'] + '/' +
                                                                                     l['file_name'])

                        for tmp_out in my_processing[product_code]:
                            tmp_out['output_path'] = self.root + p + '/' + y + '/' + d['code'] + '/PROCESSED/'
                        try:
                            for proc in my_processing[product_code]:
                                proc["source_path"] = proc["source_path"] if "source_path" in proc else result
                                result = processing_core.process_obj(proc)
                        except Exception, e:
                            print '##################################################'
                            print e
                            print '##################################################'
                        print 'Processing done.'
Exemplo n.º 4
0
from geobricks_downloader.download.downloader import Downloader
from geobricks_modis.core.modis_core import list_layers_countries_subset


# Filters
product = 'MCD12Q1'
year = '2001'
day = '001'
country = '0'

# Get the list of layers through the Geobricks MODIS plug-in
layers_to_be_downloaded = list_layers_countries_subset(product, year, day, country)

# Target folder: MODIS layers will be downloaded here
target = {'target': '/home/kalimaha/Desktop/MODIS', 'product': product, 'year': year, 'day': day}

# Run the downloader
Downloader('modis', target, layers_to_be_downloaded, True).download()
Exemplo n.º 5
0
 def test_list_layers_countries_subset_gaul(self):
     layers = c.list_layers_countries_subset('MOD13A2', '2010', '001', '8,1')
     self.assertEqual(len(layers), 8)
Exemplo n.º 6
0
 def test_list_layers_countries_subset(self):
     layers = c.list_layers_countries_subset('MOD13A2', '2010', '001', '8,IT,fra')
     self.assertEqual(len(layers), 12)
Exemplo n.º 7
0
def list_layers_countries_subset_service(product_name, year, day, countries):
    out = m.list_layers_countries_subset(product_name, year, day, countries)
    return Response(json.dumps(out), content_type='application/json; charset=utf-8')