Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump Probability with Greyscale Images #24

Merged
merged 11 commits into from
Jun 15, 2023
Prev Previous commit
Next Next commit
Add hit frequency script
  • Loading branch information
TomTranter committed Oct 10, 2019
commit 32a86ab7d97614863ecd8a80cdfb426d404868ff
57 changes: 57 additions & 0 deletions frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 10 08:34:14 2019

@author: Tom
"""

import porespy as ps
import pytrax as pt
import numpy as np
import matplotlib.pyplot as plt
import scipy.ndimage as spim
plt.close('all')
if __name__ == '__main__':
im = ps.generators.blobs(shape=[1000, 1000], porosity=0.7).astype(np.int)
dt = spim.distance_transform_edt(im)
grey = dt.copy()/dt.max()
grey = np.pad(grey, 1, mode='constant', constant_values=0)
# Number of time steps and walkers
num_t = 10000
num_w = 10000
stride = 1

rw = pt.RandomWalk(grey, seed=False)
rw.run(num_t, num_w, same_start=False, stride=stride, num_proc=12)
# Plot mean square displacement
rw.plot_msd()
rw.plot_walk_2d()

print('Calculating hit frequency')
coords = rw.real_coords + 1
freq = np.zeros_like(grey)
if len(im.shape) == 2:
for t in range(coords.shape[0]):
x = coords[t, :, 0]
y = coords[t, :, 1]
freq[x, y] += 1
else:
for t in range(coords.shape[0]):
x = coords[t, :, 0]
y = coords[t, :, 1]
z = coords[t, :, 2]
freq[x, y, z] += 1

some_hits = freq[freq > 0]
frange = np.unique(some_hits)
plt.figure()
plt.hist(some_hits, bins=100)
log_freq = np.log(freq)
log_freq[freq == 0] = np.nan
print(frange.min(), frange.max(), log_freq[freq > 0].min(), log_freq[freq > 0].max())
plt.figure()
plt.imshow(grey > 0, cmap='gist_gray')
plt.imshow(log_freq)
plt.colorbar()