[AstroPy] Plotting .fits data using filters

Didrik Nilsen didrik.nilsen at live.no
Wed Apr 7 20:14:15 EDT 2021


I am doing a research project in Astronomy where I am supposed to analyze three different pictures. I am using several different packages to extract the data from every pixel in every picture. To make sure that my data is reliable I am dividing one picture of one galaxy by another picture of the same galaxy, but the second picture is an error picture. To make sure my data is reliable I am dividing the two arrays by each other to get a ratio in order to plot and calculate the median with proper data. I think I have gotten the median right, but my plots are not. There are far too many plots based on the elements in the ratio array which is 23. Please help me. Here is my code. I can supply more info about the project if needed.
glx_list = os.listdir(r'C:\Users\didri\Documents\Spring2021\PHYS481 Individual Research\H2_Maps-20210201T082125Z-001\H2_Maps')
hello = 0
for i in glx_list:
        image_data_dg = 0
        print(i)
        map_gau = r'C:\Users\didri\Documents\Spring2021\PHYS481 Individual Research\SiVI_Maps-20210201T084648Z-001\SiVI_Maps' + '\\' + i + '\\SiVI\\Spat3\\map_gau.fits'
        map_gau_err = r'C:\Users\didri\Documents\Spring2021\PHYS481 Individual Research\SiVI_Maps-20210201T084648Z-001\SiVI_Maps' + '\\' + i + '\\SiVI\\Spat3\\map_gau_err.fits'
        disp_gau = r'C:\Users\didri\Documents\Spring2021\PHYS481 Individual Research\H2_Maps-20210201T082125Z-001\H2_Maps' + '\\' + i + '\\H2\\Spat3\\disp_gau.fits'
        image_data_dg = fits.open(disp_gau)
        image_data_mg = fits.open(map_gau)
        image_data_err = fits.open(map_gau_err)
        dshape = image_data_mg[0].data.shape
        dshape = np.subtract(dshape, (1, 1))
        y, x = dshape
        data_mg = image_data_mg[0].data[0:x, 0:y].astype('float')
        data_err = image_data_err[0].data[0:x, 0:y].astype('float')
        data_dg = image_data_dg[0].data[0:x, 0:y].astype('float')
        data_mg[data_mg == 0] = 'nan'
        data_err[data_err == 0] = 'nan'
        data_dg[data_dg == 0] = 'nan'
        ratio = np.divide(data_mg[0:x, 0:y], data_err[0:x, 0:y])
        low_snr = (ratio < 2)
        bad_pixel = (ratio == np.nan)
        mask = ~(low_snr & bad_pixel)
        counter1 = 0
        for i in ratio:
                counter2 = 0
                for j in i:
                        if j < 2:
                                data_mg[counter1][counter2] = 'nan'
                                data_dg[counter1][counter2] = 'nan'
                        elif j == 'nan':
                                data_mg[counter1][counter2] = 'nan'
                                data_dg[counter1][counter2] = 'nan'
                counter1 = counter1 + 1
        plt.scatter(data_mg, data_dg)
        plt.xlim(0, .2)
        plt.ylim(0, 500)
        #plt.savefig('plot' + str(hello))
        hello = hello + 1
        plt.show()
        if hello == 1:
                break
        plt.clf()


data_mg = np.ndarray.flatten(data_mg)
data_mg = data_mg[np.logical_not(np.isnan(data_mg))]
data_dg = np.ndarray.flatten(data_dg)
data_dg = data_dg[np.logical_not(np.isnan(data_dg))]

b = np.where(np.array(data_dg > 100))

median = np.median(data_mg[b])
print('Flux median at dispersion > 100 km/s is ' + str(median))
a = np.where(data_dg <= 100)
median1 = np.median(data_mg[a])
print('Flux median at dispersion <= 100 km/s is ' + str(median1))


Best regards,

Didrik Langmoen Nilsen
University of Alaska Anchorage Ski Team
BBA Global Logistics & Supply Chain Managment

C | +1 (907) 301 5507
E | dlnilsen at alaska.edu<mailto:dlnilsen at alaska.edu>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20210408/f3f0b733/attachment-0001.html>


More information about the AstroPy mailing list