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.')
def list_days_service(product_name, year):
    """
    List available days for the given product and year.
    @param product_name: MODIS product code.
    @type product_name: str
    @param year: Year.
    @type year: str|int
    @return: List of code/label objects.
    """
    out = m.list_days(product_name, year)
    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.'
 def test_list_days(self):
     days = c.list_days('MOD13A2', '2010')
     self.assertEqual(len(days), 23)
Exemple #5
0
def list_days_service(product_name, year):
    out = m.list_days(product_name, year)
    return Response(json.dumps(out), content_type='application/json; charset=utf-8')