forked from cgq-qgc/pyhelp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR: Refactoring od the HELP manager (cgq-qgc#5)
* Add a method to set the working directory * Add a method to get arrays of cellnames lat/long * Add a method to get the cells that need to be run * Add a function to return surf. water cells * Add a method to calcul budget for surf. water * Add a property that return the input dir * Rework manager arguments * Make manager load a grid from a csv * Update script * Make d10d11 formatting compat with pandas * Update scripts * Move the logic to load grid from csv in a function * Update gitignore * Override d10d11 files if they exist * Codestyle and fix a typo * dump changes to scripts * Dump changes to script * Function to create shapely points from coords * New posprocessing module
- Loading branch information
1 parent
5764be6
commit fe65acc
Showing
8 changed files
with
569 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
example/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*$py.class | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Apr 24 11:18:39 2018 | ||
@author: User | ||
""" | ||
|
||
from itertools import product | ||
from shapely.geometry import Point | ||
import numpy as np | ||
|
||
|
||
def produce_point_geometry(lat, lon): | ||
"""Return a list of shapely points from lat, lon coordinates.""" | ||
return [Point(x, y) for x, y in zip(lon, lat)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright © 2018 PyHelp Project Contributors | ||
# https://github.com/jnsebgosselin/pyhelp | ||
# | ||
# This file is part of PyHelp. | ||
# Licensed under the terms of the GNU General Public License. | ||
|
||
# ---- Third Party imports | ||
|
||
import numpy as np | ||
import time | ||
|
||
|
||
def add_yrly_avg_to_shp(shp, outdat): | ||
tic = time.clock() | ||
|
||
cellnames = list(outdat.keys()) | ||
years = outdat[cellnames[0]]['years'].value | ||
nyears = len(years) | ||
ncells = len(cellnames) | ||
|
||
avg_rain = np.zeros(ncells) | ||
avg_runoff = np.zeros(ncells) | ||
avg_evapo = np.zeros(ncells) | ||
avg_perco = np.zeros(ncells) | ||
avg_subrun1 = np.zeros(ncells) | ||
avg_subrun2 = np.zeros(ncells) | ||
avg_recharge = np.zeros(ncells) | ||
|
||
for i, cellname in enumerate(cellnames): | ||
print("\rProcessing cell %d of %d..." % (i+1, ncells), end=' ') | ||
data = outdat[cellname] | ||
avg_rain[i] = np.sum(data['rain'].value) / nyears | ||
avg_runoff[i] = np.sum(data['runoff'].value) / nyears | ||
avg_evapo[i] = np.sum(data['evapo'].value) / nyears | ||
if shp['context'][cellname] == 0: | ||
# Handle surface water results. | ||
avg_perco[i] = 0 | ||
avg_subrun1[i] = 0 | ||
avg_subrun2[i] = 0 | ||
avg_recharge[i] = 0 | ||
else: | ||
# Handle HELP results. | ||
avg_perco[i] = np.sum(data['percolation'].value) / nyears | ||
avg_subrun1[i] = np.sum(data['subrun1'].value) / nyears | ||
avg_subrun2[i] = np.sum(data['subrun2'].value) / nyears | ||
avg_recharge[i] = np.sum(data['recharge'].value) / nyears | ||
if shp['context'][cellname] == 2: | ||
# Convert recharge to runoff when cells are close to a stream. | ||
if avg_subrun2[-1] == 0: | ||
# Convert recharge as surficial subrunoff. | ||
avg_subrun1[-1] = avg_subrun1[-1] + avg_recharge[-1] | ||
else: | ||
# This means there is a layer of sand above the clay layer. | ||
# Convert recharge as deep runoff. | ||
avg_subrun2[-1] = avg_subrun2[-1] + avg_recharge[-1] | ||
avg_recharge[-1] = 0 | ||
|
||
# Insert yearly average values in the grid. | ||
shp.loc[cellnames, 'rain'] = avg_rain | ||
shp.loc[cellnames, 'runoff'] = avg_runoff | ||
shp.loc[cellnames, 'evapo'] = avg_evapo | ||
|
||
shp.loc[cellnames, 'percolation'] = avg_perco | ||
shp.loc[cellnames, 'subrun1'] = avg_subrun1 | ||
shp.loc[cellnames, 'subrun2'] = avg_subrun2 | ||
shp.loc[cellnames, 'recharge'] = avg_recharge | ||
print("\rProcessing cell %d of %d... done in %0.1fs" % | ||
(i+1, ncells, (time.clock() - tic))) | ||
return shp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.