def generate_two_polygon_annotation_sets(retina_grader=False): graders = (UserFactory(), UserFactory()) if retina_grader: add_to_graders_group(graders) polygonsets = ( PolygonAnnotationSetFactory(grader=graders[0]), PolygonAnnotationSetFactory(grader=graders[1]), ) # Create child models for polygon annotation set singlepolygonbatches = ( SinglePolygonAnnotationFactory.create_batch( 10, annotation_set=polygonsets[0] ), SinglePolygonAnnotationFactory.create_batch( 10, annotation_set=polygonsets[1] ), ) return TwoPolygonAnnotationSets( grader1=graders[0], grader2=graders[1], polygonset1=polygonsets[0], polygonset2=polygonsets[1], )
def generate_two_polygon_annotation_sets(retina_grader=False): graders = (UserFactory(), UserFactory()) if retina_grader: add_to_graders_group(graders) polygonsets = ( PolygonAnnotationSetFactory(grader=graders[0]), PolygonAnnotationSetFactory(grader=graders[1]), ) # Create child models for polygon annotation set singlepolygonbatches = ( SinglePolygonAnnotationFactory.create_batch( 10, annotation_set=polygonsets[0] ), SinglePolygonAnnotationFactory.create_batch( 10, annotation_set=polygonsets[1] ), ) return TwoPolygonAnnotationSets( grader1=graders[0], grader2=graders[1], polygonset1=polygonsets[0], polygonset2=polygonsets[1], )
def generate_annotation_set(retina_grader=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) measurement = MeasurementAnnotationFactory(grader=grader) boolean = BooleanClassificationAnnotationFactory(grader=grader) integer = IntegerClassificationAnnotationFactory(grader=grader) polygon = PolygonAnnotationSetFactory(grader=grader) coordinatelist = CoordinateListAnnotationFactory(grader=grader) landmark = LandmarkAnnotationSetFactory(grader=grader) etdrs = ETDRSGridAnnotationFactory(grader=grader) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) for i in range(5): image = ImageFactory() SingleLandmarkAnnotationFactory(annotation_set=landmark, image=image) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, etdrs=etdrs, integer=integer, )
def generate_annotation_set(retina_grader=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) measurement = MeasurementAnnotationFactory(grader=grader) boolean = BooleanClassificationAnnotationFactory(grader=grader) integer = IntegerClassificationAnnotationFactory(grader=grader) polygon = PolygonAnnotationSetFactory(grader=grader) coordinatelist = CoordinateListAnnotationFactory(grader=grader) landmark = LandmarkAnnotationSetFactory(grader=grader) etdrs = ETDRSGridAnnotationFactory(grader=grader) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) for i in range(5): image = ImageFactory() SingleLandmarkAnnotationFactory(annotation_set=landmark, image=image) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, etdrs=etdrs, integer=integer, )
def generate_annotation_set(retina_grader=False, image=False): grader = UserFactory() if retina_grader: add_to_graders_group([grader]) create_options = {"grader": grader} if image: create_options_with_image = {"image": image, **create_options} else: create_options_with_image = create_options measurement = MeasurementAnnotationFactory(**create_options_with_image) boolean = BooleanClassificationAnnotationFactory( **create_options_with_image ) integer = IntegerClassificationAnnotationFactory( **create_options_with_image ) polygon = PolygonAnnotationSetFactory(**create_options_with_image) coordinatelist = CoordinateListAnnotationFactory( **create_options_with_image ) etdrs = ETDRSGridAnnotationFactory(**create_options_with_image) landmark = LandmarkAnnotationSetFactory(**create_options) # Create child models for polygon annotation set SinglePolygonAnnotationFactory.create_batch(10, annotation_set=polygon) # Create child models for landmark annotation set (3 per image) single_landmarks = [] for i in range(5): if i > 0 or not image: image = ImageFactory() single_landmarks.append( SingleLandmarkAnnotationFactory( annotation_set=landmark, image=image ) ) return AnnotationSet( grader=grader, measurement=measurement, boolean=boolean, polygon=polygon, coordinatelist=coordinatelist, landmark=landmark, singlelandmarks=single_landmarks, etdrs=etdrs, integer=integer, )
def test_create_view_wrong_user_id( self, TwoRetinaPolygonAnnotationSets, rf, user_type ): model_build = SinglePolygonAnnotationFactory.build() model_serialized = SinglePolygonAnnotationSerializer(model_build).data other_user = UserFactory() annotation_set = PolygonAnnotationSetFactory(grader=other_user) model_serialized["annotation_set"] = str(annotation_set.id) model_json = json.dumps(model_serialized) response = view_test( "create", user_type, self.namespace, self.basename, TwoRetinaPolygonAnnotationSets.grader1, None, rf, SinglePolygonViewSet, model_json, check_response_status_code=False, ) if user_type == "retina_admin": assert response.data["value"] == model_serialized["value"] elif user_type == "retina_grader": assert response.status_code == status.HTTP_400_BAD_REQUEST assert ( str(response.data["non_field_errors"][0]) == "User is not allowed to create annotation for other grader" ) else: assert response.status_code == status.HTTP_403_FORBIDDEN
def test_partial_update_view( self, TwoRetinaPolygonAnnotationSets, rf, user_type ): model_serialized = SinglePolygonAnnotationSerializer( TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first() ).data annotation_set = SinglePolygonAnnotationFactory() model_serialized["value"] = annotation_set.value partial_model = copy.deepcopy(model_serialized) del partial_model["annotation_set"] del partial_model["id"] model_json = json.dumps(partial_model) response = view_test( "partial_update", user_type, self.namespace, self.basename, TwoRetinaPolygonAnnotationSets.grader1, TwoRetinaPolygonAnnotationSets.polygonset1.singlepolygonannotation_set.first(), rf, SinglePolygonViewSet, model_json, ) if user_type in ("retina_grader", "retina_admin"): assert response.data == model_serialized
def test_create_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type): model_build = SinglePolygonAnnotationFactory.build() model_serialized = SinglePolygonAnnotationSerializer(model_build).data annotation_set = PolygonAnnotationSetFactory( grader=TwoRetinaPolygonAnnotationSets.grader1 ) model_serialized["annotation_set"] = str(annotation_set.id) model_json = json.dumps(model_serialized) response = view_test( "create", user_type, self.namespace, self.basename, TwoRetinaPolygonAnnotationSets.grader1, None, rf, SinglePolygonViewSet, model_json, ) if user_type in ("retina_grader", "retina_admin"): model_serialized["id"] = response.data["id"] response.data["annotation_set"] = str( response.data["annotation_set"] ) assert response.data == model_serialized
def test_testmigratelesionnames_unique_violation_appends(self): annotation = PolygonAnnotationSetFactory( name="drusen and drusen like structures::hard drusen") SinglePolygonAnnotationFactory(annotation_set=annotation), SinglePolygonAnnotationFactory(annotation_set=annotation), annotation_dup = PolygonAnnotationSetFactory( name="retina::enface::rf_present::Hard drusen", grader=annotation.grader, image=annotation.image, created=annotation.created, ) SinglePolygonAnnotationFactory(annotation_set=annotation_dup), SinglePolygonAnnotationFactory(annotation_set=annotation_dup), assert annotation_dup.singlepolygonannotation_set.count() == 2 result = migrate_annotations(PolygonAnnotationSet.objects.all()) assert result["translated"] == 1 assert result["already_translated"] == 1 assert PolygonAnnotationSet.objects.count() == 1 annotation_dup.refresh_from_db() assert annotation_dup.singlepolygonannotation_set.count() == 4
def test_create_view(self, TwoRetinaPolygonAnnotationSets, rf, user_type): model_build = SinglePolygonAnnotationFactory.build() model_serialized = SinglePolygonAnnotationSerializer(model_build).data annotation_set = PolygonAnnotationSetFactory( grader=TwoRetinaPolygonAnnotationSets.grader1 ) model_serialized["annotation_set"] = str(annotation_set.id) model_json = json.dumps(model_serialized) response = view_test( "create", user_type, self.namespace, self.basename, TwoRetinaPolygonAnnotationSets.grader1, None, rf, SinglePolygonViewSet, model_json, ) if user_type in ("retina_grader", "retina_admin"): assert response.data["value"] == model_serialized["value"]
def test_create_view_wrong_user_id( self, TwoRetinaPolygonAnnotationSets, rf, user_type ): model_build = SinglePolygonAnnotationFactory.build() model_serialized = SinglePolygonAnnotationSerializer(model_build).data other_user = UserFactory() annotation_set = PolygonAnnotationSetFactory(grader=other_user) model_serialized["annotation_set"] = str(annotation_set.id) model_json = json.dumps(model_serialized) response = view_test( "create", user_type, self.namespace, self.basename, TwoRetinaPolygonAnnotationSets.grader1, None, rf, SinglePolygonViewSet, model_json, check_response_status_code=False, ) if user_type == "retina_admin": model_serialized["id"] = response.data["id"] response.data["annotation_set"] = str( response.data["annotation_set"] ) assert response.data == model_serialized elif user_type == "retina_grader": assert response.status_code == status.HTTP_400_BAD_REQUEST assert ( str(response.data["non_field_errors"][0]) == "User is not allowed to create annotation for other grader" ) else: assert response.status_code == status.HTTP_403_FORBIDDEN
def create_load_data(data_type, ds, grader): if data_type == "Registration": model = LandmarkAnnotationSetFactory(grader=grader) SingleLandmarkAnnotationFactory( annotation_set=model, image=ds["image_cf"] ), if ds["archive"].name == "Australia": # Australia does not allow obs images so create a new cf image for Australia test img = ImageFactory(study=ds["study"]) SingleLandmarkAnnotationFactory(annotation_set=model, image=img) else: SingleLandmarkAnnotationFactory( annotation_set=model, image=ds["image_obs"] ), elif data_type == "ETDRS": model = ETDRSGridAnnotationFactory(grader=grader, image=ds["image_cf"]) elif data_type == "GA" or data_type == "kappa": model_macualar = PolygonAnnotationSetFactory( grader=grader, image=ds["image_cf"], name="macular" ) SinglePolygonAnnotationFactory(annotation_set=model_macualar) SinglePolygonAnnotationFactory(annotation_set=model_macualar) SinglePolygonAnnotationFactory(annotation_set=model_macualar) model_peripapillary = PolygonAnnotationSetFactory( grader=grader, image=ds["image_cf"], name="peripapillary" ) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) SinglePolygonAnnotationFactory(annotation_set=model_peripapillary) model = [model_macualar, model_peripapillary] elif data_type == "Measure": model = [ MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), MeasurementAnnotationFactory(grader=grader, image=ds["image_cf"]), ] elif data_type == "Fovea": model = BooleanClassificationAnnotationFactory( grader=grader, image=ds["image_cf"], name="fovea_affected" ) return model