Python Q&A (Not plotting related) - UMKCgeg/Wiki GitHub Wiki
Welcome to the Python Question/Answer page. The goal of this is to document the questions that you encountered while coding in python and cracked it by doing some research. However, owing to the amount of questions that might be filled here, i am excluding plotting related question in here and they will be addressed in another page.
Please do look at some other independent pages on wiki at (link)
1. How can i find cosmological calculations?/ How can i use Cosmology Calculator? :
A detailed explanation on how to import and use Cosmology calculator can be found at Cosmology Calculator
2. How can i find Angular separation between two positions in the sky? :
Please visit this link for explanation and example code for finding Angular separation at Angular Separation
3. How do i write my data as a CSV file :
As a remainder, CSV stands for "comma-separated-file". If you have an array of data that you computed and want to write it as a csv file for further use, the go to this page Write CSV File
Note : Please google "Astropy Tables" and you can find some useful information on ascii format or sometimes custom formatting.
4. How do i parse/load my data from a CSV file :
Okay ! you might have a csv file and might be wondering how the heck do i load it into python and use it for other stuff. So please go this page for further details CSV parsing/handling
5. How do i find binomial error for simple number fractions? :
If you are finding fractions in your study and want to find binomial confidence limits to you results (error bars). Then look at this article Binomial errors
6. How do i load a fits image using python? :
Whatever you need is located in this section Load Fits image
7. How do i cut small postage stamps from a large image using python? :
While there is a full routine with other features, the simple task of cutting images can be done by following this link Cutouts
8. Is there anyway that i can do automatic stretch when displaying images in python? : Yes (assuming that you want to do this on a postage stamp). The concept is as follows :
- First you take the cutout of a galaxy you need
- Make a flattened version of the 2D array cutout image data using
cutout.data.flat
- Use this data to run a sigma clipping process to clip out ridiculously high or values in the image
- Use the upper and lower limits to stretch the image.
This can be automated on every image, works pretty good.
sigma_clipped=ro.removeoutliers(np.array(to_be_clipped_data),nsigma=7, remove='both', center='median', niter=np.Inf, retind=False, verbose=False)
# see sigma clipping code description for extra details.
# max and min of the sigma_clipped will tell you the min and max stretch, you have to play around a little bit to finalize the stretch. This is where it gets semi automated.
Note : Please look for my page on sigma clipping process code Sigma Clipping
9. Can i create custom markers (like in ds9) in python? :
Yes you can!
Coming soon
10. If i have a bunch of images, can i create a collage? :
Coming soon
11. I have images of a galaxies and i want to inspect them. Is there a GUI interface at which i can just look at and click yes or no/ that asks for multiple options? :
Yes !
Coming soon
12. What is a montecarlo simulation, how to implement preliminarily in python? :
Coming soon
13. I just have a list of RA and DECs, how do i find edges in my data :
Coming soon
14. I have just list of RA and DECs in a survey, how do i find area that they cover in the sky?
Coming soon
15. What are different types of stretches that can be done? How to implement them :
Coming soon
16. How do i convert RA and DEC at a given location of the image to pixel coordinates? :
You can use the following implementation to convert the sky coordinates to pixel coordinates. It requires WCS object. Follow this link World2pix
17. How do i use/load the header information of the image :
Here is how you can achieve this Header and WCS
18. How do write a 2D array to an image with header information? :
Follow this link to write your data into a fits file Writing FITS file.
19. Example code for sigma clipping process :
You can find the sigma clipping example code at this page Sigma Clipping