Skip to content

Commit d275647

Browse files
authored
Add local brightness property to FluorState model, Fixes FPBASE-6EP (#393)
1 parent 8653e21 commit d275647

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

backend/proteins/models/fluorophore.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING, Final, cast
44

55
from django.db import models
6+
from django.db.models import Avg
67
from django.utils.text import slugify
78

89
from proteins.models.fluorescence_data import AbstractFluorescenceData
@@ -230,6 +231,17 @@ def stokes(self) -> float | None:
230231
except TypeError:
231232
return None
232233

234+
@property
235+
def local_brightness(self) -> float:
236+
"""Brightness relative to spectral neighbors. 1 = average."""
237+
if not (self.em_max and self.brightness):
238+
return 1
239+
avg = FluorState.objects.exclude(id=self.id).filter(em_max__around=self.em_max).aggregate(Avg("brightness"))
240+
try:
241+
return round(self.brightness / avg["brightness__avg"], 4)
242+
except TypeError:
243+
return 1
244+
233245
def has_spectra(self) -> bool:
234246
if any([self.ex_spectrum, self.em_spectrum]):
235247
return True

0 commit comments

Comments
 (0)