... | ... | @@ -63,3 +63,50 @@ for i,cell in enumerate(bingrid): |
|
|
|
|
|
file.close()
|
|
|
|
|
|
## open landuse binary file with grid
|
|
|
```
|
|
|
file = "/landuse/users/brazil_landuseinput/landuse_GLDAS_pasture_update_mapbiomas.clm"
|
|
|
file = open(file, "rb")
|
|
|
#read header
|
|
|
|
|
|
binlanduse = np.zeros((nyear,ncell,nband)) #[36 57616 64]
|
|
|
for i in range (0,nyear,1):
|
|
|
for j in range (0,ncell,1): # loop over cell
|
|
|
for k in range (0,nband,1): # loop bands = landuse categories
|
|
|
byte = struct.unpack('h',file.read(2))[0]
|
|
|
binlanduse[i,j,k] = byte
|
|
|
file.close()
|
|
|
|
|
|
years = np.arange(0,nyear,1)
|
|
|
cfts = np.arange(0,nband,1)
|
|
|
|
|
|
|
|
|
#read header
|
|
|
|
|
|
bingrid = np.zeros((ncell,2)) #[5200 2]
|
|
|
for i in range (0,ncell,1): #band 1= longitude, 0= latitude
|
|
|
bingrid[i,1] = struct.unpack('h',file.read(2))[0]* scalar
|
|
|
bingrid[i,0] = struct.unpack('h',file.read(2))[0]* scalar
|
|
|
file.close()
|
|
|
|
|
|
#latitudes = np.unique(bingrid[:,0])
|
|
|
latitudes = np.arange(-32.75,6.25,0.5)
|
|
|
longitudes = np.arange(-74.25,-34.75,0.5)
|
|
|
#longitudes = np.unique(bingrid[:,1])
|
|
|
|
|
|
|
|
|
landuse = ma.zeros((len(years),len(cfts),len(latitudes),len(longitudes)))
|
|
|
landuse[:] = np.ma.masked
|
|
|
|
|
|
for i,cell in enumerate(bingrid):
|
|
|
try :
|
|
|
lat = np.where(cell[0]==latitudes)[0][0]
|
|
|
lon = np.where(cell[1]==longitudes)[0][0]
|
|
|
for j,year in enumerate(years):
|
|
|
for k,cft in enumerate(cfts):
|
|
|
landuse[j,k,lat,lon] = binlanduse[j,i,k]
|
|
|
except :
|
|
|
a = 1
|
|
|
|
|
|
file.close()
|
|
|
``` |