-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
113 lines (93 loc) · 3.1 KB
/
Copy pathMakefile
File metadata and controls
113 lines (93 loc) · 3.1 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
ifndef DATA_ROOT
ifeq ($(shell hostname),vagrant)
$(warn Setting DATA_ROOT to /data)
DATA_ROOT := /data
else
$(error Please set DATA_ROOT)
endif
endif
##
## Boilerplate
##
ifeq (,$(filter _%,$(notdir $(CURDIR))))
#DIVERSITY_DB := ../tools/yarg/data/diversity.rds
export DIVERSITY_DB := ${DATA_ROOT}/predicts/diversity-2017-02-06-03-36-23.rds
export HPD_DB := ${DATA_ROOT}/grump1.0/gluds00ag
export ROADS_DB := ${DATA_ROOT}/groads1.0/groads-v1-global-gdb/gROADS_v1.gdb
export LUI_DATA := $(abspath ${DATA_ROOT}/LUIdata.zip)
include target.mk
else
VPATH = ${SRCDIR}
##
## Rules
##
OS := $(shell uname -s)
ifeq (${OS},Darwin)
TRUE := /usr/bin/true
NOSLEEP := caffeinate -i
else
TRUE := /bin/true
NOSLEEP :=
endif
all: sr-model.rds ab-model.rds lui-models
outdir:
+@pwd
merged.rds: ${DIVERSITY_DB} ${SRCDIR}/preprocess-diversity.R
@echo "Merging diversity data"
@${SRCDIR}/preprocess-diversity.R --input $< --output $@
sites.csv: merged.rds ${SRCDIR}/get-sites.R
@echo "Extracting geographic about sites"
@${SRCDIR}/get-sites.R $< $@
sites.vrt: sites.vrt.in
@cp $^ $@
hpd/sites.shp: sites.vrt sites.csv \
${SRCDIR}/projections/scripts/extract_values.py
@echo "Extracting human population density at sites"
@ogr2ogr -f "ESRI Shapefile" -overwrite hpd $<
@extract_values -nodata -9999 -f $@ ${HPD_DB}
roads/sites.shp: sites.vrt sites.csv ${SRCDIR}/projections/roads/groads.py
@echo "Computing distance to a road"
@ogr2ogr -f "ESRI Shapefile" -overwrite roads $<
@project roads compute ${ROADS_DB} $@
# There are a couple of odd bits when running ogr2ogr:
#
# - It doesn't like it if the output file exists--even with the
# -override flag.
#
# - It deletes sites.csv
#
# So, remove the output and move sites.csv out of the way. Moveit back
# after ogr2ogr finishes.
%_sites.csv: %/sites.shp
rm -f $@
mv sites.csv foo.csv
ogr2ogr -f CSV -overwrite $@ $<
mv foo.csv sites.csv
site-div.rds: merged.rds hpd_sites.csv roads_sites.csv \
${SRCDIR}/gen-site-data.R
@echo "Generating site data file"
${SRCDIR}/gen-site-data.R --diversity merged.rds --hpd hpd_sites.csv \
--roads roads_sites.csv --out $@
sr-model.rds: site-div.rds ${SRCDIR}/fit-species-richness-model.R
@echo "Generating species richness model"
${NOSLEEP} ${SRCDIR}/fit-species-richness-model.R --site-data $< \
--out $(basename $@)
ab-model.rds: site-div.rds ${SRCDIR}/fit-abundance-model.R
@echo "Generating species abundance model"
${NOSLEEP} ${SRCDIR}/fit-abundance-model.R --site-data $< \
--out $(basename $@)
LU_TYPES = primary secondary cropland pasture urban
LUI_MODELS = $(addsuffix .rds, ${LU_TYPES})
${LUI_MODELS}: ${LUI_DATA} ${SRCDIR}/fit-landuse-intensity-model.R
@echo "Fitting $(basename $(notdir $@)) land use intensity model"
@${NOSLEEP} ${SRCDIR}/fit-landuse-intensity-model.R \
-t $(basename $(notdir $@)) --zip ${LUI_DATA} \
> $(addsuffix .log, $(basename $(notdir $@))) 2>&1
%.py: %.rds
@echo "compiling $(basename $(notdir $@)) land use intensity module"
@${NOSLEEP} r2py $(abspath $^)
@python $@
lui-models: ${LUI_MODELS} ${LUI_MODELS:.rds=.py}
.PRECIOUS: sites.csv
.PHONY: all lui-models outdir
endif