diff --git a/SMHviz_plot/utils_data.py b/SMHviz_plot/utils_data.py index 8b4e51e..d9eb3fa 100644 --- a/SMHviz_plot/utils_data.py +++ b/SMHviz_plot/utils_data.py @@ -206,7 +206,9 @@ def sample_df(df, scenario, pathogen, k=1000): all_sample_sel = list(np.random.permutation(all_sample_sel)) df_sample_sel = df_scen.reset_index().set_index("sample_id").loc[all_sample_sel] all_sample = df_sample_sel.reset_index().drop(columns="index") - all_sample["sample_id_n"] = list(np.repeat(list(range(k)), len(df_scen['horizon'].drop_duplicates()))) + + all_sample["sample_id_n"] = np.repeat(np.arange(k), len(df_scen['horizon'].drop_duplicates())) + all_sample = all_sample[["value", "target_end_date", "sample_id_n"]] all_sample = all_sample.rename(columns={"value": "value" + "_" + pathogen}) else: @@ -223,7 +225,7 @@ def q1(x): :type x: pd.Series :return: float """ - return x.quantile(0.025) + return np.quantile(x, 0.025) def q2(x): @@ -235,7 +237,7 @@ def q2(x): :type x: pd.Series :return: float """ - return x.quantile(0.05) + return np.quantile(x, 0.05) def q3(x): @@ -247,7 +249,7 @@ def q3(x): :type x: pd.Series :return: float """ - return x.quantile(0.1) + return np.quantile(x, 0.1) def q4(x): @@ -259,7 +261,7 @@ def q4(x): :type x: pd.Series :return: float """ - return x.quantile(0.25) + return np.quantile(x, 0.25) def q5(x): @@ -271,7 +273,7 @@ def q5(x): :type x: pd.Series :return: float """ - return x.quantile(0.75) + return np.quantile(x, 0.75) def q6(x): @@ -283,7 +285,7 @@ def q6(x): :type x: pd.Series :return: float """ - return x.quantile(0.9) + return np.quantile(x, 0.9) def q7(x): @@ -295,7 +297,7 @@ def q7(x): :type x: pd.Series :return: float """ - return x.quantile(0.95) + return np.quantile(x, 0.95) def q8(x): @@ -307,7 +309,7 @@ def q8(x): :type x: pd.Series :return: float """ - return x.quantile(0.975) + return np.quantile(x, 0.975) def med(x): @@ -319,7 +321,7 @@ def med(x): :type x: pd.Series :return: float """ - return x.quantile(0.5) + return np.quantile(x, 0.5) def mean(x): @@ -391,9 +393,9 @@ def prep_multipat_plot_comb(pathogen_information, calc_mean=False): # Preparation pathogen_name = patho.lower() if calc_mean is True: - f2.update({"proportion_" + pathogen_name: [med, mean, q1, q2, q3, q4, q5, q6, q7, q8]}) + f2.update({"proportion_" + pathogen_name: [mean, q4, q5]}) else: - f2.update({"proportion_" + pathogen_name: [med, q1, q2, q3, q4, q5, q6, q7, q8]}) + f2.update({"proportion_" + pathogen_name: [q4, q5]}) all_sample["proportion_" + pathogen_name] = all_sample["value_" + pathogen_name] / all_sample["value"] # Calculate the quantiles for each "value" and "proportion" columns all_quantile = all_sample.groupby(["target_end_date"]).agg(f) diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..541cf09 --- /dev/null +++ b/changelog.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## 0.0.1 + +First version diff --git a/docs/release_protocol.md b/docs/release_protocol.md new file mode 100644 index 0000000..635f581 --- /dev/null +++ b/docs/release_protocol.md @@ -0,0 +1,153 @@ +# Release Process + +Parts of this document is adapted for the U.S. Scenario Modeling Hub (SMH) from +[The Hubverse](https://hubverse-org.github.io/hubDevs/articles/release-process.html) +and from +[The Carpentries Developer's Handbook](https://carpentries.github.io/workbench-dev/releases.html) © +The Carpentries under the +[CC-BY 4.0 license](https://creativecommons.org/licenses/by/4.0/). + +## Workflow + +The release process follow a general workflow: + +1. Iterate on small bug fixes and PRs on branches: + - merging into `main` once ready to publish/deploy + - merging into a development branch (here called `dev`) for ongoing test/process +2. When ready to release on `main`: bump the version, add an annotated git tag, and release +3. Bump the version in main back to a development version + +Some of the steps in these instructions are specific for R packages, but they are largely process-based +and can apply to Python packages as well. + +### Versioning + +The SMH is built using very basic semantic versioning using the X.Y.Z[.9000] pattern. Everything that +has a .9000 attached is considered in-development. + +`X`: **Major version number**: this version number will change if there are significant breaking +changes to any of the user-facing workflows. That is, if a change requires users to modify their +scripts, then it is a breaking change. + +`Y`: **Minor version number**: this version number will change if there are new features or + enhanced behaviors available to the users in a way that *does not affect how users who do not +need the new features use the package*. This number grows the fastest in early stages of development. + +`Z`: **Patch version number**: this version number will change if something that was previously +broken was fixed, but no new features have been added. + +`9000`: **Development version indicator**: this version number indicates that the package is in a +development state and has the potential to change. When its on the main branch, it indicates +that the features or patches introduced have been reviewed and tested. This version is appended +after every successful release. + +### Hotfixes + +A hotfix is a bug fix for a situation where a bug has been found, but the main branch has new features +that are not yet ready to be released. + +## Checklist + +### Updates + +[] Create new branch from `main` (or `master`, or branch of interest) called `"//"` + +[] Update `Changelog.md` accordingly + +[] Commit, push + +[] Open Pull-Request (PR) on branch of interest (`main` for release we want to implement quickly or ready to deploy, other + branch of interest for ongoing updates) + +[] Merge after review, once all accepted + +**Create new release version only if important change, see version** + +### Release + +[] Create new branch from `main` (or `master`) called `"/release/X.Y.Z"` + +[] Update `pyproject.toml` and `Changelog.md` accordingly + +[] Commit, push + +[] Open Pull-Request (PR) + +[] Merge after review, once all accepted + +[] Checkout `main` branch (or `master`) & make sure it's up to date + +[] Add new tag + +``` +git tag -a v.X.Y.Z -m '' +git push --tags +``` + +[] Create a new release on GitHub (can be done using R, for example) + +```r +usethis::use_github_release() +``` + +### Post-Release + +[] Create new branch from `main` (or `master`) called `"post-release-X.Y.Z"` + +[] Set project to dev version (can be done using R, for example): + - adding `.9000` to the version number + - adding new heading to `Changelog.md` (`## (development)`) + +```r +usethis::use_dev_version() +``` + +[] Commit, push, open Pull-Request (PR) + +[] Merge after review, once all accepted + + +### Subsequent updates + +[] Create new branch from `main` (or `master`, or branch of interest) called `"//"` + +[] Update `Changelog.md` accordingly + +[] Commit, push + +[] Open Pull-Request (PR) + +[] Merge after review, once all accepted + +**Create new release version only if important change, see version** + +### Hotfixes + +[] Create new branch from `main` (or `master`) called `"/hotfix/"` + +``` +git switch --detach v.X.Y.Z' +git switch -c /hotfix/ +``` + +[] Write a test, fix the bug, commit, push +** Don't change the version ** + +[] Open Pull-Request (PR) + +[] Update `Changelog.md` accordingly and bump the patch version in `pyproject.toml` + +``` +git commit -m 'bump version to X.Y.Z+1' +git tag -a v.X.Y.Z+1 -m '' +git push +git push --tags +``` + +[] Create a new release on GitHub (can be done using R, for example) + +```r +usethis::use_github_release() +``` + +[] Resolve conflicts in PR & merge into `main` (or `master`)