<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Exercise 3
We're going to switch gears a little and talk about the astrophysical part of Astrophysical Machine Learning. This exercise will have you examine two different forms of data. The first is an actual image of the sky, and the second a catalog of sources (galaxies).
PART I
Step1:  Now the image is just a numpy array (matrix) that can be indexed like any other array. The np.flipup function ("flip up-down") was used so that when you display the array it will have the same orientation as when you look at the fits image with DS9. Once you read in the image, apply each filter to the image and display the image. To display, you will need to use the matplotlib module. For example, to display the image above, you could use
<ASSISTANT_TASK:>
Python Code:
from astropy.io import fits as fits
fitsimage=fits.open('filename.fits')
image=np.flipud(fitsimage[0].data)
Explanation: Exercise 3
We're going to switch gears a little and talk about the astrophysical part of Astrophysical Machine Learning. This exercise will have you examine two different forms of data. The first is an actual image of the sky, and the second a catalog of sources (galaxies).
PART I: Astronomical images (and catalogs for the that matter) are most often stored in FITS format, which stands for Flexible Image Transport System. There are several programs for opening and examining FITS images. Probably the easiest one to install would be the SAOImage DS9 Astronomical Data Visualization Application. I recommend installing DS9 on your system.   For this part of the exercise, download this image of a region of the sky (near the Coma cluster). For this, you can use the SkyView virtual observatory page. Go to the page and enter "coma cluster" in the “Coordinates or Source” field, then under the Optical:DSS: section select the "DSS1 Red" and press submit. This should open another page which has an image that looks like this:
Download the FITS file associated with the image (it should say “FITS” below the image) and save it in your working python directory. For the following exercise, you will need to have the Astopy package installed.
MEDIAN, MEAN, MAX AND MIN: A common way to manipulate an image in order to highlight features that might not be obvious at first glance, is to modify the pixel values by applying a filter-function to the image. The way these filter-functions are applied is to replace the value of each pixel by another value that is related in some way to the values of surrounding pixels. For example, a $maxFilter()$ function might replace each pixel value by the maximum pixel value in a 3×3 or 5×5 box surrounding the pixel (the pixel itself is also included). A minFilter() would do the same thing, except replace each pixel by the minimum value in the box. For this part of the exercise, you must:
A) Start a python script labeled image_filters.py. This script should contain four functions for computing a $medianFilter()$, $meanFilter()$, $maxFilter()$, and $minFilter()$ of an input image. For now, make the filter size 5×5 pixels, and ignore the edge of the image where the filter would run over the edge.
B) After the functions, read in the FITS file that you got above into an array. This can be done by using astropy like so:
End of explanation
import matplotlib.pyplot as plt
plt.imshow(image)
plt.show()
Explanation: Now the image is just a numpy array (matrix) that can be indexed like any other array. The np.flipup function ("flip up-down") was used so that when you display the array it will have the same orientation as when you look at the fits image with DS9. Once you read in the image, apply each filter to the image and display the image. To display, you will need to use the matplotlib module. For example, to display the image above, you could use:
End of explanation
<END_TASK>