Example #1
0
             cmap='hsv',
             s=50,
             linewidth=0)
 plt.tight_layout()
 plt.xlim(min(latlongs[:, 0]) - .0005, max(latlongs[:, 0]) + .0005)
 plt.ylim(min(latlongs[:, 1]) - .0005, max(latlongs[:, 1]) + .0005)
 plt.savefig(PATH + PLACE + "_MAP_" + str(CLST_METHOD) + "_" + namePad +
             ".png",
             dpi=500)
 plt.close()
 ###########################################################################
 # Export distance matrix
 ###########################################################################
 distPath = PATH + PLACE + "_DST_" + str(
     CLST_METHOD) + "_" + namePad + ".csv"
 distMat = monet.calculateDistanceMatrix(latlongs,
                                         distFun=vn.vincenty) * 1000
 # np.savetxt(distPath, distMat.astype(int), fmt='%i', delimiter=',')
 # heat = sns.heatmap(distMat, annot=False)
 # heat.get_figure().savefig(PATH + PLACE + "DIST.png", dpi=500)
 ###########################################################################
 # Export migration matrix
 ###########################################################################
 migrPath = PATH + PLACE + "_MIG_" + str(
     CLST_METHOD) + "_" + namePad + ".csv"
 zeroInflation = pow(lifeStayProb, adultMortality)
 migrMat = monet.zeroInflatedExponentialMigrationKernel(
     distMat, params=monet.AEDES_EXP_PARAMS, zeroInflation=zeroInflation)
 monet.testMarkovMatrix(migrMat)
 # np.savetxt(migrPath, migrMat, delimiter=',')
 # heat = sns.heatmap(migrMat, annot=False)
 # heat.get_figure().savefig(PATH + "MIGR.png", dpi=500)
Example #2
0
def genSingle(n, zeroInflation, landscapeProb, mskMat):
    (lo, hi, n) = (0, 1225, n)
    # ############################################################################
    # Mosquito biological behaviour
    # ############################################################################
    # mskMat: This matrix defines how probable is for a mosquito to
    #   move from one life stage to the next (and, as a consequence, from a site
    #   type to the next).
    # ############################################################################
    passMkvtest = aux.testMarkovMat(mskMat)
    passMkvtest

    # ############################################################################
    # Landscape
    # ############################################################################
    # Creates a random landscape (x,y coordinates) and calculates the distances
    #   matrix.
    # ############################################################################
    #landscape = land.genUniformLandscape(lo, hi, n)
    landscape = land.genLineLandscape(lo, hi, n)
    distMat = monet.calculateDistanceMatrix(landscape)

    # ############################################################################
    # Migration
    # ############################################################################
    # Converts the distances matrix into a proper migration matrix by applying
    #   the kernel, and normalizing it.
    # ############################################################################
    migrMat = monet.zeroInflatedExponentialMigrationKernel(
        distMat,
        params=monet.AEDES_EXP_PARAMS,
        zeroInflation=0.75
    )
    aux.testMarkovMat(migrMat)

    # ############################################################################
    # Point types
    # ############################################################################
    # Assigns classes types to the points in the landscape (this routine will
    #   fail if there's few points with respect to the dimension of the point
    #   types)
    # ############################################################################
    # pointClasses = bts.genURandLandscapeClasses(len(mskMat), n)
    pointClasses = bts.genMRandLanscapeClasses(len(mskMat), n, landscapeProb)
    # plot the assigned landscape
    landscape_plot = sns.scatterplot(
            [i[0] for i in landscape],
            [i[1] for i in landscape],
            hue=pointClasses, legend=False
        )
    clandMskMat = bts.calcClandMskMat(pointClasses, mskMat)
    # print(clandMskMat)

    # ############################################################################
    # Full network
    # ############################################################################
    # Applies the point-types mask to the migration matrix, and normalizes it
    #   to take into account the movement due to life-stage, and distance.
    # ############################################################################
    network = mntw.normalizeMskMgrMat(migrMat, clandMskMat)
    return (network, pointClasses, landscape_plot)
Example #3
0
mskMat = [
        [0.20, 0.80, 0.00],
        [0.10, 0.75, 0.15],
        [0.80, 0.00, 0.20]
    ]
passMkvtest = aux.testMarkovMat(mskMat)

# ############################################################################
# Landscape
# ############################################################################
# Creates a random landscape (x,y coordinates) and calculates the distances
#   matrix.
# ############################################################################
# landscape = land.genURandLandscape(lo, hi, ptsNum)
landscape = land.genLineLandscape(lo, hi, ptsNum)
distMat = monet.calculateDistanceMatrix(landscape)
print(distMat)
sns.heatmap(distMat, annot=True)

# ############################################################################
# Migration
# ############################################################################
# Converts the distances matrix into a proper migration matrix by applying
#   the kernel, and normalizing it.
# ############################################################################
migrMat = monet.zeroInflatedExponentialMigrationKernel(
    distMat,
    params=monet.AEDES_EXP_PARAMS,
    zeroInflation=zeroInflation
)
aux.testMarkovMat(migrMat)
Example #4
0
        r = rand.uniform(radius[0], radius[1])
        # calculating coordinates
        x = r * math.cos(alpha) + center[0]
        y = r * math.sin(alpha) + center[1]
        coords.append([x, y])
else:
    coords = list(zip(rand.uniform(*xRan, POINTS), rand.uniform(*yRan,
                                                                POINTS)))
# Point-types -----------------------------------------------------------------
pNum = len(list(coords))
pTypes = np.array(PTYPE_PROB).cumsum().searchsorted(np.random.sample(pNum))
sites = np.asarray(coords)
###############################################################################
# Generate matrices
###############################################################################
dist = monet.calculateDistanceMatrix(coords)
tau = monet.zeroInflatedExponentialMigrationKernel(dist,
                                                   aux.MKERN,
                                                   zeroInflation=0.75)
###############################################################################
# Generate masking matrix
###############################################################################
itr = list(range(len(coords)))
msk = np.zeros((pNum, pNum))
r = 0
for r in itr:
    for c in itr:
        msk[r, c] = PTS_TMAT[pTypes[r], pTypes[c]]
tauN = normalize(msk * tau, axis=1, norm='l1')
###############################################################################
# Check matrices