Skip to content

Commit

Permalink
issue #29: Move custom exceptions to specific files
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxence Guindon committed Apr 25, 2024
1 parent b9ddbd0 commit b60950a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
12 changes: 0 additions & 12 deletions custom_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,3 @@ class ProcessInferenceResultError(Exception):

class ValidateEnvVariablesError(Exception):
pass


class ServerError(Exception):
pass


class MicroscopeQueryError(Exception):
pass


class ExifNonPresentError(Exception):
pass
45 changes: 31 additions & 14 deletions docs/Tagarno_API_objective.md → docs/tagarno-api-objective.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# 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
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.
Expand All @@ -16,40 +18,42 @@ 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
[exif](#exif-information-in-image) for more.

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)

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|
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
```
```
16 changes: 12 additions & 4 deletions microscope/microscope_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io
from PIL import Image, ExifTags

Check failure on line 8 in microscope/microscope_info.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (F401)

microscope/microscope_info.py:8:24: F401 `PIL.ExifTags` imported but unused
from dotenv import load_dotenv
from custom_exceptions import MicroscopeQueryError, ExifNonPresentError

load_dotenv()

Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_microscope_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
print(f"{key:25} : {value}")

0 comments on commit b60950a

Please sign in to comment.