Making stars
Table of Contents
Why make stars?
I want to test software I'm developing to determine pointing and disortion information. This requires a realistic star field where the pointing and distortion are known. The only way to get this is to make the star field yourself.
Making the first version
There will be a follow up to this article about adding a point-spread function (PSF) to the star field. But for now, we'll stick with Gaussian stars.
Imports and packages
We only need a few packages for this work: pandas
, numpy
, maptlotlib
, astropy
, and photutils
.
Getting a catalog
To make stars in real positions, we need a catalog. We'll use the Hipparcos catalog.
=
"""Download hipparcos catalog from website.
Parameters
----------
catalog_path : str
path to the Hipparcos catalog
Returns
-------
pd.DataFrame
loaded catalog with selected columns
"""
=
=
= 1000 /
=
return
I recommend saving this as a CSV file and then opening it as needed instead of downloading it every time.
Filtering for relevant stars
There are a lot of stars in this catalog. We may only want to show up to a certain magnitude. Filtering on Pandas dataframes is easy though.
"""Filters to only include stars brighter than a given magnitude
Parameters
----------
catalog : pd.DataFrame
a catalog data frame
dimmest_magnitude : float
the dimmest magnitude to keep
Returns
-------
pd.DataFrame
a catalog with stars dimmer than the `dimmest_magnitude` removed
"""
return
In addition, not all the stars will be visible in our image. A world coordinate system or WCS describes where an image is in the sky. We'll use it to determine the pixel coordinates of each star and then throw away those outside the frame.
"""Using the provided WCS converts the RA/DEC catalog into pixel coordinates
Parameters
----------
catalog : pd.DataFrame
a catalog dataframe
wcs : WCS
the world coordinate system of a given image
image_shape: (int, int)
the shape of the image array associated with the WCS,
used to only consider stars with coordinates in image
mode : str
either "all" or "wcs",
see
<https://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html#astropy.coordinates.SkyCoord.to_pixel>
Returns
-------
np.ndarray
pixel coordinates of stars in catalog that are present in the image
"""
= ,
= ,
, = * * *
=
=
=
return
Making the actual star image
Finally, we can write a straightforward function to make a star field.
It'll use all our other work until now.
We provide it with a wcs
, the dimensions of an image (img_shape
), and the full-width-half-maximum (fwhm
) of our Gaussian PSF for stars.
There are a few other helpful parameters here too.
For example, mag_set
and flux_set
work together to scale the star brightnesses.
If mag_set=0
and flux_set=500_000
then stars with magnitude 0 in the catalo will have a flux value of 500_000
.
All other magnitude stars are scaled accordingly.
We also sometimes want to add noise. We can currently add a Gaussian noise with mean of noise_mean
and standard deviation of noise_std
.
If these parameters are set to None, then no noise is added.
Finally, we can control the dimmest_magnitude
to limit what magnitude stars are shown. The more stars you show, the slower the code is.
= / 2.355
=
=
=
=
=
=
=
= *
= *
= *
=
=
# we only add noise if it's specified
+=
return ,
So let's run it!
= 1
=
=
= / 2 - 0.5, / 2 - 0.5
= 0, 0
= 0.0225, 0.0225
= ,
= ,
And visualize it.
=
,
Note that our WCS here is rather simple, but we could have added a distortion model too and that would've been applied.
Be careful to set wcs_mode=all
in that case.
Conlusions
This makes a rather convincing initial star field. But it lacks shot noise, a complex PSF, and other effects that we may want to simulate.
In the follow up to this article, we'll add those.