Habe ein kleines Problem. Für eine Auswertesoftware möchte ich aus 2 gegebenen Datenarrays (angle & b im code unten) Ringe "schneiden" und diesen dann zu einem 2D-Array umfunktionieren. Sprich: Die Werte innerhalb dieses Ringes interessieren mich, die anderen müssen weg. Spalten bzw. zeilenweises Ausschneiden ist kein Problem, aber mit dem Ring habe ich momentan ein Problem. Bis zur 4letzten Zeile ist das Programm vielleicht nicht sonderlich schön, funktioniert aber....
Code: Alles auswählen
##Import of all important packages
import numpy as np
import pylab as pl
import scipy
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from numpy.fft import fft2, ifft2
from scipy.fftpack import fftshift
from pylab import xcorr
import random
## Defining the Image Porperties
pixelnr = 128.0
pixelnr_b = pixelnr / 2 + 1
alpha = np.pi / 4
sin_alpha = np.sin(alpha)
cos_alpha = np.cos(alpha)
N = np.arange(1, 11)
numrods = 50
## Defining the pixelarray and the pixelmatrix for the image
pixelarray = np.arange(1 - pixelnr_b, pixelnr + 1 - (pixelnr / 2))
d = np.array(np.arange(1, pixelnr + 2), ndmin=2).T.repeat(len(pixelarray), 1)
## Building an image of a rod with edge length x & y
x = 0.5
y = 4
for n in N:
for i in range(numrods):
p = (random.random())
pixels = ((((d - pixelnr_b) * np.cos(np.pi/p) + (np.sin(np.pi/p) * pixelarray)) / x)**2+ (((-d + pixelnr_b) * np.sin(np.pi/p) + (np.cos(np.pi/p)))))
## Defining the q-value on the detector
q = (pl.sqrt((d-pixelnr/2)**2 + (pixelarray)**2))
## Defining the angle on the detector image
angle3 = pl.arctan(((pixelarray)/(d-pixelnr/2)))
angle2 = np.where((d-pixelnr/2)<0, (pl.arctan((pixelarray+np.pi/2)/(d-pixelnr/2+np.pi/2)))+np.pi/2, angle3)
angle4 = np.where((d-pixelnr/2)>0, (pl.arctan((pixelarray-2+(3*np.pi/2))/(d-3-pixelnr/2+(3*np.pi/2))))+3*np.pi/2, angle2)
angle4[62:64,1:63] = np.pi
angle4[62:64,63:128] = 0
angle = angle4*180/np.pi
## improving the contrast of the image
rod1 = np.where(pixels<150,0,pixels)
rod = np.where(pixels>= 150,1,rod1)
a = fft2(rod)
if i==1:
c = a
if i>1:
c = c + a
b = abs(fftshift((c)))
selectedQ = 20
k = np.arange(selectedQ, selectedQ+1)
step= int(np.max(q)/100)+1
## Selecting the q-values of the ring
if q in range(selectedQ, selectedQ+step):
l1 = np.ravel(b)
g1 = np.ravel(angle)