Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update pre-commit hooks and format all files #94

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
directory: '/'
schedule:
interval: daily
- package-ecosystem: 'github-actions'
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ name: CI

on:
push:
branches: "*"
branches:
- main
pull_request:
branches: "*"
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
Expand All @@ -19,7 +25,7 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2.1.1
with:
python-version: ${{ matrix.python-version }}
mamba-version: "*"
mamba-version: '*'
activate-environment: carbonplan
channels: conda-forge
channel-priority: true
Expand Down Expand Up @@ -73,10 +79,3 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
- uses: actions/setup-python@v2.3.1
- uses: pre-commit/action@v2.0.3
65 changes: 33 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
ci:
autoupdate_schedule: quarterly
exclude: notebooks/fire/figure_foresttype.ipynb
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-json
- id: check-yaml
- id: pretty-format-json
args: ["--autofix", "--indent=2", "--no-sort-keys"]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: debug-statements
- id: mixed-line-ending

- repo: https://github.com/ambv/black
rev: 20.8b1
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: black
args: ["--line-length", "100", "--skip-string-normalization"]
- id: pyupgrade
args:
- '--py310-plus'

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.0
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: flake8
- id: black
- id: black-jupyter

- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.8.0
- id: blackdoc

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: isort
- id: flake8

- repo: https://github.com/deathbeds/prenotebook
rev: f5bdb72a400f1a56fe88109936c83aa12cc349fa
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: prenotebook
- id: isort

# for R code
# - repo: https://github.com/lorenzwalthert/precommit
# rev: v0.1.3
# hooks:
# - id: style-files
# args: [--style_pkg=styler, --style_fun=tidyverse_style]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
hooks:
- id: prettier
3 changes: 3 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tabWidth = 2
semi = false
singleQuote = true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ Several notebooks are additionally provided that show the use of these tools for
## data products

As part of this project we have created derived data products for five key variables relevant to evaluating forest carbon storage potential and risks.

- `biomass` The potential carbon storage in forests assuming continued growth of existing forests.
- `fire` The risks associated with forest fires.
- `drought` The risk to forests from insect-related tree mortality.
- `insects` The risk to forests from insect-related tree mortality.

