def main(Ca=None):

    par = 1500.0
    Ci = Ca * 0.7
    Rd = None
    Tleaf = 25.
    deg2kelvin = 273.15
    Tleaf += deg2kelvin
    Eaj = 27900.0
    Eav = 69900.0
    deltaSj = 619.0
    deltaSv = 634.0
    Hdv = 200000.0
    Hdj = 200000.0
    r25 = 2.0
    Q10 = 2.0
    N_c = 0.015
    N_e = 0.015
    N_p = 0.10
    #===== Medlyn paper ====#
    alpha = 0.425  # (-)
    g_m = 0.4  # mol m-2 s-1 bar-1 ie mol m-2 s-1 at 1 atm
    K_cat = 24.0  # mmol CO2 mol-1 Rubisco-1
    K_s = 1.25E-04  # mol N s umol-1
    #=======================#

    P = PhotosynthesisModel(peaked_Jmax=True,
                            peaked_Vcmax=True,
                            alpha=alpha,
                            g_m=g_m,
                            K_cat=K_cat,
                            K_s=K_s)
    O = OptimiseNitrogenAllocation(model=P)

    Jm_store = np.zeros(0)
    Vm_store = np.zeros(0)
    leaf_temp = np.linspace(5, 30, 10)
    Npools_store = np.zeros((len(leaf_temp), 4))
    for i, Tleaf in enumerate(leaf_temp):

        initial_guess = np.array([N_c, N_e])
        # ===== OPTIMIZE parameter set ===== #
        result = O.main(fit_params=initial_guess,
                        par=par,
                        Rd=Rd,
                        Ci=Ci,
                        N_p=N_p,
                        Tleaf=Tleaf + deg2kelvin,
                        Tref=25.0,
                        Eaj=Eaj,
                        Eav=Eav,
                        deltaSj=deltaSj,
                        deltaSv=deltaSv,
                        r25=r25,
                        Q10=Q10,
                        Hdv=Hdv,
                        Hdj=Hdj)

        # retrieve all fitted N pools
        (N_c, N_e, N_r, N_s) = P.N_pool_store
        Npools_store[i] = N_c, N_e, N_r, N_s

        fitted_x0 = np.array([N_c, N_e])

        (An, Anc, Anj, Jmax25,
         Vcmax25) = P.calc_photosynthesis(N_pools=fitted_x0,
                                          par=par,
                                          Ci=Ci,
                                          Rd=Rd,
                                          N_p=N_p,
                                          Tleaf=Tleaf + deg2kelvin,
                                          Tref=25.0,
                                          Eaj=Eaj,
                                          Eav=Eav,
                                          deltaSj=deltaSj,
                                          deltaSv=deltaSv,
                                          r25=r25,
                                          Q10=Q10,
                                          Hdv=Hdv,
                                          Hdj=Hdj)

        Jm_store = np.append(Jm_store, Jmax25)
        Vm_store = np.append(Vm_store, Vcmax25)
    jv_ratio = Jm_store / Vm_store

    return jv_ratio, leaf_temp, Npools_store
  deltaSv = 650.0
  Hdv = 200000.0
  Hdj = 200000.0
  r25 = None
  Q10 = None
  N_c = 0.015
  N_e = 0.015
  #===== Medlyn paper ====#
  alpha = 0.425   # (-)
  g_m = 0.4       # mol m-2 s-1 bar-1 ie mol m-2 s-1 at 1 atm
  K_cat = 24.0    # mmol CO2 mol-1 Rubisco-1
  K_s = 1.25E-04  # mol N s umol-1
  #=======================#
 
  
  P = PhotosynthesisModel(peaked_Jmax=True, peaked_Vcmax=True, 
                               alpha=alpha, g_m=g_m, K_cat=K_cat, K_s=K_s)
  O = OptimiseNitrogenAllocation(model=P)
  
  
  
  N_c_store = []
  N_e_store = []
  N_r_store = []
  N_s_store = []
  
  An_store = []
  for N_p in np.linspace(0.05, 0.15, 10):
      x0 = np.array([N_c, N_e])
      # ===== OPTIMIZE parameter set ===== # 
      result = O.main(fit_params=x0, par=par, Rd=Rd, Ci=Ci, 
                         N_p=N_p, Tleaf=Tleaf, Tref=25.0, Eaj=Eaj, Eav=Eav, 
    Hdv = 200000.0
    Hdj = 200000.0
    r25 = None
    Q10 = None
    N_c = 0.015
    N_e = 0.015
    #===== Medlyn paper ====#
    alpha = 0.425  # (-)
    g_m = 0.4  # mol m-2 s-1 bar-1 ie mol m-2 s-1 at 1 atm
    K_cat = 24.0  # mmol CO2 mol-1 Rubisco-1
    K_s = 1.25E-04  # mol N s umol-1
    #=======================#

    P = PhotosynthesisModel(peaked_Jmax=True,
                            peaked_Vcmax=True,
                            alpha=alpha,
                            g_m=g_m,
                            K_cat=K_cat,
                            K_s=K_s)
    O = OptimiseNitrogenAllocation(model=P)

    N_c_store = []
    N_e_store = []
    N_r_store = []
    N_s_store = []

    An_store = []
    for N_p in np.linspace(0.05, 0.15, 10):
        x0 = np.array([N_c, N_e])
        # ===== OPTIMIZE parameter set ===== #
        result = O.main(fit_params=x0,
                        par=par,
def main(Ca=None):
    
    par = 1500.0
    Ci = Ca * 0.7
    Rd = None
    Tleaf = 25.
    deg2kelvin = 273.15
    Tleaf += deg2kelvin
    Eaj = 27900.0
    Eav = 69900.0
    deltaSj = 619.0
    deltaSv = 634.0
    Hdv = 200000.0
    Hdj = 200000.0
    r25 = 2.0
    Q10 = 2.0
    N_c = 0.015
    N_e = 0.015
    N_p = 0.10
    #===== Medlyn paper ====#
    alpha = 0.425   # (-)
    g_m = 0.4       # mol m-2 s-1 bar-1 ie mol m-2 s-1 at 1 atm
    K_cat = 24.0    # mmol CO2 mol-1 Rubisco-1
    K_s = 1.25E-04  # mol N s umol-1
    #=======================#
   
    
    P = PhotosynthesisModel(peaked_Jmax=True, peaked_Vcmax=True, 
                                 alpha=alpha, g_m=g_m, K_cat=K_cat, K_s=K_s)
    O = OptimiseNitrogenAllocation(model=P)
    
    
    
    Jm_store = np.zeros(0)
    Vm_store = np.zeros(0)
    leaf_temp = np.linspace(5, 30, 10)
    Npools_store = np.zeros((len(leaf_temp),4))
    for i, Tleaf in enumerate(leaf_temp):
        
        initial_guess = np.array([N_c, N_e])
        # ===== OPTIMIZE parameter set ===== # 
        result = O.main(fit_params=initial_guess, par=par, Rd=Rd, Ci=Ci, 
                        N_p=N_p, Tleaf=Tleaf+deg2kelvin, Tref=25.0, Eaj=Eaj, 
                        Eav=Eav, deltaSj=deltaSj, deltaSv=deltaSv, r25=r25, 
                        Q10=Q10, Hdv=Hdv, Hdj=Hdj)
    
    
        # retrieve all fitted N pools
        (N_c, N_e, N_r, N_s) = P.N_pool_store
        Npools_store[i] = N_c, N_e, N_r, N_s
        
        fitted_x0 = np.array([N_c, N_e])
        
        (An, Anc, Anj, 
         Jmax25, 
         Vcmax25) = P.calc_photosynthesis(N_pools=fitted_x0, par=par, Ci=Ci, 
                                               Rd=Rd, N_p=N_p, 
                                               Tleaf=Tleaf+deg2kelvin, 
                                               Tref=25.0, Eaj=Eaj, Eav=Eav, 
                                               deltaSj=deltaSj, deltaSv=deltaSv, 
                                               r25=r25, Q10=Q10, Hdv=Hdv, 
                                               Hdj=Hdj)
        
        Jm_store = np.append(Jm_store, Jmax25)
        Vm_store = np.append(Vm_store, Vcmax25)
    jv_ratio = Jm_store / Vm_store

    return jv_ratio, leaf_temp, Npools_store