-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompress_for_ltvis.py
More file actions
45 lines (37 loc) · 1.42 KB
/
compress_for_ltvis.py
File metadata and controls
45 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 3 09:29:54 2018
@author: braatenj
"""
import subprocess
import os
import sys
#raster = '/vol/v3/lt_stem_v3.1/models/biomassfiaald_20180708_0859/{year}/biomassfiaald_20180708_0859_{year}_mean.tif'
#startYear = 1984
#endYear = 2017
#noData = -9999
#ofType = 'Int16' 'Byte'
#outDir = '/vol/v2/archive/biomass/'
#method = 'deflate' or 'lzw', or 'packbits'
def main(raster, startYear, endYear, noData, ofType, outDir, method):
for year in range(startYear, endYear+1):
print(year)
inFile = raster.format(year=str(year))
if not os.path.exists(inFile):
sys.exit('Error: file '+inFile+' does not exist')
bname = os.path.splitext(os.path.basename(inFile))[0]+'_{method}.tif'
bname = bname.format(method=method.lower())
outFile = os.path.join(outDir, str(year), bname)
if not os.path.exists(os.path.dirname(outFile)):
os.makedirs(os.path.dirname(outFile))
cmd = 'gdal_translate -co COMPRESS='+method.upper()+' -co BIGTIFF=YES -of GTIFF -tr 30 30 -a_nodata '+str(noData)+' -ot '+ofType+' '+inFile+' '+outFile #
subprocess.call(cmd, shell=True)
if __name__ == '__main__':
raster = str(sys.argv[1])
startYear = int(sys.argv[2])
endYear =int( sys.argv[3])
noData = int(sys.argv[4])
ofType = str(sys.argv[5])
outDir = str(sys.argv[6])
method = str(sys.argv[7])
sys.exit(main(raster, startYear, endYear, noData, ofType, outDir, method))