-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASCAT_MortDf.py
85 lines (57 loc) · 2.18 KB
/
ASCAT_MortDf.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 30 00:35:32 2017
@author: kkrao
"""
## sectin for making attribute tables
from __future__ import division
from dirs import*
arcpy.env.overwriteOutput=True
year_range=range(2009,2017)
box_area=5000**2
for k in year_range:
year='%s'%k
Y1='%02d'%(k-2000)
arcpy.env.workspace = Dir_mort+'/ADS'+year+'.gdb'
inFeature='ADS'+Y1
outFeature= 'd_'+inFeature
arcpy.Dissolve_management(inFeature, outFeature)
joinFeature=Dir_mort+'/CA_proc.gdb/smallgrid'
inFeature=[outFeature,joinFeature]
outFeature='i_'+outFeature
arcpy.Intersect_analysis(inFeature, outFeature)
inFeature=outFeature
fieldName='FAM'
arcpy.AddField_management(inFeature, fieldName, "FLOAT")
arcpy.CalculateField_management(inFeature, fieldName, "!Shape_Area!/%s"%box_area,"PYTHON_9.3")
dropField='gridID'
arcpy.DeleteField_management(inFeature, dropField)
outFeature='j_'+inFeature
targetFeature=inFeature
matchoption='HAVE_THEIR_CENTER_IN'
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(targetFeature)
fieldmappings.addTable(joinFeature)
arcpy.SpatialJoin_analysis(targetFeature, joinFeature, outFeature, "#", "#", '#',matchoption)
# section for making Df
from __future__ import division
from dirs import*
arcpy.env.overwriteOutput=True
year_range=range(2009,2017)
nos=5938
mortDf=pd.DataFrame()
for k in year_range:
year='%s'%k
Y1='%02d'%(k-2000)
arcpy.env.workspace = Dir_mort+'/ADS'+year+'.gdb'
mort=pd.DataFrame(np.full(nos,0), columns=[year])
fname='j_i_d_ADS'+Y1
if arcpy.Exists(fname):
cursor = arcpy.SearchCursor(fname)
for row in cursor:
mort.iloc[row.getValue('gridID')-1]=row.getValue('FAM')
mortDf=pd.concat([mortDf,mort],axis=1)
mortDf.index.name='gridID'
store = pd.HDFStore(Dir_CA+'/ASCAT_mort.h5')
store['mort'] = mortDf
store.close()