Changeset 4805 for trunk/TOOLS/GENERATE_VEGET_MAP/ESA-LUH2
- Timestamp:
- 2017-12-01T16:10:17+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/TOOLS/GENERATE_VEGET_MAP/ESA-LUH2/post_PFT.py
r4777 r4805 5 5 import datetime, netCDF4, numpy as np, os 6 6 7 path_luh = "/home/ orchidee03/vuichard/LandUseMap_CMIP6/ESA2.0.7b_19PFT_quarterdeg_final/landusemap_%(year)s.nc"7 path_luh = "/home/surface7/vuichard/LandUseMap_CMIP6/ESA2.0.7b_19PFT_quarterdeg_final//landusemap_%(year)s.nc" 8 8 path_orc = "/home/satellites7/vbastri/LC/orchidee/ESA2.0.7b/19PFT_quarterdeg_final/PFTmap_2010.nc" 9 path_out = "/home/satellites7/vbastri/LC/orchidee/ESA-LUH2-final -ext8/PFTmap_%(year)s.nc"9 path_out = "/home/satellites7/vbastri/LC/orchidee/ESA-LUH2-final/PFTmap_%(year)s.nc" 10 10 11 11 # Define global attributes to be written in the output netcdf-files 12 atts = dict(description = "ORCHIDEE PFT map based on the ESA CCI Land Cover map v2.0.7b for 2010 aggregated by the user-tool v3.13 with the cross-walking table v2.4, followed by historical reconstrution using G. Hurtt data LU H2v2h with merging rules v2.0",13 contact = "V.Bastrikov (vladislav.bastrikov@lsce.ipsl.fr), P.Peylin (p eylin@lsce.ipsl.fr), N.Vuichard (nicolas.vuichard@lsce.ipsl.fr)",12 atts = dict(description = "ORCHIDEE PFT map based on the ESA CCI Land Cover map v2.0.7b for 2010 aggregated by the user-tool v3.13 with the cross-walking table v2.4, followed by historical reconstrution using G. Hurtt data LU2v2h with merging rules v2.0", 13 contact = "V.Bastrikov (vladislav.bastrikov@lsce.ipsl.fr), P.Peylin (philippe.peylin@lsce.ipsl.fr), N.Vuichard (nicolas.vuichard@lsce.ipsl.fr)", 14 14 web = "https://orchidas.lsce.ipsl.fr/dev/LCCCI.php", 15 15 date = datetime.datetime.now().strftime("%d/%m/%Y %H:%M"), … … 24 24 # Load ORCHIDEE PFT data for year 2010 (with 19 PFTs) 25 25 nc = netCDF4.Dataset(path_orc) 26 orc 19= nc.variables["maxvegetfrac"][0]26 orc = nc.variables["maxvegetfrac"][0] 27 27 nc.close() 28 28 … … 41 41 return newveg 42 42 43 for year in range( 1880, 2016):43 for year in range(850, 2016): 44 44 print year 45 45 nc = netCDF4.Dataset(path_luh % dict(year=year)) 46 46 veg = nc.variables["YEARLYMAXVEGETFRAC_NORMALIZE"][0,:,::-1,:] 47 47 nc.close 48 49 print "Veg range [%s - %s], total range [%s - %s], %s pts" % (veg.min(), veg.max(), veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.) 48 50 49 51 # Make LSM uniform across pfts … … 54 56 print "Add %s pts to PFT%s" % (len(ys), pft+1) 55 57 veg[pft, ys, xs] = 0 56 print " Total range [%s - %s], %s pts" % (veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.)58 print "Veg range [%s - %s], total range [%s - %s], %s pts" % (veg.min(), veg.max(), veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.) 57 59 60 # Clip to [0,1] and normalize 61 veg = np.ma.clip(veg, 0, 1) 62 veg = veg / veg.sum(axis=0) 63 print "Clip to [0,1] and normalize" 64 print "Veg range [%s - %s], total range [%s - %s], %s pts" % (veg.min(), veg.max(), veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.) 65 58 66 # Fill masked inland pts with bare soil 59 ys, xs = np.ma.where((orc 19[-2] > 0) & (veg[0].mask == True))67 ys, xs = np.ma.where((orc[-2] > 0) & (veg[0].mask == True)) 60 68 print "Add %s pts as bare soil" % len(ys) 61 69 veg[0, ys, xs] = 1 62 70 for pft in range(1,15): veg[pft, ys, xs] = 0 63 print " Total range [%s - %s], %s pts" % (veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.)71 print "Veg range [%s - %s], total range [%s - %s], %s pts" % (veg.min(), veg.max(), veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.) 64 72 65 # Extend by 8 pixelsoutside the land66 for idx in range( 8):73 # Extend by 1 pixel outside the land 74 for idx in range(1): 67 75 print "Extend by 1 pixel" 68 76 veg = extend(veg) 69 print " Total range [%s - %s], %s pts" % (veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.)77 print "Veg range [%s - %s], total range [%s - %s], %s pts" % (veg.min(), veg.max(), veg.sum(axis=0).min(), veg.sum(axis=0).max(), veg.count() / 15.) 70 78 71 79 # Write output file … … 87 95 ncout.variables["time_counter"].setncatts(dict(units = "years since 0-1-1", calendar = "gregorian", axis = "T")) 88 96 ncout.variables["veget"].setncatts(dict(valid_min = 1, valid_max = len(veg), long_name = "Vegetation classes", units = "-", axis = "Z")) 89 ncout.variables["lat"][:] = grid.lat90 ncout.variables["lon"][:] = grid.lon97 ncout.variables["lat"][:] = lat 98 ncout.variables["lon"][:] = lon 91 99 ncout.variables["maxvegetfrac"][0] = veg 92 100 ncout.variables["time_counter"][0] = year
Note: See TracChangeset
for help on using the changeset viewer.