pysersic / pysersic

Bayesian fitting of Sersic profiles to galaxy images accelerated with jax
MIT License
23 stars 1 forks source link

Autoprior: numpy.float64' object has no attribute 'to' #54

Closed ke27whal closed 5 months ago

ke27whal commented 5 months ago

Hi all,

I'm trying to use pysersic to fit a sersic profile to synthetic data. I have unitless 2D numpy arrays for the image, mask, and sig files, and I am using a psf generated from WebbPSF for my PSF file.

`from pysersic.results import plot_image from pysersic import check_input_data

######### Image array is sersic_prof2d_convolved_mock ######### Sig array is rms_image ######### PSF array is rms_image,psf[0].data

mask2 = sersic_prof2d_convolved_mock < 0 # All True mask with shape = np.shape(sersic_prof2d_convolved_mock)

fig, ax = plot_image(sersic_prof2d_convolved_mock,mask2,rms_image,psf[0].data)

check_input_data(data=sersic_prof2d_convolved_mock,rms=rms_image,psf=psf[0].data,mask=mask2)

######### Next step from pysersic.priors import autoprior

prior = autoprior(image = sersic_prof2d_convolved_mock, profile_type = 'sersic', sky_type = 'none')`

This input passes the check_input command, but crashes while running autoprior with the error message:

`ttributeError Traceback (most recent call last) Cell In[106], line 16 13 ######### Next step 14 from pysersic.priors import autoprior ---> 16 prior = autoprior(image = sersic_prof2d_convolved_mock, profile_type = 'sersic', sky_type = 'none')

File ~/miniforge3/lib/python3.10/site-packages/pysersic/priors.py:807, in autoprior(image, profile_type, mask, sky_type) 788 def autoprior(image: np.array, profile_type: 'str', mask:np.array =None, sky_type: str = 'none') -> PySersicSourcePrior: 789 """Simple wrapper function to generate a prior using the built-in defaults. This can be used as a starting place but may not work for all sources 790 791 Parameters (...) 805 Prior object that can be used in initializing FitSingle 806 """ --> 807 props = SourceProperties(image = image, mask = mask) 808 prior = props.generate_prior(profile_type = profile_type, sky_type = sky_type) 809 return prior

File ~/miniforge3/lib/python3.10/site-packages/pysersic/priors.py:526, in SourceProperties.init(self, image, mask) 524 else: 525 self.cat = dataproperties(self.image) --> 526 = self.measure_properties()

File ~/miniforge3/lib/python3.10/site-packages/pysersic/priors.py:537, in SourceProperties.measure_properties(self, kwargs) 529 """Measure default properties of the source 530 531 Returns (...) 534 returns self 535 """ 536 self.set_flux_guess(kwargs) --> 537 self.set_r_eff_guess(kwargs) 538 self.set_theta_guess(kwargs) 539 self.set_position_guess(**kwargs)

File ~/miniforge3/lib/python3.10/site-packages/pysersic/priors.py:613, in SourceProperties.set_r_eff_guess(self, r_eff_guess, r_eff_guess_err, **kwargs) 598 """Measure or set guess for effective radius. If no estimate is provided, the r_eff of the source in estimated using photutils 599 600 Parameters (...) 610 returns self 611 """ 612 if r_eff_guess is None: --> 613 r_eff_guess = self.cat.fluxfrac_radius(0.5).to(u.pixel).value 615 if r_eff_guess_err is not None: 616 self.r_eff_guess_err = r_eff_guess_err

AttributeError: 'numpy.float64' object has no attribute 'to'`

Is this a compatibility issue between the code's dependencies and my installed packages?

prappleizer commented 5 months ago

This looks like a change in the way photutils "data_properties" table generation works between some versions. In our code, (and in the environment I currently run pysersic in), data_properties ) returns a SourceCatalog for which the fluxfrac_radius for some value is an astropy.Quantity, hence the use of .to() to ensure it is in pixels, then .value to extract the float.

In your case, it appears the fluxfrac_radius() method is returning a float directly, meaning there is no .to() method (which is only for quantities).

Could you try using

import photutils
photutils.__version__

and see which you have? For reference, we are currently on 1.11.0.

I noticed photutils' latest version is now 1.12.0, so it's possible the change happened there. If your version is older, than 1.11.0, I recommend upgrading to that version in your pysersic environment; if you have the latest 1.12.0, then let me know and I'll go through and ensure that pysersic reflects any breaking changes.

(that might take me a day or two, so you could always downgrade to 1.11.0 in your env for now as well).

ke27whal commented 5 months ago

Thank you for your speedy response!

I was running photutils verison 1.1.0. I just updated to 1.11.0, though and I'm getting the same error message.

prappleizer commented 5 months ago

Photutils and astropy are pretty intimately linked, so maybe check that too. The easiest way to really confirm is to make a new conda environment using the environment.yml file we provide in the repo — pysersic is currently confirmed to be working in the environment made by that file (which is python3.11 and all packages upgraded as much as possible).

Let me know if you still have any issues!

On Fri, Apr 19, 2024 at 10:57 PM Kelly Whalen @.***> wrote:

Thank you for your speedy response!

I was running photutils verison 1.1.0. I just updated to 1.11.0, though and I'm getting the same error message.

— Reply to this email directly, view it on GitHub https://github.com/pysersic/pysersic/issues/54#issuecomment-2067524898, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD6XXHH7EC627LDVSYHMHLY6HKQVAVCNFSM6AAAAABGQDARYWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRXGUZDIOBZHA . You are receiving this because you commented.Message ID: @.***>

ke27whal commented 5 months ago

Yes, it worked in the new conda environment! Thank you!

prappleizer commented 5 months ago

Great! If you check which versions of the few core packages (astropy, numpy etc), you may determine you can easily get your normal environment set up so you don't have to activate one just for pysersic.

Closing this as complete!