Skip to content

Instantly share code, notes, and snippets.

@RickMohr
Created December 8, 2016 21:41
Show Gist options
  • Select an option

  • Save RickMohr/7dfc90b2682a9a07b893c4fe359533ef to your computer and use it in GitHub Desktop.

Select an option

Save RickMohr/7dfc90b2682a9a07b893c4fe359533ef to your computer and use it in GitHub Desktop.
from modeling.run_model.GrowthModelUrbanTreeDatabase import _growth_data
results = []
for itree_region, otm_codes in _growth_data.iteritems():
for otm_code, (age_to_dbh, min_age, max_age) in otm_codes.iteritems():
key = '{} {}'.format(itree_region, otm_code)
min_dbh = age_to_dbh(min_age)
min_dbh1 = age_to_dbh(min_age + 1)
early_growth_rate = min_dbh1 - min_dbh
# Reduce max_age if function is not monotonically increasing
age = min_age + 1
prev_dbh = min_dbh
max_age_was_wrong = ''
while age < max_age:
dbh = age_to_dbh(age)
if dbh < prev_dbh:
max_age = age - 1
max_age_was_wrong = 'Y'
break
prev_dbh = dbh
age += 1
max_dbh = age_to_dbh(max_age)
results.append({
'key': key,
'min_age': min_age,
'max_age': max_age,
'max_age_was_wrong': max_age_was_wrong,
'min_dbh': min_dbh,
'max_dbh': max_dbh,
'early_growth_rate': early_growth_rate,
})
results = sorted(results, key=lambda item: item['key'].lower())
print('key,min_age,max_age,max_age_was_wrong,min_dbh,max_dbh,early_growth_rate')
for item in results:
out = "%s,%s,%s,%s,%s,%s,%s" % (
item['key'],
item['min_age'],
item['max_age'],
item['max_age_was_wrong'],
item['min_dbh'],
item['max_dbh'],
item['early_growth_rate'])
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment