Add option of inversion of relative (negative) emissivity profile
I am studying turbulence/filaments in COMPASS via visible imaging. What we do actually is we remove the background emission with a median filter over 10s of frames, and then we invert the subtracted frame. This gives a frame with negative values. I want to use the SART method implemented on CHERAB (especially the GPU optimized one) but the function removes the negative emissivity values in the SART algorithm, as it would be unphysical. Is it possible to add an option to the invert_sart function to allow negative emissivity values ? Thanks
Thank you for your request! I think that here's the part that needs fixing: https://github.com/cherab/core/blob/7768b306065539ee786ada0c85b8f6e0a4b09850/cherab/tools/inversions/opencl/sart_kernels.cl#L143-L145
I would like to ask other developers if there is any part that we need to fix or if we should consider including such a negative value.
I'm afraid I can't help here. SART is outside by area. The zeroing might have a justification if negative values were crashing some other parts of the inversion or if it was a defined step in the SART method. If not, I would support removing this, since it is not explicitly mentioned step in the code exposed to users.
The zeroing makes sense in most cases, because we expect positive values, since negative light emission is not physically realistic. However I am looking at relative emission compared to a background, so I get negative emission and negative solutions now make sense. I would add a keyword argument to the call function of the SartOpencl class that governs this zeroing (eg : only_positive_values boolean) https://github.com/cherab/core/blob/26595cb6101e14d6a3eeb1b7421024425114c7a1/cherab/tools/inversions/opencl/sart_opencl.py#L198C1-L200C16
This new argument would apply on this function of the class https://github.com/cherab/core/blob/26595cb6101e14d6a3eeb1b7421024425114c7a1/cherab/tools/inversions/opencl/sart_opencl.py#L301C1-L302C2 By default it would be left True, as most user cases would expect positive values.
If set to False, it would ignore the if in this function from the sart_kernels.cl file, and always assign the new value instead of 0. https://github.com/cherab/core/blob/26595cb6101e14d6a3eeb1b7421024425114c7a1/cherab/tools/inversions/opencl/sart_kernels.cl#L143C1-L144C36
Yes, this think this is fine to do. The original SART implementation (which inspired Vlad's OpenCL variant, I believe) had a non-negativity constraint because the expected use case was inverting path-integral emission, for which negative values are unphysical. There are almost no instances in that case where negative values would be of benefit, though you've found one of the occasions where they are useful.
Do you want to have a go at a pull request to add a non_negative keyword and some tests for it? N.B. The current scheme does allow zeroes, so "only positive" is not strictly correct as zero isn't necessarily positive.
Yes I can try that. For the tests, is it ok if I just copy one of the example (like here https://github.com/cherab/core/blob/master/demos/ray_transfer/4_ray_transfer_map.py) ? And I just add two inversions, with the non_negative keyword set to True or False.
Add the tests to here: https://github.com/cherab/core/blob/master/cherab/tools/tests/test_sart_opencl.py. You can re-use the geometry matrix Vlad made for the existing tests, but you'll want a new solution vector that has negative numbers in it.
I don't think you'll necessarily need to make a new demo as well: those are more work and the existing demos should be sufficient for users to understand how to use the tools provided the new keyword is suitably described in the docstring.