-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopulate_eab.py
44 lines (37 loc) · 1.71 KB
/
populate_eab.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
from datetime import date
import requests
from util.database import update_time_series
from util.database import table_exists
import subprocess
import os.path
today = date.today()
current_year = today.year
today_as_string = today.strftime("%Y-%m-%d")
eab_adult_url = f'https://uspest.org/CAPS/EAB2_cohorts/Misc_output/Earliest_PEMp0Excl1_{current_year}1231.tif'
eab_egg_url = f'https://uspest.org/CAPS/EAB2_cohorts/Misc_output/Earliest_PEMe1Excl1_{current_year}1231.tif'
def set_srs(tif_file):
temp_file = str.replace(tif_file, ".tif", "_warpme.tif")
os.rename(tif_file, temp_file)
warp_command = "gdalwarp -t_srs EPSG:4269 {source_file} {dest_file}"\
.format(source_file=temp_file, dest_file=tif_file)
ps = subprocess.Popen(warp_command, stdout=subprocess.PIPE, shell=True)
ps.wait()
os.remove(temp_file)
filename = f'/geo-data/gridded_models/eab/eab_adult/eab_adult_{date.today().strftime("%Y%m%d")}.tif'
with open(filename, 'wb') as out_file:
content = requests.get(eab_adult_url, stream=True).content
out_file.write(content)
time_series_table = 'eab_adult'
tif_name = f'eab_adult_{date.today().strftime("%Y%m%d")}.tif'
if table_exists(time_series_table):
update_time_series(time_series_table, tif_name, today)
set_srs(filename)
filename = f'/geo-data/gridded_models/eab/eab_egg_hatch/eab_egg_hatch_{date.today().strftime("%Y%m%d")}.tif'
with open(filename, 'wb') as out_file:
content = requests.get(eab_egg_url, stream=True).content
out_file.write(content)
time_series_table = 'eab_egg_hatch'
tif_name = f'eab_egg_hatch_{date.today().strftime("%Y%m%d")}.tif'
if table_exists(time_series_table):
update_time_series(time_series_table, tif_name, today)
set_srs(filename)