These are chat archives for BernieenJos/weetikveel

8th
Oct 2014
iambernie
@iambernie
Oct 08 2014 12:27
asdfasdf
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:27
yoyoyo
Ik probeer maar ff wat hoor

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows = 512
phases = fits.open('phases.fits')
a = np.zeros(NoRows2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows
2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1. # Array with the triple-star system

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows = 512
phases = fits.open('phases.fits')
a = np.zeros(NoRows2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows
2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1. # Array with the triple-star system

iambernie
@iambernie
Oct 08 2014 12:33
zet ff 3 enkele aanhalingstekens aan het begin en aan het eind van je blok code.
Dan geef je het opmaak mee.
Dus bijv:
oh wacht, het zijn geen enkele aanhalingstekens maar, accentjes. (links van de 1-knop)
```
``````def telop(a, b):
return a+b``````
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:35

```import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows = 512
phases = fits.open('phases.fits')
a = np.zeros(NoRows2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows
2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1. # Array with the triple-star system

kut
``````import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows  = 512
phases    = fits.open('phases.fits')
a = np.zeros(NoRows**2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows**2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1.                                    # Array with the triple-star system``````
yeeeees
iambernie
@iambernie
Oct 08 2014 12:36
Kijk
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:36
``````import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows  = 512
phases    = fits.open('phases.fits')
a = np.zeros(NoRows**2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows**2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1.                                    # Array with the triple-star system

for r in range(0, 1):                                                        # Fills the empty array a with complex phase values
phi_r = np.mod(phases[0].data[r], 2*np.pi)
for p in range(0, NoRows):
for q in range(0, NoRows):
if((p - NoRows/2)**2 + (q - NoRows/2)**2 < (NoRows/4)**2):
phi_r_pq = phi_r[p][q]
a[p,q] = m.exp(1j*phi_r_pq)
FT  = np.fft.fft2(a)
PSF = abs(FT)**2
PSF = np.fft.fftshift(PSF)                                                # This is the ultimate PSF
#    plt.imshow(PSF, cmap = cm.hsv)
#    plt.show()
c = scipy.signal.fftconvolve(b, PSF)                                        # Convolved array of the star system and the PSF
#    plt.imshow(c, cmap = cm.hsv)
#    plt.show()``````
iambernie
@iambernie
Oct 08 2014 12:36
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:36
Dit is het hele programma
Oh 1 correctie:
``````import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows  = 512
phases    = fits.open('phases.fits')
a = np.zeros(NoRows**2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows**2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1.                                    # Array with the triple-star system

for r in range(0, 100):                                                        # Fills the empty array a with complex phase values
phi_r = np.mod(phases[0].data[r], 2*np.pi)
for p in range(0, NoRows):
for q in range(0, NoRows):
if((p - NoRows/2)**2 + (q - NoRows/2)**2 < (NoRows/4)**2):
phi_r_pq = phi_r[p][q]
a[p,q] = m.exp(1j*phi_r_pq)
FT  = np.fft.fft2(a)
PSF = abs(FT)**2
PSF = np.fft.fftshift(PSF)                                                # This is the ultimate PSF
#    plt.imshow(PSF, cmap = cm.hsv)
#    plt.show()
c = scipy.signal.fftconvolve(b, PSF)                                        # Convolved array of the star system and the PSF
#    plt.imshow(c, cmap = cm.hsv)
#    plt.show()``````
(Range moest van 0 tot 100 zijn)
(Rechts staat nog commentaar)
Wat ik wil is het gemiddelde van alle 100 c'tjes
iambernie
@iambernie
Oct 08 2014 12:42
Ok, eerst ff wat simpelere voorbeelden:

```>>> tevullenlijst = []

waarden = [1,3,6,8]
for w in waarden:
... tevullenlijst.append(w**2)
...
print(tevullenlijst)
[1, 9, 36, 64]

```

oops
``````
>>> tevullenlijst = []
>>> waarden = [1,3,6,8]
>>> for w in waarden:
...     tevullenlijst.append(w**2)
...
>>> print(tevullenlijst)
[1, 9, 36, 64]``````
Dit kan je volgen.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:44
ja
iambernie
@iambernie
Oct 08 2014 12:45
Meer gebruikelijk is echter:
``````>>> kwadraten = [ w**2 for w in waarden]
[1, 9, 36, 64]``````
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:45
``````>>> list = [1,2]
>>> list
[1, 2]
>>> list.append(3)
>>> list
[1, 2, 3]
>>>``````
hmm
even kijken
jjjjja
ja
iambernie
@iambernie
Oct 08 2014 12:47
De laatste manier heet ook wel "list comprehension" en is zeer gebruikelijk in python.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:47
oke
iambernie
@iambernie
Oct 08 2014 12:48

In list comprehension mag je ook condities gebruiken, dus bijvoorbeeld:

``````>>> [i**2 for i in range(10) if i%2 == 0]
[0, 4, 16, 36, 64]``````

Ook te volgen neem ik aan.

JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:50
ja
iambernie
@iambernie
Oct 08 2014 12:52
``````>>> def even_oneven(i):
...     if i%2 == 0:
...         return "even"
...     else:
...         return "oneven"
...
>>> [even_oneven(i) for i in range(10)]
['even', 'oneven', 'even', 'oneven', 'even', 'oneven', 'even', 'oneven', 'even', 'oneven']``````
om maar even nog een voorbeeld te geven.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:52
haha
ja
iambernie
@iambernie
Oct 08 2014 12:52
Ok, nu een vb dat iets dichter in de buurt ligt van jouw probleem.
Stel ik heb een lijst van numpy arrays:
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:54
oke! Werkt dit?
``````c = scipy.signal.fftconvolve(b, PSF)                                        # Convolved array of the star system and the PSF
convolveList = c
convolvelist.append(c)``````
iambernie
@iambernie
Oct 08 2014 12:55
Dus bv zoiets:
``````>>> a = numpy.array( [1,2,3] )
>>> a
array([1, 2, 3])
>>> [a,a,a]
[array([1, 2, 3]), array([1, 2, 3]), array([1, 2, 3])]
>>> lijstvannumpyarrays = [a,a,a]``````
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:56
ja, oke
iambernie
@iambernie
Oct 08 2014 12:57
En ik wil van ieder array het gemiddelde weten en dit opslaan in een lijst.
Dat kan ik dat bijv alsvolgt doen:
``````>>> [arr.mean() for arr in lijstvannumpyarrays]
[2.0, 2.0, 2.0]``````
JosvanderSpek
@JosvanderSpek
Oct 08 2014 12:59
hmm
arr.mean()?
oh ja tuurlijk
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:04
``````>>> array
array([1, 2, 3])
>>> [array,array,array]
[array([1, 2, 3]), array([1, 2, 3]), array([1, 2, 3])]
>>> lijstvanarrays = [array,array,array]
>>> lijstvanarrays
[array([1, 2, 3]), array([1, 2, 3]), array([1, 2, 3])]
>>> mean = [arr.mean() for arr in lijstvanarrays]
>>> mean
[2.0, 2.0, 2.0]
>>>``````
iambernie
@iambernie
Oct 08 2014 13:08
Ok, nu gaan we een voorbeeld maken dat nog iets dichter ligt in de buurt van jouw probleem.
Stel dat ik vier (2,2) arrays op deze manier construeer:
``````>>> a = numpy.random.randint(0,10, size=(4,2,2))
>>> print(a)
[[[7 9]
[4 1]]

[[6 2]
[2 5]]

[[6 6]
[6 0]]

[[0 8]
[4 2]]]
>>> a.shape
(4, 2, 2)``````
iambernie
@iambernie
Oct 08 2014 13:17
en ik wil voor iedere 2bij2 array het gemiddelde weten, dan kan ik bijv dit doen:
``````>>> [i.mean() for i in a]
[5.25, 3.75, 4.5, 3.5]``````
waarbij i steeds een 2bij2 array is.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:19
jaja
iambernie
@iambernie
Oct 08 2014 13:24
Ik vind zelf echter het volgende wat consistenter:
``````>>> numpy.mean(a, axis=(1,2))
array([ 5.25,  3.75,  4.5 ,  3.5 ])``````
Het is consistenter in de zin, dat je weer een numpy array terugkrijgt.
Dit is dus equivalent aan:
``````>>> numpy.array([i.mean() for i in a])
array([ 5.25,  3.75,  4.5 ,  3.5 ])``````
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:25
hoppata
``````>>> a = np.random.randint(0,50, size = (3,2,2))
>>> a
array([[[ 1,  4],
[36, 42]],

[[20, 40],
[36, 16]],

[[39, 42],
[ 0,  0]]])
>>> m = [i.mean() for i in a]
>>> m
[20.75, 28.0, 20.25]
>>>``````
iambernie
@iambernie
Oct 08 2014 13:25
Duidelijk wat er gebeurt?
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:26
wat doet axis(1,2)?
iambernie
@iambernie
Oct 08 2014 13:27
Daarmee geef je aan over welke assen je het gemiddelde wilt nemen. Want je kunt het gemiddelde ook over andere richtingen nemen.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:27
ehmm
maar wat ik gedaan heb? Dat is toch gewoon het gemiddelde van het hele vierkant?
ja tuurlijk
oke
``````>>> n = np.mean(a, axis = (1,2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/fromnumeric.py", line 2374, in mean
return mean(axis, dtype, out)
TypeError: an integer is required
>>>``````
ik krijg deze fout
iambernie
@iambernie
Oct 08 2014 13:31
Probeer deze ook even te volgen:
``````>>> a
array([[[7, 9],
[4, 1]],

[[6, 2],
[2, 5]],

[[6, 6],
[6, 0]],

[[0, 8],
[4, 2]]])
>>> numpy.mean(a, axis=0)
array([[ 4.75,  6.25],
[ 4.  ,  2.  ]])``````
Stel je hebt 4 flatfields genomen en je wilt daar 1 master flatfield van maken door over iedere pixel het gemiddelde te nemen. Dan zou je dat dus zo (zoals hierboven) doen.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:35
nee
ik snap het niet
ik dacht dat 4.75 het gemiddelde van het bovenste vierkant zou zijn
iambernie
@iambernie
Oct 08 2014 13:36
Ok. Geef me ff 5 minuten om een tekening te maken en in te scannen.
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:36
dat ik het niet
is*
iambernie
@iambernie
Oct 08 2014 13:38
a.shape
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:40
Calculate the average image as well as the average auto-correlation of the 100 images simulating the triple-star
system as seen through the atmosphere. Compare the two results and explain the average auto-correlation in
terms of the real image of the triple-star system.
``````import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows  = 512
phases    = fits.open('phases.fits')
a = np.zeros(NoRows**2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows**2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1.                                    # Array with the triple-star system
convolveList = []

for r in range(0, 5):                                                        # Fills the empty array a with complex phase values
phi_r = np.mod(phases[0].data[r], 2*np.pi)
for p in range(0, NoRows):
for q in range(0, NoRows):
if((p - NoRows/2)**2 + (q - NoRows/2)**2 < (NoRows/4)**2):
phi_r_pq = phi_r[p][q]
a[p,q] = m.exp(1j*phi_r_pq)
FT  = np.fft.fft2(a)
PSF = abs(FT)**2
PSF = np.fft.fftshift(PSF)                                                # This is the ultimate PSF
#    plt.imshow(PSF, cmap = cm.hsv)
#    plt.show()
!!!    c = scipy.signal.fftconvolve(b, PSF)                                        # Convolved array of the star system and the PSF
!!!    convolveList = c
!!!    convolvelist.append(c)
#    plt.imshow(c, cmap = cm.hsv)
#    plt.show()``````
JosvanderSpek
@JosvanderSpek
Oct 08 2014 13:50
alright!

```import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows = 512
phases = fits.open('phases.fits')
a = np.zeros(NoRows2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows
2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1. # Array with the triple-star system
convolveList = []

for r in range(0, 5): # Fills the empty array a with complex phase values
phi_r = np.mod(phases[0].data[r], 2np.pi)
for p in range(0, NoRows):
for q in range(0, NoRows):
if((p - NoRows/2)2 + (q - NoRows/2)2 < (NoRows/4)**2):
phi_r_pq = phi_r[p][q]
a[p,q] = m.exp(1j
phi_r_pq)
FT = np.fft.fft2(a)
PSF = abs(FT)**2
PSF = np.fft.fftshift(PSF) # This is the ultimate PSF

# plt.show()

``````c = scipy.signal.fftconvolve(b, PSF)                                        # Convolved array of the star system and the PSF
convolveList.append(c)                                                    # List of b convolved with 100 different PSFs``````

mean = np.mean(convolveList, axis = 0)
print mean

# plt.show()

wow
``````import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
import pyfits as fits
import cmath as m
import scipy
from scipy import signal

NoRows  = 512
phases    = fits.open('phases.fits')
a = np.zeros(NoRows**2, dtype = np.cfloat).reshape(NoRows, NoRows)
b = np.zeros(NoRows**2).reshape(NoRows, NoRows)
b[273,269] = b[276,267] = b[267, 261] = 1.                                    # Array with the triple-star system
convolveList = []

for r in range(0, 5):                                                        # Fills the empty array a with complex phase values
phi_r = np.mod(phases[0].data[r], 2*np.pi)
for p in range(0, NoRows):
for q in range(0, NoRows):
if((p - NoRows/2)**2 + (q - NoRows/2)**2 < (NoRows/4)**2):
phi_r_pq = phi_r[p][q]
a[p,q] = m.exp(1j*phi_r_pq)
FT  = np.fft.fft2(a)
PSF = abs(FT)**2
PSF = np.fft.fftshift(PSF)                                                # This is the ultimate PSF
#    plt.imshow(PSF, cmap = cm.hsv)
#    plt.show()
c = scipy.signal.fftconvolve(b, PSF)                                        # Convolved array of the star system and the PSF
convolveList.append(c)                                                    # List of b convolved with 100 different PSFs

mean = np.mean(convolveList, axis = 0)
print mean

#    plt.imshow(c, cmap = cm.hsv)
#    plt.show()``````
dit lijkt me al goed eigenlijk :)
iambernie
@iambernie
Oct 08 2014 14:00
Maar om een triple-star system te simuleren heb je gewoon 3 pixels op 1 gezet...?
JosvanderSpek
@JosvanderSpek
Oct 08 2014 14:39
ja
zooooo je wordt wel gaar van dat programmeren man... haha
iambernie
@iambernie
Oct 08 2014 14:58
haha