daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Name: Saad Sorathiq
  2. # Date:  October 10, 2017
  3. # Takes elevation data of NYC and displays using the default color map
  4.  
  5.  
  6. #Import the libraries for arrays and displaying images:
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9.  
  10.  
  11. #Read in the data to an array, called elevations:
  12. elevations = np.loadtxt('elevationsNYC.txt')
  13.  
  14. #Take the shape (dimensions) of the elevations
  15. #  and add another dimension to hold the 3 color channels:
  16. mapShape = elevations.shape + (3,)
  17.  
  18. #Create a blank image that's all zeros:
  19. floodMap = np.zeros(mapShape)
  20.  
  21. for row in range(mapShape[0]):
  22.     for col in range(mapShape[1]):
  23.         if elevations[row,col] <= 0:
  24.             #Below sea level
  25.            floodMap[row,col,2] = 1.0     #Set the blue channel to 100%
  26.         elif elevations[row,col] <= 6:
  27.             #Below the storm surge of Hurricane Sandy (flooding likely)
  28.            floodMap[row,col,0] = 1.0     #Set the red channel to 100%
  29.         else:
  30.             #Above the 6 foot storm surge and didn't flood
  31.             floodMap[row,col,1] = 1.0  #Set the green channel to 100%
  32.      
  33. #Load the flood map image into matplotlib.pyplot:
  34. plt.imshow(floodMap)
  35.  
  36. plt.show()
  37.  
  38. #Save the image:
  39. plt.imsave('floodMap.png', floodMap)
RAW Paste Data
Top