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

[pre-commit.ci] pre-commit autoupdate #12

Open
wants to merge 2 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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -12,7 +12,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.5.6"
rev: "v0.9.4"
hooks:
# Run the linter.
- id: ruff
Expand All @@ -23,7 +23,7 @@ repos:


- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
rev: 1.9.1
hooks:
- id: nbqa-mypy
args: ["--ignore-missing-imports"]
Expand Down
139 changes: 88 additions & 51 deletions cesm2/process/create-scepter-clim_ts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@
"outputs": [],
"source": [
"# --- function to generate synthetic runoff and soil moisture data\n",
"def generate_synthetic_data(mean_runoff, mean_soil_moisture, \n",
" peak_day_runoff, peak_day_soil_moisture, \n",
" amplitude_runoff=1, amplitude_soil_moisture=1, \n",
" years=1):\n",
"def generate_synthetic_data(\n",
" mean_runoff,\n",
" mean_soil_moisture,\n",
" peak_day_runoff,\n",
" peak_day_soil_moisture,\n",
" amplitude_runoff=1,\n",
" amplitude_soil_moisture=1,\n",
" years=1,\n",
"):\n",
" \"\"\"\n",
" Generate synthetic monthly runoff and soil moisture data using sine waves.\n",
"\n",
Expand All @@ -124,35 +129,47 @@
"\n",
" # Generate timestamps for each month\n",
" dates = pd.date_range(start=\"1/1/2000\", periods=12 * years, freq=\"MS\")\n",
" \n",
"\n",
" # Calculate day of year for each month midpoint\n",
" day_of_year = dates.day_of_year + (dates.days_in_month / 2 - 0.5)\n",
"\n",
" # Normalize day of year to radians\n",
" radians_runoff = (2 * np.pi * (day_of_year - peak_day_runoff) / days_per_year)\n",
" radians_soil_moisture = (2 * np.pi * (day_of_year - peak_day_soil_moisture) / days_per_year)\n",
" radians_runoff = 2 * np.pi * (day_of_year - peak_day_runoff) / days_per_year\n",
" radians_soil_moisture = (\n",
" 2 * np.pi * (day_of_year - peak_day_soil_moisture) / days_per_year\n",
" )\n",
"\n",
" # Calculate sine wave values\n",
" runoff = mean_runoff + amplitude_runoff * np.sin(radians_runoff)\n",
" soil_moisture = mean_soil_moisture + amplitude_soil_moisture * np.sin(radians_soil_moisture)\n",
" \n",
" soil_moisture = mean_soil_moisture + amplitude_soil_moisture * np.sin(\n",
" radians_soil_moisture\n",
" )\n",
"\n",
" # Create DataFrame\n",
" df = pd.DataFrame({\n",
" \"year\": dates.year,\n",
" \"month\": dates.month,\n",
" \"runoff\": runoff,\n",
" \"soil_moisture\": soil_moisture\n",
" })\n",
" \n",
" df = pd.DataFrame(\n",
" {\n",
" \"year\": dates.year,\n",
" \"month\": dates.month,\n",
" \"runoff\": runoff,\n",
" \"soil_moisture\": soil_moisture,\n",
" }\n",
" )\n",
"\n",
" return df\n",
"\n",
"\n",
"# same as above, but can pass it a 1d array of times as the fraction through the year\n",
"def generate_synthetic_data_v2(mean_runoff, mean_soil_moisture, \n",
" peak_day_runoff, peak_day_soil_moisture, \n",
" amplitude_runoff=1, amplitude_soil_moisture=1, \n",
" time_fraction=None):\n",
"def generate_synthetic_data_v2(\n",
" mean_runoff,\n",
" mean_soil_moisture,\n",
" peak_day_runoff,\n",
" peak_day_soil_moisture,\n",
" amplitude_runoff=1,\n",
" amplitude_soil_moisture=1,\n",
" time_fraction=None,\n",
"):\n",
" \"\"\"\n",
" Generate synthetic runoff and soil moisture data using sine waves, \n",
" Generate synthetic runoff and soil moisture data using sine waves,\n",
" supporting a 1D array of time as the fraction of the year.\n",
"\n",
" Parameters:\n",
Expand All @@ -178,22 +195,27 @@
" day_of_year = (time_fraction % 1) * days_per_year\n",
"\n",
" # Normalize day of year to radians\n",
" radians_runoff = (2 * np.pi * (day_of_year - peak_day_runoff) / days_per_year)\n",
" radians_soil_moisture = (2 * np.pi * (day_of_year - peak_day_soil_moisture) / days_per_year)\n",
" radians_runoff = 2 * np.pi * (day_of_year - peak_day_runoff) / days_per_year\n",
" radians_soil_moisture = (\n",
" 2 * np.pi * (day_of_year - peak_day_soil_moisture) / days_per_year\n",
" )\n",
"\n",
" # Calculate sine wave values\n",
" runoff = mean_runoff + amplitude_runoff * np.sin(radians_runoff)\n",
" soil_moisture = mean_soil_moisture + amplitude_soil_moisture * np.sin(radians_soil_moisture)\n",
" soil_moisture = mean_soil_moisture + amplitude_soil_moisture * np.sin(\n",
" radians_soil_moisture\n",
" )\n",
"\n",
" # Create DataFrame\n",
" df = pd.DataFrame({\n",
" \"time_fraction\": time_fraction,\n",
" \"runoff\": runoff,\n",
" \"soil_moisture\": soil_moisture\n",
" })\n",
" \n",
" return df\n",
"\n"
" df = pd.DataFrame(\n",
" {\n",
" \"time_fraction\": time_fraction,\n",
" \"runoff\": runoff,\n",
" \"soil_moisture\": soil_moisture,\n",
" }\n",
" )\n",
"\n",
" return df"
]
},
{
Expand Down Expand Up @@ -227,12 +249,12 @@
"# (must be the same length as len(df))\n",
"mean_runoff = [12, 12, 12, 12]\n",
"mean_soil_moisture = [165, 165, 165, 165]\n",
"peak_day_runoff = [300,15,200,100]\n",
"peak_day_soil_moisture = [300,15,200,100]\n",
"amplitude_runoff = [11,1,1,11]\n",
"peak_day_runoff = [300, 15, 200, 100]\n",
"peak_day_soil_moisture = [300, 15, 200, 100]\n",
"amplitude_runoff = [11, 1, 1, 11]\n",
"amplitude_soil_moisture = [160, 10, 10, 160]\n",
"\n",
"# print(df.head())\n"
"# print(df.head())"
]
},
{
Expand Down Expand Up @@ -300,15 +322,24 @@
" # set yr array and save\n",
" yrs = np.linspace(yrmin, yrmax, nsteps)\n",
" # update arr if synthetic\n",
" if use_synthetic_hydroclim and thisvar.colname_var in ['moisture(mm/m)', 'runoff(mm/month)']:\n",
" if use_synthetic_hydroclim and thisvar.colname_var in [\n",
" \"moisture(mm/m)\",\n",
" \"runoff(mm/month)\",\n",
" ]:\n",
" # get climate ts\n",
" dfclim_tmp = generate_synthetic_data_v2(mean_runoff[idx], mean_soil_moisture[idx], \n",
" peak_day_runoff[idx], peak_day_soil_moisture[idx], amplitude_runoff[idx], \n",
" amplitude_soil_moisture[idx], time_fraction=yrs)\n",
" dfclim_tmp = generate_synthetic_data_v2(\n",
" mean_runoff[idx],\n",
" mean_soil_moisture[idx],\n",
" peak_day_runoff[idx],\n",
" peak_day_soil_moisture[idx],\n",
" amplitude_runoff[idx],\n",
" amplitude_soil_moisture[idx],\n",
" time_fraction=yrs,\n",
" )\n",
" if thisvar.colname_var == \"moisture(mm/m)\":\n",
" tmp = np.array(dfclim_tmp['soil_moisture'])\n",
" elif thisvar.colname_var == 'runoff(mm/month)':\n",
" tmp = np.array(dfclim_tmp['runoff'])\n",
" tmp = np.array(dfclim_tmp[\"soil_moisture\"])\n",
" elif thisvar.colname_var == \"runoff(mm/month)\":\n",
" tmp = np.array(dfclim_tmp[\"runoff\"])\n",
" # name the output directory\n",
" if lterm_mean:\n",
" yr_string = (\n",
Expand Down Expand Up @@ -518,9 +549,9 @@
"source": [
"mean_runoff = [12, 12, 12, 12]\n",
"mean_soil_moisture = [165, 165, 165, 165]\n",
"peak_day_runoff = [300,15,200,100]\n",
"peak_day_soil_moisture = [300,15,200,100]\n",
"amplitude_runoff = [11,1,1,11]\n",
"peak_day_runoff = [300, 15, 200, 100]\n",
"peak_day_soil_moisture = [300, 15, 200, 100]\n",
"amplitude_runoff = [11, 1, 1, 11]\n",
"amplitude_soil_moisture = [160, 10, 10, 160]"
]
},
Expand All @@ -546,12 +577,18 @@
" max_yr = 1\n",
" pvar = \"soil_moisture\"\n",
"\n",
" dfclim_tmp = generate_synthetic_data_v2(mean_runoff[idx], mean_soil_moisture[idx], \n",
" peak_day_runoff[idx], peak_day_soil_moisture[idx], amplitude_runoff[idx], \n",
" amplitude_soil_moisture[idx], time_fraction=yrs)\n",
" dfclim_tmp = generate_synthetic_data_v2(\n",
" mean_runoff[idx],\n",
" mean_soil_moisture[idx],\n",
" peak_day_runoff[idx],\n",
" peak_day_soil_moisture[idx],\n",
" amplitude_runoff[idx],\n",
" amplitude_soil_moisture[idx],\n",
" time_fraction=yrs,\n",
" )\n",
"\n",
" dfc = dfclim_tmp[dfclim_tmp['time_fraction'] < max_yr]\n",
" plt.plot(dfc['time_fraction'], dfc[pvar], label=idx)\n",
" dfc = dfclim_tmp[dfclim_tmp[\"time_fraction\"] < max_yr]\n",
" plt.plot(dfc[\"time_fraction\"], dfc[pvar], label=idx)\n",
" plt.legend()"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@
- cc vs gbas
- counterfactual cc (~0.4 ton/ha/yr)
- same, low upstream emissions for each

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ Emissions:
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 200.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 200.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ Emissions:
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 200.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 500.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 200.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Emissions (calcite):
barge_km: 100.0
barge_diesel_km: 0
Efactor_org: MRO

Loading