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/base.py", 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/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/user/bbOpenREM/openrem/remapp/views.py", line 858, in rf_detail_view_skin_map
    make_skin_map(pk)
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/celery/local.py", line 188, in __call__
    return self._get_current_object()(*a, **kw)
  File "/home/user/veOpenREM/local/lib/python2.7/site-packages/celery/app/task.py", line 420, in __call__
    return self.run(*args, **kwargs)
  File "/home/user/bbOpenREM/openrem/remapp/tools/make_skin_map.py", 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/manager.py", 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/query.py", line 338, in get
    (self.model._meta.object_name, num)
MultipleObjectsReturned: get() returned more than one Kvp -- it returned 22!

Comments (16)

  1. David Platten

    @edmcdonagh, can you send me an RDSR of a study that has this problem, then I'll take a look at it?

  2. David Platten

    Calculate the median kVp per exposure. 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 43270ace05b5>>

  3. 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.

    @edmcdonagh, what do you think?

  4. 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>>

  5. 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.

  6. David Platten

    @edmcdonagh, your comment must have crossed paths with my commit just now. I'm now using numpy's median function, which I think is the best way forward. I've also updated the docs to reflect this.

  7. David Platten

    Added a check for np.isnan(kvp), and if true set kvp to None. I think this addresses the comment that Ed made in the pull request. References issue #602

    → <<cset 83379155dcf4>>

  8. Log in to comment