-
Notifications
You must be signed in to change notification settings - Fork 18
/
PlotDrainageCaptureMetrics.py
85 lines (71 loc) · 4.02 KB
/
PlotDrainageCaptureMetrics.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
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
#=============================================================================
# Script to plot metrics for identifying drainage capture
#
# Authors:
# Fiona J. Clubb
#=============================================================================
#=============================================================================
# IMPORT MODULES
#=============================================================================
# set backend to run on server
import matplotlib
matplotlib.use('Agg')
#from __future__ import print_function
import sys
import os
from LSDPlottingTools import LSDMap_DrainageCapture as DC
from LSDMapFigure import PlottingHelpers as Helper
#=============================================================================
# This is just a welcome screen that is displayed if no arguments are provided.
#=============================================================================
def print_welcome():
print("\n\n=======================================================================")
print("Hello! I'm going to plot the drainage capture results for you.")
print("You will need to tell me which directory to look in.")
print("Use the -dir flag to define the working directory.")
print("If you don't do this I will assume the data is in the same directory as this script.")
print("For help type:")
print(" python PlotMOverNAnalysis.py -h\n")
print("=======================================================================\n\n ")
#=============================================================================
# This is the main function that runs the whole thing
#=============================================================================
def main(argv):
# print("On some windows systems you need to set an environment variable GDAL_DATA")
# print("If the code crashes here it means the environment variable is not set")
# print("Let me check gdal enviroment for you. Currently is is:")
# print(os.environ['GDAL_DATA'])
#os.environ['GDAL_DATA'] = os.popen('gdal-config --datadir').read().rstrip()
#print("Now I am going to get the updated version:")
#print(os.environ['GDAL_DATA'])
# If there are no arguments, send to the welcome screen
if not len(sys.argv) > 1:
full_paramfile = print_welcome()
sys.exit()
# Get the arguments
import argparse
parser = argparse.ArgumentParser()
# The location of the data files
parser.add_argument("-dir", "--base_directory", type=str, help="The base directory that contains your data files. If this isn't defined I'll assume it's the same as the current directory.")
parser.add_argument("-fname", "--fname_prefix", type=str, help="The prefix of your DEM WITHOUT EXTENSION!!! This must be supplied or you will get an error (unless you're running the parallel plotting).")
# These control the format of your figures
parser.add_argument("-fmt", "--FigFormat", type=str, default='png', help="Set the figure format for the plots. Default is png")
parser.add_argument("-size", "--size_format", type=str, default='ESURF', help="Set the size format for the figure. Can be 'big' (16 inches wide), 'geomorphology' (6.25 inches wide), or 'ESURF' (4.92 inches wide) (defualt esurf).")
# what plots you want to make
parser.add_argument("-P", "--plot_perimeter", type=bool, help="If this is true I'll make some plots of basin perimeters.")
args = parser.parse_args()
# get the base directory
if args.base_directory:
this_dir = args.base_directory
# check if you remembered a / at the end of your path_name
if not this_dir.endswith("/"):
print("You forgot the '/' at the end of the directory, appending...")
this_dir = this_dir+"/"
else:
this_dir = os.getcwd()
# make the plots depending on your choices
if args.plot_perimeter:
DC.PlotBasinPerimeter(this_dir, args.fname_prefix, args.size_format, args.FigFormat)
#=============================================================================
if __name__ == "__main__":
main(sys.argv[1:])