MultiValue kV causes skin map server error

Issue #602 resolved
Ed McDonagh
created an issue

Study with multiple kV values per exposure causes server error when detail view opened due to skin map calculations.

Refs #584

Internal Server Error: /openrem/rf/261383/skin_map/
Traceback (most recent call last):
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/django/core/handlers/", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/django/contrib/auth/", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/user/bbOpenREM/openrem/remapp/", line 858, in rf_detail_view_skin_map
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/celery/", line 188, in __call__
    return self._get_current_object()(*a, **kw)
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/celery/app/", line 420, in __call__
    return*args, **kwargs)
  File "/home/user/bbOpenREM/openrem/remapp/tools/", line 171, in make_skin_map
    kvp = float(irrad.irradeventxraysourcedata_set.get().kvp_set.get().kvp)
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/django/db/models/", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/django/db/models/", line 338, in get
    (self.model._meta.object_name, num)
MultipleObjectsReturned: get() returned more than one Kvp -- it returned 22!

Comments (15)

  1. David Platten

    I've just realised that calculating the median is a bad idea because only users with PostgreSQL have access to the median function.

    I could use the mean or max aggregate function instead.

    I think the mean is the way to go.

    @Ed McDonagh, what do you think?

  2. David Platten

    Calculate the median kVp per exposure using the numpy median function. Will work for any OpenREM install. Fixes error that otherwise occurs if a single exposure contains multiple kVp values stored for it. However, is calculating the median the best thing to do? References issue #602

    → <<cset 7df793cc1ef0>>

  3. Ed McDonagh reporter

    I think it probably is. This RDSR is the only I have ever seen with per pulse data, and generally of the two that I have been sent the value is mostly the same, except one of the series has a 0 value at the start. If you used mean then that wouldn't be representative. The only other thing you could do is exclude any zeros before taking a mean, but I think median is probably the way to go. We just need to put it in the docs somewhere.

  4. Log in to comment