diff --git a/views.py b/views.py index 00f4bfa..867e03d 100644 --- a/views.py +++ b/views.py @@ -209,7 +209,7 @@ class UpperLimitView(APIView): ) annulus_pixels = Pixel.objects.filter( - hpid__in=annulus_pixel_list, survey__in=survey_numbers + hpid__in=annulus_pixel_list, survey__in=survey_numbers, contaminated=False ) # check contamination @@ -218,9 +218,14 @@ class UpperLimitView(APIView): or annulus_pixels.filter(contaminated=True).exists() ) - if not source_pixels.exists() and not annulus_pixels.exists(): + # exclude contaminated pixels from the background calculations + annulus_pixels = annulus_pixels.exclude(contaminated=True) + + if not source_pixels.exists() or not annulus_pixels.exists(): return Response( - {"detail": "No pixel data for the given survey selection."}, + { + "detail": "No background and/or source pixel data for the given survey selection." + }, status=status.HTTP_404_NOT_FOUND, )