Gridded rasters for each of these layers are available for the continental United States at a 4km spatial scale. For biomass and fire, projections are shown through the end of the 21st century in decadal increments. Drought and insect models are still in development so we currently only show historical risks for these disturbance types. All data are accessible via this [catalog](https://github.com/carbonplan/forest-risks/blob/master/carbonplan_forest_risks/data/catalog.yaml). Additional formats and download options will be provided in the future.
Gridded rasters for each of these layers are available for the continental United States at a 4km spatial scale. For biomass and fire, projections are shown through the end of the 21st century in decadal increments. Drought and insect models are still in development so we currently only show historical risks for these disturbance types. All data are accessible via this [catalog](https://github.com/carbonplan/forest-risks/blob/master/carbonplan_forest_risks/data/catalog.yaml). Additional formats and download options will be provided in the future.

## license

Expand Down
1 change: 0 additions & 1 deletion carbonplan_forest_risks/load/cmip.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def cmip(
if member is None:
member = members[model]


path = setup.loading(store)

prefix = f'cmip6/{method}/conus/4000m/{sampling}/{model}.{scenario}.{member}.zarr'
Expand Down
2 changes: 1 addition & 1 deletion carbonplan_forest_risks/load/fia.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def fia_state_grouped(store, state, clean):
key = f'year_{year}'
if key in df.columns:
if clean:
df = df[(df[key] < 9999) | np.isnan((df[key]))]
df = df[(df[key] < 9999) | np.isnan(df[key])]
if sum(np.isnan(df[key])) == len(df):
del df[key]

Expand Down
2 changes: 1 addition & 1 deletion carbonplan_forest_risks/plot/fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def full_eval(
}

for metric, performance in eval_metrics.items():
print('performance at {} scale is: {}'.format(metric, performance))
print(f'performance at {metric} scale is: {performance}')

return eval_metrics, evaluation(
data,
Expand Down
2 changes: 1 addition & 1 deletion carbonplan_forest_risks/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def annualize(
elif variable == 'cwd':
aggregated = aggregated.max()
else:
print('{} not implemented'.format(variable))
print(f'{variable} not implemented')

# drop your first year if you were rolling
if climate_prepend is not None:
Expand Down
2 changes: 1 addition & 1 deletion carbonplan_forest_risks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def weighted_mean(ds, *args, **kwargs):


def get_store(bucket, prefix, account_key=None):
''' helper function to create a zarr store'''
'''helper function to create a zarr store'''

if account_key is None:
account_key = os.environ.get('BLOB_ACCOUNT_KEY', None)
Expand Down
8 changes: 4 additions & 4 deletions envs/python-notebook/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: carbonplan
channels:
- conda-forge
dependencies:
- pangeo-notebook=2020.10.08 # don't bump until we bump the dask-gateway chart
- pangeo-notebook=2020.10.08 # don't bump until we bump the dask-gateway chart
- adlfs
- altair
- altair_data_server
Expand Down Expand Up @@ -83,7 +83,7 @@ dependencies:
- numbagg
- showit
- git+https://github.com/jhamman/scikit-downscale.git@a502557f322cf6a8cd2e34008b31f1b89b7e8190
- git+https://github.com/jhamman/zarr.git@fix/absstore # for current version of azure api
- git+https://github.com/jhamman/climate_indices.git@39bbf038c77922f8f0a46bb69704d6aace4179f9 # for no-nco deps, expanded range of pdsi
- git+https://github.com/altair-viz/altair_data_server.git # for remote hosting
- git+https://github.com/jhamman/zarr.git@fix/absstore # for current version of azure api
- git+https://github.com/jhamman/climate_indices.git@39bbf038c77922f8f0a46bb69704d6aace4179f9 # for no-nco deps, expanded range of pdsi
- git+https://github.com/altair-viz/altair_data_server.git # for remote hosting
- git+https://github.com/carbonplan/cmip6-downscaling.git@e8cc4ad89ed3da47a1e46ccc441cdda8eebbc152
14 changes: 3 additions & 11 deletions notebooks/biomass/biomass_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@
"f = [df[inds][\"tmean_mean\"], df[inds][\"ppt_mean\"]]\n",
"(\n",
" plot.xy(x=x, y=y, color=f[0], cmap=\"magma\", xlim=[0, 250], ylim=[0, 600])\n",
" | plot.xy(\n",
" x=x, y=y, color=f[1], cmap=\"viridis\", xlim=[0, 250], ylim=[0, 600]\n",
" )\n",
" | plot.xy(x=x, y=y, color=f[1], cmap=\"viridis\", xlim=[0, 250], ylim=[0, 600])\n",
").resolve_scale(color=\"independent\")"
]
},
Expand Down Expand Up @@ -182,10 +180,7 @@
"xlim = [0, 250]\n",
"ylim = [-200, 700]\n",
"(\n",
" (\n",
" plot.xy(x=x, y=y, xlim=xlim, ylim=ylim)\n",
" + plot.line(x=x, y=model.predict(x, f, [50, 50]))\n",
" )\n",
" (plot.xy(x=x, y=y, xlim=xlim, ylim=ylim) + plot.line(x=x, y=model.predict(x, f, [50, 50])))\n",
" | (\n",
" plot.xy(x=x, y=model.sample(x, f), xlim=xlim, ylim=ylim)\n",
" + plot.line(x=x, y=model.predict(x, f, [50, 50]))\n",
Expand Down Expand Up @@ -222,10 +217,7 @@
"xlim = [0, 250]\n",
"ylim = [-200, 700]\n",
"(\n",
" (\n",
" plot.xy(x=x, y=y, xlim=xlim, ylim=ylim)\n",
" + plot.line(x=x, y=model.predict(x, f, [50, 50]))\n",
" )\n",
" (plot.xy(x=x, y=y, xlim=xlim, ylim=ylim) + plot.line(x=x, y=model.predict(x, f, [50, 50])))\n",
" | (\n",
" plot.xy(x=x, y=model.sample(x, f), xlim=xlim, ylim=ylim)\n",
" + plot.line(x=x, y=model.predict(x, f, [50, 50]))\n",
Expand Down
4 changes: 1 addition & 3 deletions notebooks/drought/drought_results.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
"metadata": {},
"outputs": [],
"source": [
"pf = pd.read_parquet(\n",
" \"/Users/freeman/github/carbonplan/forests/scripts/data/drought.parquet\"\n",
")"
"pf = pd.read_parquet(\"/Users/freeman/github/carbonplan/forests/scripts/data/drought.parquet\")"
]
},
{
Expand Down
20 changes: 5 additions & 15 deletions notebooks/fire/fire_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@
"outputs": [],
"source": [
"mask = load.nlcd(store=\"local\", classes=\"all\", year=2001)\n",
"groups = load.nftd(\n",
" store=\"local\", groups=\"all\", coarsen=coarsen, mask=mask, area_threshold=1500\n",
")"
"groups = load.nftd(store=\"local\", groups=\"all\", coarsen=coarsen, mask=mask, area_threshold=1500)"
]
},
{
Expand All @@ -101,9 +99,7 @@
},
"outputs": [],
"source": [
"climate = load.terraclim(\n",
" store=\"local\", tlim=tlim, coarsen=coarsen, data_vars=data_vars, mask=mask\n",
")"
"climate = load.terraclim(store=\"local\", tlim=tlim, coarsen=coarsen, data_vars=data_vars, mask=mask)"
]
},
{
Expand Down Expand Up @@ -188,9 +184,7 @@
"metadata": {},
"outputs": [],
"source": [
"r = rasterio.open(\n",
" \"/Users/freeman/workdir/carbonplan-data/processed/mtbs/conus/30m/2006.tif\"\n",
")"
"r = rasterio.open(\"/Users/freeman/workdir/carbonplan-data/processed/mtbs/conus/30m/2006.tif\")"
]
},
{
Expand Down Expand Up @@ -303,9 +297,7 @@
"x = mtbs[\"time\"]\n",
"y = mtbs[\"vlf\"].mean([\"x\", \"y\"])\n",
"\n",
"plot.line(\n",
" x=x, y=y, width=900, height=200, color=\"rgb(175,91,92)\", strokeWidth=2\n",
")"
"plot.line(x=x, y=y, width=900, height=200, color=\"rgb(175,91,92)\", strokeWidth=2)"
]
},
{
Expand Down Expand Up @@ -468,9 +460,7 @@
" color=\"rgb(175,91,92)\",\n",
" strokeWidth=2,\n",
" )\n",
" + plot.line(\n",
" x=x, y=y2, width=900, height=200, color=\"rgb(175,91,92)\", strokeWidth=2\n",
" )\n",
" + plot.line(x=x, y=y2, width=900, height=200, color=\"rgb(175,91,92)\", strokeWidth=2)\n",
")"
]
},
Expand Down
Loading