#!/usr/bin/env python ''' Python script to pull all MODIS files for LAI product for given years for given tiles into destination_folder ''' from geog0111.get_modis_files import get_modis_files from datetime import datetime years = [2017, 2016] tiles = ['h17v03', 'h18v03', 'h17v04', 'h18v04'] destination_folder = 'data' for year in years: ndoys = (datetime(year, 12, 31) - datetime(year, 1, 1)).days + 1 for doy in range(1, ndoys + 1, 4): print(year, ndoys, doy, end=' ') filenames = get_modis_files(doy,year,tiles,base_url='https://e4ftl01.cr.usgs.gov/MOTA',\ version=6,\ product='MCD15A3H') print(filenames)
def procure_dataset(dataset_name, destination_folder="data",verbose=False, locations=["/data/selene/ucfajlg/geog0111_data/",\ "/data/selene/ucfajlg/geog0111_data/lai_data/",\ "/archive/rsu_raid_0/plewis/public_html/geog0111_data"][::-1],\ modis_urls=['https://e4ftl01.cr.usgs.gov/MOTA',\ 'https://e4ftl01.cr.usgs.gov/MOLT',\ 'https://e4ftl01.cr.usgs.gov/MOLA',\ 'https://e4ftl01.cr.usgs.gov//MODV6_Cmp_C/MOTA/',\ 'https://e4ftl01.cr.usgs.gov/VIIRS',\ 'https://n5eil01u.ecs.nsidc.org/MOST/',\ 'https://n5eil01u.ecs.nsidc.org/MOSA/',\ 'https://n5eil01u.ecs.nsidc.org/VIIRS/'],\ urls=["http://www2.geog.ucl.ac.uk/~ucfajlg/geog0111_data/",\ "http://www2.geog.ucl.ac.uk/~plewis/geog0111_data/",\ "http://www2.geog.ucl.ac.uk/~plewis/geog0111_data/lai_files/"][::-1]): """Procure a Geog0111 dataset. This function will look for the dataset called `dataset_name`, and either provide symbolic links or download the relevant files to a local folder called by default `data`, or with a user-provided name. The other two options are to do with the location of the dataset witin the UCL filesystem (`location`), and the external URL (list `urls`). It is assumed that in either case, `datasest_name` is a valid folder under both `location` and `url`. """ dest_path = Path(destination_folder) if not dest_path.exists(): dest_path.mkdir() output_fname = dest_path.joinpath(dataset_name) if output_fname.exists(): return True done = False fully_qualified_hostname = getfqdn() if fully_qualified_hostname.find("geog.ucl.ac.uk") >= 0: if (verbose): print("Running on UCL's Geography computers") for location in locations: if (verbose): print(f'trying {location}') done = generate_symlinks(dataset_name, location, destination_folder=destination_folder, verbose=verbose) if done: break else: if (verbose): print("Running outside UCL Geography. Will try to download data.\n",\ dataset_name,"\nThis might take a while!") for url in list(urls): if (verbose): print(f'trying {url}') done = download_data(dataset_name, url, verbose=verbose, destination_folder=destination_folder) if done: break if not done: # maybe a modis dataset: try that if its an hdf try: info = dataset_name.split('.') product = info[0] tile = info[2] version = int(info[3]) year = int(info[1][1:5]) doy = int(info[1][5:]) dtype = info[-1] if dtype in ['hdf', 'tif']: for url in modis_urls: try: filename = get_modis_files(doy,year,[tile],base_url=url,\ version=version,\ destination_folder=destination_folder,\ product=product)[0] done = True except: pass except: pass return (done)
done = True # try to download it from server done = procure_dataset(fname, verbose=True) from geog0111.get_modis_files import get_modis_files from geog0111.process_timeseries import mosaic_and_clip ''' Get the MODIS LC files from the server to store in data ''' if not done: try: url = 'https://e4ftl01.cr.usgs.gov//MODV6_Cmp_C/MOTA/' filename = get_modis_files(1,year,[tiles],base_url=url,\ version=6,verbose=True,\ destination_folder='data',\ product='MCD12Q1')[0] print(filename) except: print('server may be down') ''' Extract and clip the dataset ''' lc_data = mosaic_and_clip(tiles, 1, year, folder='data', layer="LC_Type3", shpfile='data/TM_WORLD_BORDERS-0.3.shp', country_code=country_code, product='MCD12Q1',
#!/usr/bin/env python ''' Python script to pull all MODIS files for LAI product for given years for given tiles into destination_folder ''' from geog0111.get_modis_files import get_modis_files from datetime import datetime years = [2017,2016] tiles = ['h09v05'] destination_folder = 'data' for year in years: ndoys = (datetime(year,12,31) - datetime(year,1,1)).days + 1 for doy in range(1,ndoys+1,1): print(year,ndoys,doy,end=' ') filenames = get_modis_files(doy,year,tiles,base_url='https://n5eil01u.ecs.nsidc.org/MOST',\ version=6, product='MOD10A1') print(filenames)