def test_downloader_tiff(): # Extract bounding box from shapefile. point1, point2 = shpm.extract_shp_boundingbox(SHP_PATH) source = 'LandDAAC-v5-day' print(os.getcwd()) dates = pd.date_range('2016-07-20', '2016-08-05', freq='8D') options = { 'plot': False, 'keep_original': True, 'regrid': [3, 'bilinear'], 'close_browser': True, } td.download_tiffs(source, dates, point1, point2, opt=options) # Checks at source if tiff files were generated. files_dir = os.listdir(os.path.join(DOWNLOADFILES_PATH, 'LandDAAC-v5-day')) tiff_files_list = [ 'LandDAAC-v5-day-2016-07-20.tiff', 'LandDAAC-v5-day-2016-08-05-treated.tiff', 'LandDAAC-v5-day-2016-08-05.tiff', 'LandDAAC-v5-day-2016-07-28-treated.tiff', 'LandDAAC-v5-day-2016-07-20-treated.tiff', 'LandDAAC-v5-day-2016-07-28.tiff', ] assert set(files_dir) == set(tiff_files_list)
def test_LandDAAC_v5_night(): source = 'LandDAAC-v5-night' dates = pd.date_range('2016-07-20', '2016-08-05', freq='8D') point1, point2 = shpm.extract_shp_boundingbox(SHP_PATH) # Allow time_series to create a netcdf file options = { 'regrid': [3, 'cubic'], 'keep_original': False, 'time_series': True, 'close_browser': True, } td.download_tiffs(source, dates, point1, point2, opt=options) # Read if the file format is valid. filename = 'time_series.nc' path_tmp = os.path.join(DOWNLOADFILES_PATH, source) nc_filename = os.path.join(path_tmp, filename) try: # Open the netCDF file and read it. nc = Dataset(nc_filename, 'r') except OSError: print('{} failed in process {}'.format(nc_filename, i)) nc_model = nc.data_model assert nc_model == "NETCDF4", "The {} format is not correct".format( nc_model)
def download_source(source, dates, point1, point2, opt=False): """ Download satelite tiff files and save it to the directory 'downloadedFiles'. """ try: logger.info("Capturando {} {}".format(source, dates)) td.download_tiffs(source, dates, point1, point2, opt) except Exception as e: logger.error( "Error capturando from {} at {} error: {}".format(source, dates, e) ) return return