askap-vast / vast-tools

A collection of tools that are useful for the VAST project and for exploration of results from the VAST Pipeline.
https://vast-survey.org/vast-tools/
MIT License
8 stars 0 forks source link

Cutouts break for post-processed pipeline data #523

Closed ddobie closed 9 months ago

ddobie commented 9 months ago
AttributeError                            Traceback (most recent call last)
Cell In[26], line 6
      4 source = run.get_source(source_id)
      5 source.plot_lightcurve()
----> 6 source.show_all_png_cutouts(figsize=(20,10)) 
      7 print(f"[https://dev.pipeline.vast-survey.org/sources/{source_id}/](https://dev.pipeline.vast-survey.org/sources/%7Bsource_id%7D/)")

File /home/jovyan/vast-tools/vasttools/source.py:1393, in Source.show_all_png_cutouts(self, columns, percentile, zscale, contrast, outfile, save, size, figsize, force, no_selavy, disable_autoscaling, hide_epoch_labels, plot_dpi, offset_axes)
   1357 """
   1358 Creates a grid plot showing the source in each epoch.
   1359 
   (...)
   1389     None is save is `True` or the Figure if `False`.
   1390 """
   1392 if (self._cutouts_got is False) or (force):
-> 1393     self.get_cutout_data(size)
   1395 num_plots = self.measurements.shape[0]
   1396 nrows = int(np.ceil(num_plots / columns))

File /home/jovyan/vast-tools/vasttools/source.py:668, in Source.get_cutout_data(self, size)
    665 else:
    666     args = (size,)
--> 668 self.cutout_df = self.measurements.apply(
    669     self._get_cutout,
    670     args=args,
    671     axis=1,
    672     result_type='expand'
    673 ).rename(columns={
    674     0: "data",
    675     1: "wcs",
    676     2: "header",
    677     3: "selavy_overlay",
    678     4: "beam"
    679 })
    680 self._cutouts_got = True

File /opt/conda/lib/python3.8/site-packages/pandas/core/frame.py:8845, in DataFrame.apply(self, func, axis, raw, result_type, args, **kwargs)
   8834 from pandas.core.apply import frame_apply
   8836 op = frame_apply(
   8837     self,
   8838     func=func,
   (...)
   8843     kwargs=kwargs,
   8844 )
-> 8845 return op.apply().__finalize__(self, method="apply")

File /opt/conda/lib/python3.8/site-packages/pandas/core/apply.py:733, in FrameApply.apply(self)
    730 elif self.raw:
    731     return self.apply_raw()
--> 733 return self.apply_standard()

File /opt/conda/lib/python3.8/site-packages/pandas/core/apply.py:857, in FrameApply.apply_standard(self)
    856 def apply_standard(self):
--> 857     results, res_index = self.apply_series_generator()
    859     # wrap results
    860     return self.wrap_results(results, res_index)

File /opt/conda/lib/python3.8/site-packages/pandas/core/apply.py:873, in FrameApply.apply_series_generator(self)
    870 with option_context("mode.chained_assignment", None):
    871     for i, v in enumerate(series_gen):
    872         # ignore SettingWithCopy here in case the user mutates
--> 873         results[i] = self.f(v)
    874         if isinstance(results[i], ABCSeries):
    875             # If we have a view on v, we need to make a copy because
    876             #  series_generator will swap out the underlying data
    877             results[i] = results[i].copy(deep=False)

File /home/jovyan/vast-tools/vasttools/source.py:775, in Source._get_cutout(self, row, size)
    769 if self.pipeline:
    770     image = Image(
    771         row.field, row.epoch, self.stokes, self.base_folder,
    772         path=row.image, rmspath=row.rms,
    773         corrected_data=self.corrected_data
    774     )
--> 775     image.get_img_data()
    776 else:
    777     e = row.epoch

File /home/jovyan/vast-tools/vasttools/survey.py:437, in Image.get_img_data(self)
    435     self.header = hdul[0].header
    436     self.wcs = WCS(self.header, naxis=2)
--> 437     self.data = hdul[0].data.squeeze()
    439 try:
    440     self.beam = Beam.from_fits_header(self.header)

AttributeError: 'NoneType' object has no attribute 'squeeze'

pointed out by @mayavandervegt.

Issue likely arises from the post-processed HDUs placing the data in the 1th element rather than zeroth. This should have been addressed already (#480) but it looks like open_fits looks specifically for .fits.fz files, which is a different naming format to what we've now decided on.