-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
1 changed file
with
261 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,261 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "5b7ca85b-758d-4e5f-a5e4-06b0a1cb2166", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys \n", | ||
"sys.path.append(\"..\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "8dc9a65b-3aec-4a81-b1e7-f942a32d307f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"from ppe_tools import Ensemble,Member,ParamInfo\n", | ||
"from ppe_tools.utils import get_default, parse_val\n", | ||
"import xarray as xr\n", | ||
"import os\n", | ||
"import pandas as pd\n", | ||
"import glob" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "509ccc48-5091-4d70-8526-64e6318ba5be", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"## download the google spreadsheet\n", | ||
"data_url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQs413GtLXtHVDCqEPgAwn4BbDjoWmV7uFqOAWH4mgpxXoVfN6ijnJdhyRgLkV-n2eU-sSQush4CzYU/pub?output=csv'\n", | ||
"cmd = 'curl -L '+data_url+' > sept28.csv' # need to add -L option to force redirects\n", | ||
"os.system(cmd)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "e27c4dee-85fa-41c8-b8b4-e3c431bdca6b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"csvfile = 'sept28.csv'\n", | ||
"data = pd.read_csv(csvfile,header=0,skiprows=[1]) # modify read_csv to account for header spanning 2 rows" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "f83ef2ca-3c42-48bf-b6d8-d7364a52b528", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"462" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"pdir = '/glade/scratch/djk2120/PPEn11/paramfiles/'\n", | ||
"last_oaat = sorted(glob.glob(pdir+'*OAAT*'))[-1]\n", | ||
"nextnum = int(last_oaat.split('OAAT')[1].split('.')[0])+1\n", | ||
"nextnum" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "b9bf492a-8fef-4456-984d-5fd723805775", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#create dict for the new parameters\n", | ||
"oaats = {}\n", | ||
"names = ['flnr','dbh','leaf_mr_vcm','fnitr']\n", | ||
"for name in names:\n", | ||
" \n", | ||
" #access data from csv\n", | ||
" ix = data['name']==name\n", | ||
" minval = data['min'][ix].values[0]\n", | ||
" maxval = data['max'][ix].values[0]\n", | ||
" pftmin = data['pft_mins'][ix].values[0]\n", | ||
" pftmax = data['pft_maxs'][ix].values[0]\n", | ||
" thisloc = data['location'][ix].values[0]\n", | ||
"\n", | ||
" #format the minimum\n", | ||
" needs_pft = (minval=='pft')\n", | ||
" if needs_pft:\n", | ||
" thismin = np.fromstring(pftmin, dtype='float', sep=',')\n", | ||
" elif 'percent' in minval:\n", | ||
" thismin = minval\n", | ||
" else:\n", | ||
" thismin = np.array(float(minval))\n", | ||
"\n", | ||
" #format the maximum\n", | ||
" needs_pft = (maxval=='pft')\n", | ||
" if needs_pft:\n", | ||
" thismax = np.fromstring(pftmax, dtype='float', sep=',')\n", | ||
" elif 'percent' in maxval:\n", | ||
" thismax = maxval\n", | ||
" else:\n", | ||
" thismax = np.array(float(maxval))\n", | ||
"\n", | ||
" #save in dictionary\n", | ||
" oaats[name]={'min':thismin,'max':thismax,'loc':thisloc}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "a60d365d-b87c-40d6-ab44-7fab5ca9817c", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'flnr': {'min': '20percent', 'max': '20percent', 'loc': 'P'},\n", | ||
" 'dbh': {'min': array([0. , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 , 0.1 ,\n", | ||
" 0.05 , 0.05 , 0.05 , 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008]),\n", | ||
" 'max': array([0. , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 ,\n", | ||
" 0.1 , 0.1 , 0.1 , 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008,\n", | ||
" 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008]),\n", | ||
" 'loc': 'P'},\n", | ||
" 'leaf_mr_vcm': {'min': '20percent', 'max': '20percent', 'loc': 'N'},\n", | ||
" 'fnitr': {'min': array(0.8), 'max': array(1.), 'loc': 'P'}}" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"oaats" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "f70c6f71-29ab-448f-a168-c2b312aed186", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#instantiate the Ensemble object\n", | ||
"basefile = '/glade/p/cesm/cseg/inputdata/lnd/clm2/paramdata/ctsm51_params.c210507.nc'\n", | ||
"pdir = '/glade/scratch/djk2120/PPEn11/paramfiles/'\n", | ||
"ndir = '/glade/scratch/djk2120/PPEn11/namelist_mods/'\n", | ||
"x = Ensemble(basefile,pdir,ndir)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "6332513e-c8e4-4a50-865a-fc1141ca3521", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#add the new OAATS\n", | ||
"prefix = 'OAAT'\n", | ||
"x.add_oaats(oaats,prefix,nextnum,skipBFB=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"id": "171f64ff-0c95-497c-9e72-161b77535e02", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#the bfb test is not correctly catching fnitr-max\n", | ||
"# removing it manually here\n", | ||
"# the issue is that it has a 0 for bare-ground, so I'll need to edit the bfb test to ignore bareground\n", | ||
"x.remove_member(x.members[-1])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"id": "8e67801c-3f66-480b-a08d-5c2724bcefd9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"csvfile='/glade/scratch/djk2120/PPEn11/extras_for_sp.csv'\n", | ||
"x.write(csvfile=csvfile)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 60, | ||
"id": "cb6539a5-fcf8-4ecd-b3ff-8389fe61029c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9283d3cf-c368-4f40-9fe8-fb9f2078e624", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python [conda env:miniconda3-lens-py]", | ||
"language": "python", | ||
"name": "conda-env-miniconda3-lens-py-py" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |