The basic algorithm works like this: Copy rain_type to rain_type_uw. For each pixel in rain_type_uw, change rain_type_uw to stratiform if:
Some of these terms need to be defined
The following plot illustrates the algorithm. In it, the horizontal magenta line represents the height of max_refl. The dashed horizontal blue line represents the height of the last point that is within REFL_MAX_OFFSET of max_refl. This is the reference height. The dashed horizontal green line represents the height 1.5 km above the reference height. If you calculate the delta_refl between the dashed vertical blue and green lines and divide it by the delta_ht between the dashed horizontal blue and green lines you get a slope of 5.39. This is not greater than or equal to SLOPE so rain_type_uw remains convective. If that slope was greater than or equal to SLOPE, rain_type_uw would have been changed to stratiform.