Skip to content
Snippets Groups Projects
Commit 93404028 authored by Jakobsen, Mads Bregenholt's avatar Jakobsen, Mads Bregenholt
Browse files

made bash file to setup and install venv with fastxpcs package

parent ff01d207
No related branches found
No related tags found
No related merge requests found
env/
testing/output.mp4
testing/abc.png
*.o
*.so
*.pyc
*.egg-info
fastXPCS/fastXPCS/cython/welford.c
fastXPCS/fastXPCS/cython/fxpcs_sparse.c
fastXPCS/fastXPCS/cython/dense.c
File moved
File moved
File moved
python3 -m pip install --upgrade pip
python3 -m venv env
source env/bin/activate
python3 -m pip install Cython
python3 -m pip install numpy
python3 -m pip install scipy
python3 -m pip install matplotlib
python3 -m pip install pillow
cd fastXPCS
#python setup.py build_ext --inplace
#python setup.py develop
python3 -m pip install -e .
cd ..
source env/bin/activate
python3 testing/test.py
\ No newline at end of file
......@@ -6,6 +6,9 @@ import numpy as np
import matplotlib.pyplot as pl
# get some data
from fastXPCS.algos import TTCdata, do_sparse_train
from fastXPCS.fxpcs_sparse import sparsify, sparsify2
from PIL import Image
dataShape = (352, 512, 128)
photonEnergy = 13.3 # in ADU
......@@ -44,6 +47,7 @@ def getDummyData(shape, chanceOfPhotonPerPixel = 0.01, correlationPerBunch=0.5,
p=[q**0, q**1, q**2, q**3, q**4, q**5, q**6]/np.sum([q**0, q**1, q**2, q**3, q**4, q**5, q**6])),(shape[1], shape[2]))
def evolveImageFrom(image, c=correlationPerBunch):
print(c)
randMask = np.reshape(np.random.choice(
[0, 1],
size=numPixelPrImage,
......@@ -54,7 +58,8 @@ def getDummyData(shape, chanceOfPhotonPerPixel = 0.01, correlationPerBunch=0.5,
data[0,:,:] = np.reshape(getRandomImage(), (shape[1], shape[2]))
for pulseNr in range(1,dataShape[0]):
data[pulseNr, :, :] = evolveImageFrom(data[pulseNr-1,:,:])
correlationPerBunch += (1-correlationPerBunch)*0.001
data[pulseNr, :, :] = evolveImageFrom(data[pulseNr-1,:,:], correlationPerBunch )
# if we do not returned photnoized data, then add a gaussian random variable
if (~photonized ):
......@@ -70,15 +75,26 @@ data = getDummyData(
correlationPerBunch=0.5,
photonized=False,
energy=photonEnergy,
sigma=0.12)
sigma=0.012)
# function to do the xpcs the same way as in the xpcs class
# in the xpcs calng addon
# input : -image, the data set, e.g., data
def xpcs(image, energy):
image /= 1
_ttcdata = TTCdata()
_ttcdata.user_q_mask = np.ones(shape=(1,512,128)).astype(np.uint32)
_ttcdata.current_cal_mask = np.ones(shape=(1,512,128)).astype(np.uint32)
print(_ttcdata.user_q_mask.shape)
print(_ttcdata.current_cal_mask.shape)
_sparse_array = None
_cal_mask = None
image /= energy
image = np.around(image)
print(f" {np.sum(image==0)} num zeros {image.size}")
flat_image_shape = image.reshape(image.shape[0], -1).shape
print(flat_image_shape)
......@@ -90,24 +106,59 @@ def xpcs(image, energy):
# lit, i.e., have a value larger than 0
lit_mask = reshaped_data > 0
# get the values of those that have a value larger than 0
lit_pixels = reshaped_data[lit_mask].astype(np.uint32)
lit_pixels = np.ascontiguousarray(reshaped_data[lit_mask].astype(np.uint32))
# get the indices of those that
lit_indices = indices[:, lit_mask].astype(np.uint32)
lit_indices = np.ascontiguousarray(indices[:, lit_mask].astype(np.uint32))
# initalize a sparse array
sparse_array = np.empty_like(lit_pixels, dtype=np.uint32)
# call function to fill sparse array with indices and value via bitpacking
# call function to fill sparse array with indices and value via bitpacking (from Felix)
# note that aliaksandr.leonau@xfel.eu mentioned that using build in sparse capabilities from
# numpy/scipy gives comparable or better results.
sparsify2(lit_pixels, lit_indices, sparse_array)
image = image.astype(np.int32)
## sparsifing again?
start = time.time()
sparse_ref = sparsify(image.reshape(image.shape[0], -1))
_ttcdata.current_image = image.astype(np.int32)
_ttcdata.current_image_sparse = sparse_ref
_ttcdata.current_cal_mask = np.isnan(image)
do_sparse_train(_ttcdata)
elapsed = time.time() - start
print(f"TTCF in: {elapsed:.3f}")
output = _ttcdata.ttc_on.astype(np.int32)
return output
# do stuff
t = time.time()
xpcs(data, photonEnergy)
out = xpcs(data, photonEnergy)
elapsed = time.time() - t
print(f"elapsed {elapsed}")
print(out.shape)
print(np.min(out))
print(np.max(out))
def plot(data):
data = data.astype(np.float32)
cmap = pl.get_cmap('viridis')
norm = pl.Normalize(data.min(), data.max())
print("blib")
# The norm instance scales data to a 0-1 range, cmap makes it RGB
rgb = cmap(norm(data))
print("blub")
# MPL uses a 0-1 float RGB representation, so we'll scale to 0-255
rgb = (255 * rgb).astype(np.uint8)
print("blab")
Image.fromarray(rgb).save('test.png')
plot(out[0,:,:])
# cpu code with python from xpcs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment