find_widths() AttributeError: No distance has not been given.
I'm trying to find the width information on filaments, other methods were ok, but no matter what, find_widths() gives error.
# there is a skeleton length reading package
from fil_finder import FilFinder2D
import astropy.units as u
fil = FilFinder2D(processed, distance=250 * u.pc, mask=skeleton)
fil.medskel(verbose=False)
fil.analyze_skeletons(branch_thresh=0* u.pix, skel_thresh=0 * u.pix, prune_criteria='length')
f = fil.filaments[0]
plt.imshow(f.skeleton(pad_size=10))
fil.exec_rht()
fil.find_widths(max_dist=0.2 * u.pc)
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_34180/1915991156.py in <module>
5 #f.plot_radial_profile(xunit=u.pc)
6 fil.exec_rht()
----> 7 fil.find_widths(max_dist=0.2 * u.pc)
C:\ProgramData\Anaconda3\envs\cv\lib\site-packages\fil_finder\filfinder2D.py in find_widths(self, max_dist, pad_to_distance, fit_model, fitter, try_nonparam, use_longest_path, add_width_to_length, deconvolve_width, fwhm_function, chisq_max, verbose, save_png, save_name, xunit, **kwargs)
973 print("Filament: %s / %s" % (n + 1, self.number_of_filaments))
974
--> 975 fil.width_analysis(self.image, all_skeleton_array=self.skeleton,
976 max_dist=max_dist,
977 pad_to_distance=pad_to_distance,
C:\ProgramData\Anaconda3\envs\cv\lib\site-packages\fil_finder\filament.py in width_analysis(self, image, all_skeleton_array, max_dist, pad_to_distance, fit_model, fitter, try_nonparam, use_longest_path, add_width_to_length, deconvolve_width, beamwidth, fwhm_function, chisq_max, **kwargs)
762
763 # Convert quantities to pixel units.
--> 764 max_dist = self._converter.to_pixel(max_dist).value
765 pad_to_distance = self._converter.to_pixel(pad_to_distance).value
766
C:\ProgramData\Anaconda3\envs\cv\lib\site-packages\fil_finder\base_conversions.py in to_pixel(self, value)
206 return value.to(u.pix, equivalencies=self.angular_equiv)
207 elif value.unit.is_equivalent(u.pc):
--> 208 return value.to(u.pix, equivalencies=self.physical_equiv)
209 else:
210 raise u.UnitConversionError("value has units of {}. It must have "
C:\ProgramData\Anaconda3\envs\cv\lib\site-packages\fil_finder\base_conversions.py in physical_equiv(self)
186 def physical_equiv(self):
187 if not hasattr(self, "_distance"):
--> 188 raise AttributeError("No distance has not been given.")
189
190 return [(u.pix, self.distance.unit,
AttributeError: No distance has not been given.
HI @tomriddle1234 -- Thanks for posting the issue! I think the problem may be that the error message is unclear. Is the input data processed an array? If it is, the issue is coming from the unit conversion path of pix -> angular -> physical units, where the angular conversion is from a FITS header that describes the image's position in the world coordinate system (https://docs.astropy.org/en/stable/io/fits/index.html). Right now there isn't a workaround to do pix -> physical unit conversion.
Just to check, do you encounter any issues when specifying the parameters only in pixel units?