How to measure the dynamic range of an HDRi?
To properly answer your question, I'll lean on the photographic term of F-Stop to define what this range is.

What we know:


An F-Stop is a halving and doubling of light, relative to the exposure referenced.
A scene referred system has scene linear levels of light ranging from zero to infinity.


Therefore, to get from the question of dynamic range in stops to data values, we need to do a little math and figure out what our maximum and minimum values are in a given image, then convert that range to F-Stops for our solution.

We know that 2^FStops * middle_grey_peg will give us a numerical value for a given number of stops above or below middle grey in scene linear. So how would we go back from scene linear to F-Stops? Invert the formula for log(scene_referred / middle_grey_peg) / log(2) and we get the number of stops up or down for any given scene referred value.

If we subtract the two, we'd get overall dynamic range.

We can simplify it by skipping the middle grey value:

( log(scene_referred_maximum) / log(2) ) - ( log(scene_referred_minimum) / log(2) )


The result will be total dynamic range, expressed in stops.

I'm sure someone here can come up with a clever way via Python to get the minimum and maximum RGB scene referred values from a Cycles render or EXR image?

In theory the following code appears to work on EXRs, but your mileage may vary:

import bpy
from math import ceil, log

image = bpy.data.images['your_exr_goes_here.exr']

print("Total dynamic range in stops:")
print( ( log(max(image.pixels)) / log(2) ) - ( log(min(image.pixels)) / log(2) ) )
# Equivalent to (log(max) - log(min))/log(2) of course.