-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ca8c69
commit 4121831
Showing
4 changed files
with
86 additions
and
9 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,3 @@ | ||
from . import constants, io, plotting, settings | ||
from . import analysis, constants, io, plotting, settings | ||
from . import agro, crop, site, soil, weather | ||
from .model import run_pcse_single, run_pcse_ensemble, run_pcse_ensemble_parallel |
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,20 @@ | ||
""" | ||
Functions for analysis | ||
""" | ||
import numpy as np | ||
import pandas as pd | ||
import geopandas as gpd | ||
|
||
from ._typing import Callable | ||
|
||
def weighted_mean_for_DF(data: pd.DataFrame, *, weightby: str="area") -> Callable: | ||
""" | ||
Generate a weighted mean function for the given dataframe, to be used in .agg. | ||
Example: | ||
weight_by_area = weighted_mean_for_DF(summary) | ||
weighted_average_yield = summary.agg(wm_twso=("TWSO", weight_by_area)) | ||
""" | ||
def weighted_mean(x): | ||
return np.average(x, weights=data.loc[x.index, weightby]) | ||
|
||
return weighted_mean |
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
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