-
Notifications
You must be signed in to change notification settings - Fork 2
/
tools.py
54 lines (41 loc) · 1.44 KB
/
tools.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
import os
import re
def get_date(x):
"""parse filename to return event name"""
basename = os.path.basename(x)
date = basename.split("_")[1:4]
date = "_".join(date)
return date
def get_event(path):
"""
Determines the event for a given UAS flight
When there is only one event, the event is not typically recorded in the file name.
So, values for path are of the general form:
/path/to/file/site_month_day_year_projected.shp
or
/path/to/file/site_month_day_year_event_projected.shp
This function returns "primary" for no event and events with the following values:
"A", "a", "primary", "PRIMARY", or mixed case versions of "primary"
"""
filename = os.path.basename(path)
regex = re.compile(r'\w+_\d+_\d+_\d+_(\w+)_projected')
match = regex.match(filename)
if match:
event = match.group(1).upper()
if event not in {"A", "PRIMARY"}:
return (event, "_" + event)
else:
return ("primary", "_" + event)
else:
return ("primary", "")
def get_site(path):
path = os.path.basename(path)
regex = re.compile("(\\w+)_\\d+_\\d+_\\d+.*_projected")
return regex.match(path).group(1)
def get_year(path):
date = get_date(path)
year = date.split('_')[2]
return year
def get_working_dir():
test_env_set = os.environ.get("TEST_ENV")
return "/blue/ewhite/everglades_test" if test_env_set else "/blue/ewhite/everglades"