ClarkCGA / UDef-ARP

UDef-ARP was developed by Clark Labs, in collaboration with TerraCarbon, to facilitate implementation of the Verra tool, VT0007 Unplanned Deforestation Allocation (UDef-A).
GNU General Public License v3.0
25 stars 14 forks source link

Added (UDef-ARP.py) binary map checker functions #16

Closed YaoTingYao closed 7 months ago

YaoTingYao commented 7 months ago

Added a binary map checker to automatically check whether the input data is a binary map or not. After the function returns False, an error message will show up.

A binary map (boolean map) is characterized by a data type of either byte or integer, with minimum and maximum values set to 0 and 1. The only exception is when the data type is real, with minimum and maximum values precisely at 0.0000000 and 1.0000000 and would need to check pixel values.

The validation logic is as follows:

  1. If data type is byte or integer and min is 0 and max is 1, it returns True.

  2. If data type is real and min is 0 and max is 1, it executes a function to check the number of unique values. Because the function only run under this condition and break when the unique value larger than 2, it executed fast in my testing. (1) If the unique number is 2 [0,1], return True. (2) If the number is larger than 2, break and return False.

  3. For any other scenario, it returns False.

image

YaoTingYao commented 7 months ago

Hi @tawoodard, I appreciate your valuable insights on the binary check validation logic. Please review the PR and merge it when you find it convenient? Cheers!

tawoodard commented 7 months ago

I thought about it & realized we can optimize later for repeated code blocks. Sorry for the delay. I'll confirm the merge now.

YaoTingYao commented 7 months ago

Hi @tawoodard, thanks so much for your suggestions on improvements. I initially designed a separate class for each related UI file, which resulted in repetitive functions across the classes. Following your advice, I've relocated the binary check functions into a distinct class and called it by each UI class. It worked smoothly. I will restructure all other repetitive functions and create another PR accordingly. Cheers!