-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_raster_point.py
50 lines (37 loc) · 1.75 KB
/
write_raster_point.py
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
46
47
48
49
50
# script to add raster point data to csvs
import os
import pandas as pd
import csv
import subprocess as sub
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("current_name",nargs='?',default="none")
inputs = parser.parse_args()
current_name = inputs.current_name
target = '/exports/csce/datastore/geos/users/s1134744/LSDTopoTools/Topographic_projects/Himalayan_front/himalaya_all/'
raster = '/exports/csce/datastore/geos/users/s1134744/LSDTopoTools/Topographic_projects/TRMM_data/annual.tif'
with open(target+current_name+'_output_MChiSegmented_export.csv','wb') as csvfile:
csvWriter = csv.writer(csvfile)
csvWriter.writerow(["burned_data","latitude","longitude","node","row","col","chi","elevation","flow_distance","drainage_area","m_chi","b_chi","source_key","basin_key","segmented_elevation","raster_point"])
def write_row(string):
with open(target+current_name+'_output_MChiSegmented_export.csv','a') as writefile:
csvWriter = csv.writer(writefile,delimiter=',')
csvWriter.writerow((string))
#setting up output file
#tracker
x_i = 0
with open(target+current_name+"_output_MChiSegmented_burn.csv",'r') as csvfile:
csvReader = csv.reader(csvfile,delimiter=',')
#pandasDF = pd.read_csv(csvfile,delimiter=',')
next(csvReader)
for row in csvReader:
string = [row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[11],row[12],row[13],row[14]]
#sampling target raster using gdallocationinfo
gdal = ['gdallocationinfo', '-wgs84', '-valonly', raster, row[2], row[1]]
locate = sub.Popen(gdal, stdout=sub.PIPE)
value = locate.stdout.read()
value = int(value)
string.append(value)
write_row(string)
print value,x_i
x_i+=1