-
Notifications
You must be signed in to change notification settings - Fork 9
/
rasterMM.py
64 lines (55 loc) · 3.77 KB
/
rasterMM.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
# -*- coding: utf-8 -*-
# Program: RASTR.MM
# Version: 1.0
# Objective: To determine the max & min values in a raster dataset
# - BEGIN PROGRAM -
# Ascii art and name
print(
r"""
_____ _____ _______ _____ __ __ __ __
| __ \ /\ / ____|__ __| __ \ | \/ | \/ |
| |__) | / \ | (___ | | | |__) | | \ / | \ / |
| _ / / /\ \ \___ \ | | | _ / | |\/| | |\/| |
| | \ \ / ____ \ ____) | | | | | \ \ _| | | | | | |
|_| \_|_/ \_\_____/ |_| |_| \_(_)_| |_|_| |_|
-._ Developed by: Bilal Karim _.-
"""
)
# Main body of code
import os # Import OS module for later use to load appropriate paths, depending on which system is being used
filePath = raw_input("\n Hello, user. " # Provide info/instructions and ask user to input file path
"RASTR.MM lets you determine the MAX and MIN values of your raster dataset."
"\n \n Please type in the path of your raster file and press 'Enter': ")
x = 0 # Set up a file path validation system
while x < 1:
if os.path.exists(filePath): # If file path exists, continue. Otherwise, go to Line 58
x = 1
rasterFile = open(filePath, "r") # Open the file in read mode
data = rasterFile.readlines()[6:] # Read lines in data except for first 6 lines (i.e., skip header information)
check = True # Validation system for later use to determine max & min values
for lines in data:
content = lines.split() # Split lines of data and assign to a new variable
for dNvalue in content:
dNvalue = int(dNvalue) # Convert strings of DN values from data into integers for max & min evaluation
if check == True:
max = -1 # Validation system for min value (i.e., anything lower than 255)
min = 255 # Validation system for max value (i.e., anything higher than -1)
check = False
else:
if dNvalue > max: # Check to see if the currently read value is greater than max (i.e., -1)..
max = dNvalue # ..and keep continuing until the max value is found from the data
if dNvalue < min: # Check to see if the currently read value is less than min (i.e., 255)..
min = dNvalue # ..and keep continuing until the min value is found from the data
print ("\n Oh, hai there!"), ("\n Your maximum value is"), max, # Display max value to user
print ("\n Your minimum value is"), min # Display min value to user
rasterFile.close() # Close the file
else: # If file path does not exist..
raw_input("\n ** ERROR: File does not exist. Press 'Enter' to continue. ** ") # ..display an error message, and..
filePath = raw_input("\n Please type in the path to your raster file and press 'Enter': ") # ..ask the user to input the file path again
print ("\n RASTR.MM will exit in 5 seconds. \n") # Display exit message for users running this program in Command Prompt/Terminal
import time # Import time module..
time.sleep(5) # ..and exit the program in 5 seconds
# - END PROGRAM -
# What’s the most resilient parasite? Bacteria? A virus? An intestinal worm? An idea. Resilient. Highly contagious.
# Once an idea has taken hold of the brain, it is almost impossible to eradicate. An idea that is fully formed..
# ..fully understood - that sticks; right in there somewhere - Dom Cobb (Inception)