-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaleocar_v2.sh
executable file
·103 lines (83 loc) · 5.57 KB
/
paleocar_v2.sh
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
mkdir -p paleocar_v2/raw
for long in {103..115}
do
for lat in {31..42}
do
echo paleocar_v2/raw/$long\W$lat\N_GDD.nc4
if ! [ -f paleocar_v2/raw/$long\W$lat\N_GDD.nc4 ]; then
curl https://www1.ncdc.noaa.gov/pub/data/paleo/treering/reconstructions/northamerica/usa/bocinsky2016/$long\W$lat\N_GDD.nc4 --output paleocar_v2/raw/$long\W$lat\N_GDD.nc4
fi
echo paleocar_v2/raw/$long\W$lat\N_PPT.nc4
if ! [ -f paleocar_v2/raw/$long\W$lat\N_PPT.nc4 ]; then
curl https://www1.ncdc.noaa.gov/pub/data/paleo/treering/reconstructions/northamerica/usa/bocinsky2016/$long\W$lat\N_PPT.nc4 --output paleocar_v2/raw/$long\W$lat\N_PPT.nc4
fi
done
done
## ppt_water_year
echo "Building paleocar_v2 ppt_water_year dataset"
mkdir -p paleocar_v2/ppt_water_year/geoserver
if ! [ -f paleocar_v2/ppt_water_year/cube.tif ]; then
gdalbuildvrt -a_srs EPSG:4326 -srcnodata -32768 paleocar_v2/ppt_water_year/cube.vrt paleocar_v2/raw/*PPT.nc4
gdal_translate -ot Int16 -co BIGTIFF=YES -co TILED=YES -co BLOCKXSIZE=16 -co BLOCKYSIZE=16 -co COMPRESS=DEFLATE -co NUM_THREADS=ALL_CPUS --config GDAL_PAM_ENABLED NO paleocar_v2/ppt_water_year/cube.vrt paleocar_v2/ppt_water_year/cube.tif
fi
N=$(($(nproc --all)-2))
(
for year in {0001..2000}; do
((i=i%N)); ((i++==0)) && wait
# echo "paleocar_v2/ppt_water_year/geoserver/paleocar_v2_ppt_water_year_$year.tif"
if [ -f "paleocar_v2/ppt_water_year/geoserver/paleocar_v2_ppt_water_year_$year.tif" ]
then
continue
else
let band=$((10#$year)); gdal_translate paleocar_v2/ppt_water_year/cube.tif paleocar_v2/ppt_water_year/geoserver/paleocar_v2_ppt_water_year_$year.tif -b $band -of COG -ot Int16 -co BLOCKSIZE=128 -co OVERVIEWS=NONE -co COMPRESS=DEFLATE -q &
fi
done
)
## gdd_may_sept
echo "Building paleocar_v2 gdd_may_sept dataset"
mkdir -p paleocar_v2/gdd_may_sept/geoserver
if ! [ -f paleocar_v2/gdd_may_sept/cube.tif ]; then
gdalbuildvrt -a_srs EPSG:4326 -srcnodata -32768 paleocar_v2/gdd_may_sept/cube.vrt paleocar_v2/raw/*GDD.nc4
gdal_translate -ot Int16 -co BIGTIFF=YES -co TILED=YES -co BLOCKXSIZE=16 -co BLOCKYSIZE=16 -co COMPRESS=DEFLATE -co NUM_THREADS=ALL_CPUS --config GDAL_PAM_ENABLED NO paleocar_v2/gdd_may_sept/cube.vrt paleocar_v2/gdd_may_sept/cube.tif
fi
(
for year in {0001..2000}; do
((i=i%N)); ((i++==0)) && wait
# echo "paleocar_v2/gdd_may_sept/geoserver/paleocar_v2_gdd_may_sept_$year.tif"
if [ -f "paleocar_v2/gdd_may_sept/geoserver/paleocar_v2_gdd_may_sept_$year.tif" ]
then
continue
else
let band=$((10#$year)); gdal_translate paleocar_v2/gdd_may_sept/cube.tif paleocar_v2/gdd_may_sept/geoserver/paleocar_v2_gdd_may_sept_$year.tif -b $band -of COG -ot Int16 -co BLOCKSIZE=128 -co OVERVIEWS=NONE -co COMPRESS=DEFLATE -q &
fi
done
)
# maize_farming_niche
echo "Building paleocar_v2 maize_farming_niche dataset"
mkdir -p paleocar_v2/maize_farming_niche/geoserver
(
for year in {0001..2000}; do
((i=i%N)); ((i++==0)) && wait
# echo "paleocar_v2/maize_farming_niche/geoserver/paleocar_v2_maize_farming_niche_$year.tif"
if [ -f "paleocar_v2/maize_farming_niche/geoserver/paleocar_v2_maize_farming_niche_$year.tif" ]
then
continue
else
let band=$((10#$year)); gdal_calc.py -A paleocar_v2/ppt_water_year/geoserver/paleocar_v2_ppt_water_year_$year.tif -B paleocar_v2/gdd_may_sept/geoserver/paleocar_v2_gdd_may_sept_$year.tif --outfile=paleocar_v2/maize_farming_niche/geoserver/temp.tif --calc="(A>=300)*(B>=1800)" --type=Byte --co TILED=YES --co BLOCKXSIZE=128 --co BLOCKYSIZE=128 --co COMPRESS=DEFLATE --overwrite --quiet; gdal_translate paleocar_v2/maize_farming_niche/geoserver/temp.tif paleocar_v2/maize_farming_niche/geoserver/paleocar_v2_maize_farming_niche_$year.tif -of COG -ot Byte -co BLOCKSIZE=128 -co OVERVIEWS=NONE -co COMPRESS=DEFLATE -q &
fi
done
)
## Bash add pause prompt for 5 seconds ##
sleep 30
rm paleocar_v2/maize_farming_niche/geoserver/temp.tif
cp styles/paleocar_ppt_annual.sld paleocar_v2/ppt_water_year/geoserver/paleocar_ppt_annual.sld
cp styles/paleocar_gdd_summer.sld paleocar_v2/gdd_may_sept/geoserver/paleocar_gdd_summer.sld
cp styles/paleocar_niche.sld paleocar_v2/maize_farming_niche/geoserver/paleocar_niche.sld
rsync -razhv paleocar_v2/ppt_water_year skope_staging:/projects/skope/datasets/paleocar_v2/
rsync -razhv paleocar_v2/gdd_may_sept skope_staging:/projects/skope/datasets/paleocar_v2/
gdalbuildvrt -separate paleocar_v2/maize_farming_niche/cube.vrt paleocar_v2/maize_farming_niche/geoserver/*.tif
gdal_translate -ot Byte -co BIGTIFF=YES -co TILED=YES -co BLOCKXSIZE=16 -co BLOCKYSIZE=16 -co COMPRESS=DEFLATE -co NUM_THREADS=ALL_CPUS --config GDAL_PAM_ENABLED NO paleocar_v2/maize_farming_niche/cube.vrt paleocar_v2/maize_farming_niche/cube.tif
rsync -razhv paleocar_v2/maize_farming_niche skope_staging:/projects/skope/datasets/paleocar_v2/
#python main.py geoserver load --host https://geoserver.openskope.org --workspace SKOPE --geoserver-base-path /projects/skope/datasets/paleocar_v2/ppt_water_year/geoserver --base-path /projects/skope/datasets/paleocar_v2/ppt_water_year/geoserver
#python main.py geoserver load --host https://geoserver.openskope.org --workspace SKOPE --geoserver-base-path /projects/skope/datasets/paleocar_v2/gdd_may_sept/geoserver --base-path /projects/skope/datasets/paleocar_v2/gdd_may_sept/geoserver
#python main.py geoserver load --host https://geoserver.openskope.org --workspace SKOPE --geoserver-base-path /projects/skope/datasets/paleocar_v2/maize_farming_niche/geoserver --base-path /projects/skope/datasets/paleocar_v2/maize_farming_niche/geoserver