i4Ds / Karabo-Pipeline

The Karabo Pipeline can be used as Digital Twin for SKA
https://i4ds.github.io/Karabo-Pipeline/
MIT License
11 stars 4 forks source link

xarray concat got unexpected keyword argument 'attrs' #146

Closed Lukas113 closed 1 year ago

Lukas113 commented 2 years ago

When I use imaging_rascil in how_to_use_karabo_example.ipynb (localhost Ubuntu 20.04 & CSCS.daint), I got:

image

This is caused in xarray.core.concat.py 593

I am not sure why this occurs and how to approach it since in the Imager just contains the .ms observation and the error is thrown through RASCIL code. Maybe this is something RSCIL fixed in a newer release? I've just found an issue related to on https://github.com/pydata/xarray/issues/6827 , but I'm not sure if this is what we are looking for.

sfiruch commented 2 years ago

Can you provide a full stacktrace from imager.py to xarray?

It seems that whatever object we're deserializing here doesn't have the correct constructor.

Lukas113 commented 2 years ago
File ~/Karabo-Pipeline/karabo/imaging/imager.py:184, in Imager.imaging_rascil(self, client, num_bright_sources, clean_algorithm, clean_beam, clean_scales, clean_nmoment, clean_nmajor, clean_niter, clean_psf_support, clean_gain, clean_threshold, clean_component_threshold, clean_component_method, clean_fractional_threshold, clean_facets, clean_overlap, clean_taper, clean_restore_facets, clean_restore_overlap, clean_restore_taper, clean_restored_output)
    173 cellsize = self.imaging_cellsize
    174 models = [
    175     rsexecute.execute(create_image_from_visibility)(
    176         bvis,
   (...)
    182     for bvis in blockviss
    183 ]
--> 184 result = continuum_imaging_skymodel_list_rsexecute_workflow(
    185     blockviss,  # List of BlockVisibilitys
    186     models,  # List of model images
    187     context=self.imaging_context,  # Use nifty-gridder
    188     threads=self.imaging_ng_threads,
    189     wstacking=self.imaging_w_stacking
    190     == "True",  # Correct for w term in gridding
    191     niter=clean_niter,  # iterations in minor cycle
    192     nmajor=clean_nmajor,  # Number of major cycles
    193     algorithm=clean_algorithm,
    194     gain=clean_gain,  # CLEAN loop gain
    195     scales=clean_scales,  # Scales for multi-scale cleaning
    196     fractional_threshold=clean_fractional_threshold,
    197     # Threshold per major cycle
    198     threshold=clean_threshold,  # Final stopping threshold
    199     nmoment=clean_nmoment,
    200     # Number of frequency moments (1 = no dependence)
    201     psf_support=clean_psf_support,
    202     # Support of PSF used in minor cycles (halfwidth in pixels)
    203     restored_output=clean_restored_output,  # Type of restored image
    204     deconvolve_facets=clean_facets,
    205     deconvolve_overlap=clean_overlap,
    206     deconvolve_taper=clean_taper,
    207     restore_facets=clean_restore_facets,
    208     restore_overlap=clean_restore_overlap,
    209     restore_taper=clean_restore_taper,
    210     dft_compute_kernel=self.imaging_dft_kernel,
    211     component_threshold=clean_component_threshold,
    212     component_method=clean_component_method,
    213     flat_sky=self.imaging_flat_sky,
    214     clean_beam=clean_beam,
    215     clean_algorithm=clean_algorithm,
    216 )
    218 result = rsexecute.compute(result, sync=True)
    220 residual, restored, skymodel = result

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/workflows/rsexecute/pipelines/pipeline_skymodel_rsexecute.py:392, in continuum_imaging_skymodel_list_rsexecute_workflow(vis_list, model_imagelist, context, skymodel_list, **kwargs)
    372 def continuum_imaging_skymodel_list_rsexecute_workflow(
    373     vis_list, model_imagelist, context, skymodel_list=None, **kwargs
    374 ):
    375     """Create graph for the continuum imaging pipeline.
    376 
    377     Same as ICAL but with no selfcal.
   (...)
    385     :return:
    386     """
    387     (
    388         residual_imagelist,
    389         restore_imagelist,
    390         skymodel_list,
    391         gt_list,
--> 392     ) = ical_skymodel_list_rsexecute_workflow(
    393         vis_list,
    394         model_imagelist,
    395         context=context,
    396         skymodel_list=skymodel_list,
    397         calibration_context="",
    398         do_selfcal=False,
    399         pipeline_name="cip",
    400         **kwargs,
    401     )
    402     return (
    403         residual_imagelist,
    404         restore_imagelist,
    405         skymodel_list,
    406     )

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/workflows/rsexecute/pipelines/pipeline_skymodel_rsexecute.py:252, in ical_skymodel_list_rsexecute_workflow(vis_list, model_imagelist, context, skymodel_list, calibration_context, controls, do_selfcal, pipeline_name, **kwargs)
    239 # We've finished so now we update the residual images and calculate the restored image
    240 residual_imagelist = residual_skymodel_list_rsexecute_workflow(
    241     cal_vis_list,
    242     skymodel_list,
   (...)
    245     **kwargs,
    246 )
    248 (
    249     skymodel_list,
    250     residual_imagelist,
    251     restored_imagelist,
--> 252 ) = restore_skymodel_pipeline_rsexecute_workflow(
    253     skymodel_list, psf_imagelist, residual_imagelist, **kwargs
    254 )
    255 return (
    256     residual_imagelist,
    257     restored_imagelist,
    258     skymodel_list,
    259     gt_list,
    260 )

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/workflows/rsexecute/pipelines/pipeline_skymodel_rsexecute.py:281, in restore_skymodel_pipeline_rsexecute_workflow(skymodel_list, psf_imagelist, residual_imagelist, **kwargs)
    278 output = get_parameter(kwargs, "restored_output", "list")
    280 if output == "integrated":
--> 281     restored_imagelist = restore_centre_skymodel_list_rsexecute_workflow(
    282         skymodel_list, psf_imagelist, residual_imagelist, **kwargs
    283     )
    284 elif output == "taylor":
    285     # In this case, we overwrite the originals with Taylor term versions
    286     nmoment = get_parameter(kwargs, "nmoment", 1)

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/workflows/rsexecute/skymodel/skymodel_rsexecute.py:118, in restore_centre_skymodel_list_rsexecute_workflow(skymodel_list, psf_imagelist, residual_imagelist, clean_beam, **kwargs)
    115     return restore_skycomponent(res_image, s.components, cb)
    117 residual = sum_invert_results_rsexecute(residual_imagelist)[0]
--> 118 restored = rsexecute.execute(skymodel_restore, nout=1)(
    119     skymodel_list[centre], residual, clean_beam
    120 )
    122 return restored

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/workflows/rsexecute/skymodel/skymodel_rsexecute.py:114, in restore_centre_skymodel_list_rsexecute_workflow.<locals>.skymodel_restore(s, res, cb)
    113 def skymodel_restore(s, res, cb):
--> 114     res_image = restore_cube(s.image, residual=res, clean_beam=cb)
    115     return restore_skycomponent(res_image, s.components, cb)

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/processing_components/image/deconvolution.py:1013, in restore_cube(model, psf, residual, clean_beam)
   1004 psf_list = image_scatter_channels(psf)
   1006 restored_list = restore_list(
   1007     model_list=model_list,
   1008     psf_list=psf_list,
   1009     residual_list=residual_list,
   1010     clean_beam=clean_beam,
   1011 )
-> 1013 return image_gather_channels(restored_list)

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/rascil/processing_components/image/gather_scatter.py:185, in image_gather_channels(image_list, im, subimages)
    175 def image_gather_channels(
    176     image_list: List[Image], im: Image = None, subimages=0
    177 ) -> Image:
    178     """Gather a list of subimages back into an image
    179 
    180     :param image_list: List of subimages
   (...)
    183     :return: list of subimages
    184     """
--> 185     return xarray.concat(image_list, dim="frequency")

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/xarray/core/concat.py:243, in concat(objs, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs)
    231     return _dataarray_concat(
    232         objs,
    233         dim=dim,
   (...)
    240         combine_attrs=combine_attrs,
    241     )
    242 elif isinstance(first_obj, Dataset):
--> 243     return _dataset_concat(
    244         objs,
    245         dim=dim,
    246         data_vars=data_vars,
    247         coords=coords,
    248         compat=compat,
    249         positions=positions,
    250         fill_value=fill_value,
    251         join=join,
    252         combine_attrs=combine_attrs,
    253     )
    254 else:
    255     raise TypeError(
    256         "can only concatenate xarray Dataset and DataArray "
    257         f"objects, got {type(first_obj)}"
    258     )

File ~/anaconda3/envs/karabo_dev_env/lib/python3.9/site-packages/xarray/core/concat.py:593, in _dataset_concat(datasets, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs)
    589     elif name in result_vars:
    590         # preserves original variable order
    591         result_vars[name] = result_vars.pop(name)
--> 593 result = type(datasets[0])(result_vars, attrs=result_attrs)
    595 absent_coord_names = coord_names - set(result.variables)
    596 if absent_coord_names:

TypeError: __init__() got an unexpected keyword argument 'attrs'
kenfus commented 2 years ago

FYI: I get the same error

kenfus commented 2 years ago

Reinstalling an old version fixes this:

pip install xarray==2022.3.0

A solution is just to fix this version in the meta.yaml.

Now the notebook-cell with

imager_askap.ingest_chan_per_blockvis = 1
imager_askap.ingest_vis_nchan = 16

deconvolved, restored, residual = imager_askap.imaging_rascil(
..
)

works.

kenfus commented 1 year ago

Still fails with rascil==0.7.0. Will create a PR with an updated xarray version. However, Rascil is pinning the newest version (2022.6.0) in their requirements (which gives the error) but I don't see an issue for this error in their repository. Do we call rascil differently?

kenfus commented 1 year ago

@deiruch We saw that rascil released a hotfix version 0.7.1 which apparently deals with this issue. Would be better than fixing the verison.

sfiruch commented 1 year ago

Great. Can't we both upgrade AND fix it?

kenfus commented 1 year ago

Sadly no, because creating a python package from rascil 0.7.1 gives an error. The pipeline works perfectly for 0.5.0 and 0.7.0 (and I guess all the other versions but not for 0.7.1). Maybe rascil did not update some parameters yet by mistake? @Lukas113

So now we just downgrade xarray to 2022.3.0.

Lukas113 commented 1 year ago

To me it seems that RASCIL has launched their upgrade, but didn't update at least their version number. So for RASCIL 0.7.1 we have to fix the dependencies first. So it seems to be a good idea to downgrade xarray for 0.7.0 and fix the dependencies of 0.7.1 as soon as possible.