def calculateFlowsAndPlot(elevation, rain, resampleF): # plot input rasters plotRaster(elevation.getData(), "Original elevation (m)") plotRaster(rain.getData(), "Rainfall") resampledElevations = elevation.createWithIncreasedCellsize(resampleF) ################# step 1 find and plot the intial network ####### fr = flow.FlowRaster(resampledElevations) plotFlowNetwork(resampledElevations, fr, "Network structure - before lakes", plotLakes=False) ################Step 2 ###################################### plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - constant rain") ################# step 3 ####################################### #handle variable rainfall fr.addRainfall(rain.getData()) plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall") ############# step 4 and step 5 ####################################### #handle lakes fr.calculateLakes() plotFlowNetwork(resampledElevations, fr, "Network structure (i.e. watersheds) - with lakes") plotExtractedData(fr, flow.LakeDepthExtractor(), "Lake depth") plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall") maxflow, maxnode = fr.getMaxFlow() print("Maximum Flow is " + str(maxflow) + " mm per year at " + str(maxnode))
def calculateFlowsAndPlot(elevation, rain, resampleF, tasks=['1', '2', '3', '4', '5']): """ The main function to execute the project. Processes elevation and rain data, producing a series of plots of elevations, flow networks, and lake depths. """ # plot input rasters plotRaster(elevation.getData(), "Original elevation (m)") plotRaster(rain.getData(), "Rainfall") resampledElevations = elevation.createWithIncreasedCellsize(resampleF) ################# step 1 find and plot the intial network ####### fr = flow.FlowRaster(resampledElevations) plotFlowNetwork(elevation, fr, "Network structure - before lakes", plotLakes=False) ################Step 2 ###################################### plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - constant rain") ################# step 3 ####################################### #handle variable rainfall fr.addRainfall(rain.getData()) plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall") ############# step 4 and step 5 ####################################### # handle lakes fr.calculateLakes() plotFlowNetwork(elevation, fr, "Network structure (i.e. watersheds) - with lakes") plotExtractedData(fr, flow.LakeDepthExtractor(), "Lake depth") plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall") ############# Answer questions for step 5 ############################# values = fr.extractValues(flow.FlowExtractor()) # Max maxflow = np.max(values) # Row rowMax = np.where(values == maxflow)[0][0] # Col colMax = np.where(values == maxflow)[1][0] # Print message print("Maximum flow of\n\n{} found in node [{},{}]".format( maxflow, rowMax, colMax))
def calculateFlowsAndPlot(elevation, rain, resampleF): """Calculates all the flows and plots them Input Parameter: elevation – a Raster class object containing elevation rain – a Raster class object containing rainfall resampleF – an Integer """ # plot input rasters plotRaster(elevation.getData(), "Original elevation (m)") #plot elevation plotRaster(rain.getData(), "Rainfall") #plot rainfall resampledElevations = elevation.createWithIncreasedCellsize(resampleF) ################# step 1 find and plot the intial network ####### fr = Flow.FlowRaster(resampledElevations) #create FlowRaster plotFlowNetwork(fr, fr, "Task 1: Network structure - before lakes", plotLakes=False) #plot flow raster ################Step 2 ###################################### plotExtractedData(fr, Flow.FlowExtractor(1), "Task 2: River flow rates - constant rain") ################# step 3 ####################################### #handle variable rainfall fr.addRainfall(rain.getData()) plotExtractedData(fr, Flow.FlowExtractor(), "Task 3: River flow rates - variable rainfall") ############# step 4 and step 5 ####################################### # handle lakes fr.calculateLakes() plotFlowNetwork( fr, fr, "Task 4: Network structure (i.e. watersheds) - with lakes") plotExtractedData(fr, Flow.LakeDepthExtractor(), "Task 4: Lake depth") plotExtractedData(fr, Flow.FlowExtractor(), "Task 4: River flow rates - variable rainfall") #TESTING #this line tests if total raster outflow is equal to total rainfall on the raster assert round(fr.getTotalFlow(), 2) == round(fr.getTotalRainfall(), 2) ############# step 5 ####################################### maxflow = fr.getMaximumFlow() print("Task 5: Maximum Flow: {} mm, at FlowNode object: {}".format( round(maxflow[0], 3), maxflow[1]))
def calculateFlowsAndPlot(elevation, rain, resampleF): # plot input rasters plotRaster(elevation.getData(), "Original elevation (m)") plotRaster(rain.getData(), "Rainfall") resampledElevations = elevation.createWithIncreasedCellsize(resampleF) ################# step 1 find and plot the intial network ####### ''' 1. From Raster import Raster 2. Execute full code ''' fr = flow.FlowRaster(resampledElevations) plotFlowNetwork(elevation, fr, "Network structure - before lakes", plotLakes=False) ################Step 2 ###################################### ''' Calculate flow volume Resursively call each up-node and add one each time Solution: def getValue(self, node): return node.numUpnodes() ''' plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - constant rain") ################# step 3 ####################################### #handle variable rainfall ''' addRainfall does not replace any values but adds the rainfall values on top of the current _data attribute of every node ''' fr.addRainfall(rain.getData()) plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall", isRainFall=True)
def calculateFlowsAndPlot(elevation, rain, resampleF): """ The main function to execute the project. Processes elevation and rain data, producing a series of plots of elevations, flow networks, and lake depths. """ # plot input rasters plotRaster(elevation.getData(), "Original elevation (m)") plotRaster(rain.getData(), "Rainfall") resampledElevations = elevation.createWithIncreasedCellsize(resampleF) ################# step 1 find and plot the intial network ####### fr = flow.FlowRaster(resampledElevations) plotFlowNetwork(elevation, fr, "Network structure - before lakes", plotLakes=False) ################Step 2 ###################################### plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - constant rain") ################# step 3 ####################################### #handle variable rainfall fr.addRainfall(rain.getData()) plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall") ############# step 4 and step 5 ####################################### # handle lakes fr.calculateLakes() plotFlowNetwork(elevation, fr, "Network structure (i.e. watersheds) - with lakes") plotExtractedData(fr, flow.LakeDepthExtractor(), "Lake depth") plotExtractedData(fr, flow.FlowExtractor(), "River flow rates - variable rainfall")