import numpy as np from geog0111.process_timeseries import mosaic_and_clip # set to True if you want to override # the MODIS projection (see above) use_6974 = False ''' https://stackoverflow.com/questions/10454316/ how-to-project-and-resample-a-grid-to-match-another-grid-with-gdal-python ''' # first get an exemplar LAI file, clipped to # the required limits. We will use this to match # the t2 dataset to match_filename = mosaic_and_clip(tiles,1,year,ofolder='tmp',\ country_code=country_code,shpfile=shpfile,frmat='GTiff') print(match_filename) ''' Now get the projection, geotransform and dataset size that we want to match to ''' match_ds = gdal.Open(match_filename, gdalconst.GA_ReadOnly) match_proj = match_ds.GetProjection() match_geotrans = match_ds.GetGeoTransform() wide = match_ds.RasterXSize high = match_ds.RasterYSize print('\nProjection from file:') print(match_proj,'\n')
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', frmat="MEM") ''' Define LC table from userguide https://lpdaac.usgs.gov/sites/default/\ files/public/product_documentation/\ mcd12_user_guide_v6.pdf ''' table = ''' |Water Bodies|0|At least 60% of area is covered by permanent water bodies.| |Grasslands|1|Dominated by herbaceous annuals (<2m) includ- ing cereal croplands.| |Shrublands|2|Shrub (1-2m) cover >10%.|