sunpy / ndcube

A base package for multi-dimensional contiguous and non-contiguous coordinate-aware arrays.
http://docs.sunpy.org/projects/ndcube/
BSD 2-Clause "Simplified" License
44 stars 48 forks source link

Support Arithmetic Operations between NDCube and WCS-less NDData #734

Open DanRyanIrish opened 4 months ago

DanRyanIrish commented 4 months ago

Describe the feature

Currently, NDCube does not support arithmetic operations with NDData instances because it does not make sense to combine cubes on different coordinate grids. However, this is not a concern when the NDData instance has a wcs set to None. Therefore, we should support arithmetic operations between NDCube and WCS-less NDData instances. This would serve the cases where users want to NDCube with data with uncertainties and a mask.

Proposed solution

This would need to be explicitly supported in NDCube.__add__ and NDCube.__mul__.

For adding, code needs to be inserted here that checks if not hasattr(value, wcs) or value.wcs is None: and then add then convert the value to the right units ( u.Quantity(value.data, unit=value.unit).to_value(self.unit) ), add the data as masked_arrays, (new_data = np.ma.masked_array(self.data, mask=self.mask) + np.ma.masked_array(value.data, mask=value.mask), and propagate the uncertainties, An example can be seen in NDCube.__pow__ for multipy uncertainty propagation.

A similar structure should work for multiplication somewhere in the codebase around here.