-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlfcoords.py
46 lines (38 loc) · 1.71 KB
/
lfcoords.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
import pandas as pd
import argparse
import logging
from lisfloodpreprocessing import Config
from lisfloodpreprocessing.finer_grid import coordinates_fine
from lisfloodpreprocessing.coarser_grid import coordinates_coarse
def main():
parser = argparse.ArgumentParser(
description="""
Correct the coordinates of a set of points to match the river network in the
LISFLOOD static map.
First, it uses a reference value of catchment area to find the most accurate
pixel in a high-resolution map.
Second, it finds the pixel in the low-resolution map that better matches the
catchment shape derived from the high-resolution map.
"""
)
parser.add_argument('-c', '--config-file', type=str, required=True, help='Path to the configuration file')
parser.add_argument('-r', '--reservoirs', action='store_true', default=True,
help='Define the points in the input CSV file as reservoirs')
args = parser.parse_args()
# create logger
logger = logging.getLogger('correct-coordinates')
logger.setLevel(logging.INFO)
logger.propagate = False
log_format = logging.Formatter('%(asctime)s | %(levelname)s | %(name)s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
c_handler = logging.StreamHandler()
c_handler.setFormatter(log_format)
c_handler.setLevel(logging.INFO)
logger.addHandler(c_handler)
# read configuration
cfg = Config(args.config_file)
# find coordinates in high resolution
points_HR = coordinates_fine(cfg, save=False)
# find coordinates in LISFLOOD
coordinates_coarse(cfg, points_HR, reservoirs=args.reservoirs, save=True)
if __name__ == "__main__":
main()