malcolmSQ
feat: add mortality inputs for years 1-10 and subsequent, update both species, and fix UI assignment
8d81017 | import gradio as gr | |
| def get_model_inputs(config): | |
| spA = config["species"][0] | |
| spB = config["species"][1] | |
| # Species A | |
| planting_density_A = gr.Number(value=spA['planting_density'], label=f"{spA['name']} Planting Density (trees/ha)") | |
| r0_dbh_A = gr.Number(value=spA['declining_increment']['dbh']['r0'], label=f"{spA['name']} r0 (DBH, cm/yr)") | |
| tm_dbh_A = gr.Number(value=spA['declining_increment']['dbh']['T_m'], label=f"{spA['name']} Tm (DBH, yrs)") | |
| r0_height_A = gr.Number(value=spA['declining_increment']['height']['r0'], label=f"{spA['name']} r0 (Height, m/yr)") | |
| tm_height_A = gr.Number(value=spA['declining_increment']['height']['T_m'], label=f"{spA['name']} Tm (Height, yrs)") | |
| # Species B | |
| planting_density_B = gr.Number(value=spB['planting_density'], label=f"{spB['name']} Planting Density (trees/ha)") | |
| r0_dbh_B = gr.Number(value=spB['declining_increment']['dbh']['r0'], label=f"{spB['name']} r0 (DBH, cm/yr)") | |
| tm_dbh_B = gr.Number(value=spB['declining_increment']['dbh']['T_m'], label=f"{spB['name']} Tm (DBH, yrs)") | |
| r0_height_B = gr.Number(value=spB['declining_increment']['height']['r0'], label=f"{spB['name']} r0 (Height, m/yr)") | |
| tm_height_B = gr.Number(value=spB['declining_increment']['height']['T_m'], label=f"{spB['name']} Tm (Height, yrs)") | |
| # Mortality (one set, mirrored, years 1-10 + subsequent) | |
| mort_inputs = {} | |
| mort_defaults = [] | |
| for yr in range(1, 11): | |
| key = f"year_{yr}" | |
| mort_inputs[key] = gr.Number(value=spA['mortality_rates'][key], label=f"Year {yr} Mortality (%)") | |
| mort_defaults.append(spA['mortality_rates'][key]) | |
| mort_inputs['subsequent'] = gr.Number(value=spA['mortality_rates']['subsequent'], label="Subsequent Years Mortality (%)") | |
| mort_defaults.append(spA['mortality_rates']['subsequent']) | |
| # Project/Carbon | |
| project_duration = gr.Number(value=config['project']['duration_years'], label="Project Duration (years)") | |
| buffer_pct = gr.Number(value=config['carbon']['buffer_percentage'], label="Buffer %") | |
| soil_carbon = gr.Number(value=config['carbon']['soil_carbon_per_ha_per_year'], label="Soil Carbon per ha per year (tCO2)") | |
| # Return as dict and list of default values (for initial call) | |
| components = { | |
| 'planting_density_A': planting_density_A, | |
| 'r0_dbh_A': r0_dbh_A, | |
| 'tm_dbh_A': tm_dbh_A, | |
| 'r0_height_A': r0_height_A, | |
| 'tm_height_A': tm_height_A, | |
| 'planting_density_B': planting_density_B, | |
| 'r0_dbh_B': r0_dbh_B, | |
| 'tm_dbh_B': tm_dbh_B, | |
| 'r0_height_B': r0_height_B, | |
| 'tm_height_B': tm_height_B, | |
| **mort_inputs, | |
| 'project_duration': project_duration, | |
| 'buffer_pct': buffer_pct, | |
| 'soil_carbon': soil_carbon | |
| } | |
| defaults = [ | |
| spA['planting_density'], spA['declining_increment']['dbh']['r0'], spA['declining_increment']['dbh']['T_m'], | |
| spA['declining_increment']['height']['r0'], spA['declining_increment']['height']['T_m'], | |
| spB['planting_density'], spB['declining_increment']['dbh']['r0'], spB['declining_increment']['dbh']['T_m'], | |
| spB['declining_increment']['height']['r0'], spB['declining_increment']['height']['T_m'], | |
| *mort_defaults, | |
| config['project']['duration_years'], config['carbon']['buffer_percentage'], config['carbon']['soil_carbon_per_ha_per_year'] | |
| ] | |
| return components, defaults |