Dec-17-2017, 04:16 PM
Hi - I'm just starting to programme in Python, so this may be a very simple error - I'm trying to write code which will monitor astroimages and as they are taken, calculate the running average of the image to improve the signal to noise.
To do that, I'm going to need to update my image every few minutes, but am struggling to work out how to update the image using PyPlot. Code below. If I take out the block=False on the second call, then the updated figure is shown - but I need to do this with block=False so that I can automatically add new images.
Thank you for any advice,
Colin
#!/usr/bin/env python2 # Import basic files for reading and manipulating fits data import numpy as np import math import matplotlib import matplotlib.pyplot as plt from astropy.io import fits import time hdul = fits.open('M31s.fit') image_data = hdul[0].data image_real = image_data * 1.0/(2**16) image_min = np.amin(image_real) image_max = np.amax(image_real) image_real -= image_min image_real /= (image_max-image_min) image_med = np.median(image_real) beta = math.sinh(0.25*10)/image_med image_real *= beta image_real = np.arcsinh(image_real) print image_min, image_max, image_med, beta image_real_min = np.amin(image_real) image_real_max = np.amax(image_real) image_real_med = np.median(image_real) print image_real_min, image_real_max, image_real_med fig = plt.imshow(image_real, cmap='gray') plt.colorbar() plt.draw() plt.show(block=False) time.sleep(5) image_real /= math.asinh(beta) image_real_min = np.amin(image_real) image_real_max = np.amax(image_real) image_real_med = np.median(image_real) print image_real_min, image_real_max, image_real_med image_neg = 1-image_real fig.set_data(image_neg) plt.show(block=False) time.sleep(10)