From b60950acaadb57c0172806917ebb8aa4e36ca064 Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Thu, 25 Apr 2024 15:23:25 +0000 Subject: [PATCH] issue #29: Move custom exceptions to specific files --- custom_exceptions.py | 12 ----- ..._objective.md => tagarno-api-objective.md} | 45 +++++++++++++------ microscope/microscope_info.py | 16 +++++-- tests/test_microscope_info.py | 2 +- 4 files changed, 44 insertions(+), 31 deletions(-) rename docs/{Tagarno_API_objective.md => tagarno-api-objective.md} (94%) diff --git a/custom_exceptions.py b/custom_exceptions.py index bcef01c4..48449a75 100644 --- a/custom_exceptions.py +++ b/custom_exceptions.py @@ -8,15 +8,3 @@ class ProcessInferenceResultError(Exception): class ValidateEnvVariablesError(Exception): pass - - -class ServerError(Exception): - pass - - -class MicroscopeQueryError(Exception): - pass - - -class ExifNonPresentError(Exception): - pass diff --git a/docs/Tagarno_API_objective.md b/docs/tagarno-api-objective.md similarity index 94% rename from docs/Tagarno_API_objective.md rename to docs/tagarno-api-objective.md index dadd6162..42da3bab 100644 --- a/docs/Tagarno_API_objective.md +++ b/docs/tagarno-api-objective.md @@ -1,6 +1,7 @@ # Tagarno API Objective ## Main objective for milestones 1 + The main objective of the Tagarno API integration is to be able to retrieve data from the image taken by the microscope to build a trust threshold. For example, we want to build confidence level, base on the condition and configuration a @@ -8,6 +9,7 @@ picture was taken. Having data on this will help build a confidence level in Nachet prediction. ### Opportunity Tagarno API + --- Tagarno is offering an API that can retrieve and set the config of the microscope. However, there is no function that return all the config at once. @@ -16,6 +18,7 @@ microscope. However, there is no function that return all the config at once. documentation](https://t6x6f6w2.rocketcdn.me/wp-content/uploads/2022/12/TAGARNO-Microscope-API-Documentation.pdf) ### Opportunity Picture Properties + --- When a picture is taken, a lot of metadata is record. See @@ -23,23 +26,23 @@ When a picture is taken, a lot of metadata is record. See For example : -#### Origin properties of image: +**Origin properties of image:** ![Alt text](./asssets/image/origin_properties.png) -#### Image properties: +**Image properties:** ![Alt text](./asssets/image/image_properties.png) -#### Camera properties of image: +**Camera properties of image:** ![Alt text](./asssets/image/camera_properties.png) -#### Advanced photo properties of image: +**Advanced photo properties of image:** ![Alt text](./asssets/image/advanced_photo_properties.png) -#### File properties of image: +File properties of image: ![Alt text](./asssets/image/file_properties.png) @@ -47,9 +50,10 @@ Lot's of the recording is also in the Tagarno API (White balance, contrast, brightness, etc.). If we cross references the data with Tagarno API, we could be able to only call specific Tagarno function to get a full configuration dataset. -### Tagarno API Get functions: +### Tagarno API Get functions + |Function|Configuration| ----|--- +|---|---| |getSerial|Request the serial number of the microscope| |getVersion|Request the application version of the microscope| |getFieldOfView|Request the current horizontal filed of view in micromillimiter| @@ -60,23 +64,26 @@ able to only call specific Tagarno function to get a full configuration dataset. |getExposureCompensation|Request the current exposure compensation| |getManualIris|Request the current manual Iris value| |getManualGain|Request the current manual gain value| -|getManualExposureTime|Request the current manual exposure time| +|getManualExposureTime|Request the current manual exposure time| |getContrast|Request the position of the Contrast slider in Advanced camera settings| |getSaturation|Request the position of the Saturation slider in Advanced camera settings| -|getSharpness|Request the position of the Sharpness slider in Advanced camera settings| +|getSharpness|Request the position of the Sharpness slider in Advanced camera settings| |getNoiseReduction|Request the position of the Sharpness slider in Advanced camera settings| |getWhiteBalanceCalibration|Request red and blue calibration gain values| -### Other Tagarno API utilitary functions: +### Other Tagarno API utilitary functions + |Function|params|return| ----|---|--- +|---|---|---| |captureImage|[bmp, tiff, png, jpg]|return base64 encoded image| |executeWhiteBalanceCalibration|None|Execute white balance calibration| ### Exif information in Image + --- #### What is exif? + Exif (Exchangeable image file format) a standard that specifies formats for images, sound, and ancillary tags used by digital cameras (including smartphones), scanners and other systems handling image and sound files recorded @@ -86,14 +93,18 @@ This format record information that is present in the property of a picture under details. ### Potential issue + --- + We need to carefully exchange image. If a transformation occurs during the exchange process, exif information can be lost. Therefore, we need to valide if data follow the picture when it goes through the frontend to the backend. ### List of validation + --- -- [ ] Validate that Tagarno image produce exif metadata + +- [ ] Validate that Tagarno image produce exif metadata - [x] Validate that image coming from frontend also produced exif metadata :x: - [ ] Find another way to collect metadata from image if they don't recorded exif @@ -104,9 +115,11 @@ data follow the picture when it goes through the frontend to the backend. ### Return on validation #### Validate that Targano image produce exif metadata + Ongoing #### Validate that image coming from frontend also produced exif metadata + Nachet frontend send png image to be analyze by the pipelines(list of models). Therefore, no metadata seems to be taken since PNG file doesn't store exif information. [png_documentation](https://www.w3.org/TR/png/#11Chunks) @@ -118,20 +131,24 @@ As confirmed by Taran, TIFF format is used at the laboratory and was used to train our models. #### Find another way to collect metadata from image if they don't recorded + Ongoing #### Incorporate TIFF tag into the functionnality since Tagarno image are .tiff + Ongoing #### Waiting for Jack to return email on API + It was confirm by Anders Ravnskjaer Pedersen (after Jake from Tagarno ask him) that there is no functionnality in the API that return all the microscope configuration at once. In the same email chain, Jill Gagnon confirm that we could not have an extension -on our API trial. The invoice was forwaded by Ricky to Noureddine. +on our API trial. The invoice was forwaded by Ricky to Noureddine. ### get exif function + ```mermaid sequenceDiagram actor Client @@ -149,4 +166,4 @@ sequenceDiagram Microscope Modul-)Backend: return exif_dict Backend-)Blob Storage: HTTP POST req. note over Backend, Blob Storage: Storing metadata and image path with the rest of the inference result -``` \ No newline at end of file +``` diff --git a/microscope/microscope_info.py b/microscope/microscope_info.py index ad857b5d..cbc72de7 100644 --- a/microscope/microscope_info.py +++ b/microscope/microscope_info.py @@ -7,7 +7,6 @@ import io from PIL import Image, ExifTags from dotenv import load_dotenv -from custom_exceptions import MicroscopeQueryError, ExifNonPresentError load_dotenv() @@ -17,6 +16,15 @@ params = {"id": int(uuid.uuid4())} HEADERS = {'Content-Type': 'application/json'} + +class MicroscopeQueryError(Exception): + pass + + +class ExifNonPresentError(Exception): + pass + + def post_request(MICROSCOPE_URL, method, params, headers=HEADERS): ''' This method call Tagarno's API with a specific function and return the result. @@ -48,7 +56,7 @@ def is_hex(s): ''' Validate if a value is hexadecimal - :return: bool True or False + :return: bool True or False ''' try: int(s, 16) @@ -75,7 +83,7 @@ def get_microscope_configuration(METHODS): result = int(result, 16) config[method] = result - + except MicroscopeQueryError as mqe: config[method] = None logging.error(f"MicroscopeQueryError: {mqe}") @@ -103,7 +111,7 @@ def get_picture_details(image:bytes) -> dict: # full_exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS } # return full_exif - + if __name__ == "__main__": try: config = get_microscope_configuration(METHODS) diff --git a/tests/test_microscope_info.py b/tests/test_microscope_info.py index a41cbc39..162871f4 100644 --- a/tests/test_microscope_info.py +++ b/tests/test_microscope_info.py @@ -6,4 +6,4 @@ def test_print_exif_info(): data = m.get_picture_details(path) for key, value in data.items(): - print(f"{key:25} : {value}") \ No newline at end of file + print(f"{key:25} : {value}")