# enforce a minimum individual density of 2
    indices = mete.which([site_data[i][2] > 2 for i in range(0, len(site_data))])
    site_data = [site_data[i] for i in indices]

    site_data = np.array(site_data)

    Amin = min(site_data[:, 0])
    Amax = max(site_data[:, 0])
    S0 = int(max(site_data[:, 1]))
    N0 = int(max(site_data[:, 2]))

    sar_down_iterative = []
    for i in range(0, nperm):
        p = mete.exp(-mete.get_beta(S0, N0))
        n0_rvs = mete.trunc_logser_rvs(p, N0, S0)
        sar_down_iterative.append(mete.downscale_sar_fixed_abu(Amax, n0_rvs, Amin))

    Avals = sar_down_iterative[0][0][:]
    len_A = len(Avals)

    out = np.empty((nperm * len_A, 2))

    for j in range(0, nperm):
        for i in range(0, 2):
            start = j * len_A
            stop = start + len_A
            out[start:stop, i] = sar_down_iterative[j][i]

    filename = "./sar/" + shrt_name + "_mete_sar_middle_ground.txt"
import sys
import os
from math import exp

import mete

if len(sys.argv) > 1:
    S0 = int(sys.argv[1])
    N0 = int(sys.argv[2])

if os.path.exists('../demo') is False:
    os.mkdir('../demo')

beta = mete.get_beta(S0, N0)

n0 = mete.trunc_logser_rvs(exp(-beta), N0, S0)
n0 = list(n0)
n0 = [int(x) for x in n0]
n0.sort(reverse=True)

rad = mete.get_mete_rad(S0, N0)[0]

Amax = 4
Amin = 1

recur = mete.downscale_sar(Amax, S0, N0, Amin)
recur_obsSAD = mete.downscale_sar_fixed_abu(Amax, n0, Amin)

Avals = recur_obsSAD[0][ : ]

nonrecur = mete.sar_noniterative(Avals, Amax, S0, N0, 'precise')