Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulated images break with latest photutils #378

Open
stephtdouglas opened this issue Nov 1, 2024 · 2 comments · May be fixed by #383
Open

Simulated images break with latest photutils #378

stephtdouglas opened this issue Nov 1, 2024 · 2 comments · May be fixed by #383

Comments

@stephtdouglas
Copy link

Hello! I'm using the CCD Guide in my class this semester, and we've run into an issue with image_sim.py. The Guide is written using an older version of photutils, and the latest release no longer includes two of the functions used for simulating fake stars: photutils.datasets.make_random_gaussians_table and photutils.datasets.make_gaussian_sources_image. They've been superceded by the more general functions photutils.datasets.make_model_image and photutils.datasets.make_model_params.

For most of us with relatively recent anaconda installations (using Python 3.12), conda could not find an environment solution to install the necessary packages with an older version of photutils. Two of my students had older anaconda installations that used Python 3.9, and it installed the older photutils (and compatible packages) just fine. For some reason conda would not find a solution on our newer installations even if we requested Python 3.9, so that doesn't seem to be a universal solution.

I found a workaround for using the latest photutils with an updated version of image_sim.py. I'm pasting in my updated lines below for reference. I can make a pull request if desired, but since this version won't work with an older version of photutils, I didn't want to do so just yet.

The import line (currently lines 6-7) becomes

from photutils.datasets import make_model_image, make_model_params

And then the new stars function becomes

def stars(image, number, max_counts=10000, gain=1, fwhm=4):
    """
    Add some stars to the image.
    """
    # Most of the code below is a direct copy/paste from
    # https://photutils.readthedocs.io/en/stable/_modules/photutils/datasets/make.html#make_100gaussians_image

    model = Gaussian2D()

    flux_range = [max_counts / 10, max_counts]

    y_max, x_max = image.shape
    xmean_range = [0.1 * x_max, 0.9 * x_max]
    ymean_range = [0.1 * y_max, 0.9 * y_max]
    xstddev_range = [fwhm, fwhm]
    ystddev_range = [fwhm, fwhm]
    params = make_model_params(image.shape, number, x_name='x_mean',
                               y_name='y_mean', 
                               amplitude=flux_range, x_stddev=xstddev_range,
                               y_stddev=ystddev_range, theta=(0, 2*np.pi),
                               x_mean=xmean_range,y_mean=ymean_range)


    star_im = make_model_image(image.shape, model, params,
                            x_name='x_mean', y_name='y_mean')

    return star_im

So now params is the output of make_model_params, and is passed directly into make_model_image rather than the intermediate step of the sources table.

@mwcraig
Copy link
Member

mwcraig commented Nov 3, 2024

Hi @stephtdouglas, thanks for reporting this. If you could open a PR that would be great. I'll add a bit of code to the PR that ensures it works with older or new versions of stellarphot.

If you don't have a chance before then, I can open the PR on Tuesday of this week.

@stephtdouglas
Copy link
Author

Hi @mwcraig - unfortunately I didn't end up having time to open a PR today, sorry! I did also want to note that this issue affects notebook 01-03-Construction..., which duplicates the stars function.

@mwcraig mwcraig linked a pull request Nov 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants