From da0db0a4de712c588c39bbabb67f375d390a57fe Mon Sep 17 00:00:00 2001 From: Chris Schnaufer Date: Wed, 23 Sep 2020 17:00:46 -0700 Subject: [PATCH 1/5] Changing to species --- .github/workflows/docker_test_check.sh | 2 +- test_data/experiment.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker_test_check.sh b/.github/workflows/docker_test_check.sh index b81c12d..7ee279b 100755 --- a/.github/workflows/docker_test_check.sh +++ b/.github/workflows/docker_test_check.sh @@ -36,7 +36,7 @@ BEGIN { FPAT = "([^,]+)|(\"[^\"]+\")" } { - if ($1 != "germplasmName") { # Skipping the header line + if ($1 != "species") { # Skipping the header line printf("(%s %s %s %s %s %s %s %s %s %s %s)\n", $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) } } diff --git a/test_data/experiment.yaml b/test_data/experiment.yaml index efae358..36873bb 100755 --- a/test_data/experiment.yaml +++ b/test_data/experiment.yaml @@ -3,7 +3,7 @@ pipeline: studyName: 'S7_20181011' season: 'S7_20181011' - germplasmName: Sorghum bicolor + species: Sorghum bicolor collectingSite: Maricopa observationTimeStamp: '2018-10-11T13:01:02-08:00' From 1b78ea04c84382f782251097b7db29c86b002e2c Mon Sep 17 00:00:00 2001 From: Chris Schnaufer Date: Wed, 30 Sep 2020 12:33:10 -0700 Subject: [PATCH 2/5] Added handling of alpha channel --- algorithm_rgb.py | 53 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/algorithm_rgb.py b/algorithm_rgb.py index 33a64c2..4b0d6ef 100644 --- a/algorithm_rgb.py +++ b/algorithm_rgb.py @@ -140,14 +140,22 @@ def percent_green(pxarray: np.ndarray) -> float: Returns the percentage of an image that is green, which can be used to identify plant cover """ - # redness value - red = np.sum(pxarray[:, :, 0]) - - # greenness value - green = np.sum(pxarray[:, :, 1]) - - # blueness value - blue = np.sum(pxarray[:, :, 2]) + if pxarray.shape[2] < 4: + # Get redness, greenness, and blueness values + red = np.sum(pxarray[:, :, 0]) + green = np.sum(pxarray[:, :, 1]) + blue = np.sum(pxarray[:, :, 2]) + else: + # Handle Alpha channel masking + # Get redness, greenness, and blueness values + alpha_mask = np.where(pxarray[:, :, 3] == 0, 1, 0) # Convert alpha channel to numpy.ma format + channel_masked = np.ma.array(pxarray[:, :, 0], mask=alpha_mask) + red = np.ma.sum(channel_masked) + channel_masked = np.ma.array(pxarray[:, :, 1], mask=alpha_mask) + green = np.ma.sum(channel_masked) + channel_masked = np.ma.array(pxarray[:, :, 2], mask=alpha_mask) + blue = np.ma.sum(channel_masked) + del channel_masked return round(green / (red + green + blue), 2) @@ -156,16 +164,24 @@ def get_red_green_blue_averages(pxarray: np.ndarray) -> tuple: """ Returns the average red, green, and blue values in a pxarray object """ - # redness value - red = np.average(pxarray[:, :, 0]) - - # greenness value - green = np.average(pxarray[:, :, 1]) - - # blueness value - blue = np.average(pxarray[:, :, 2]) - - return (red, green, blue) + if pxarray.shape[2] < 4: + # Get redness, greenness, and blueness values + red = np.average(pxarray[:, :, 0]) + green = np.average(pxarray[:, :, 1]) + blue = np.average(pxarray[:, :, 2]) + else: + # Handle Alpha channel masking + # Get redness, greenness, and blueness values + alpha_mask = np.where(pxarray[:, :, 3] == 0, 1, 0) # Convert alpha channel to numpy.ma format + channel_masked = np.ma.array(pxarray[:, :, 0], mask=alpha_mask) + red = np.ma.average(channel_masked) + channel_masked = np.ma.array(pxarray[:, :, 1], mask=alpha_mask) + green = np.ma.average(channel_masked) + channel_masked = np.ma.array(pxarray[:, :, 2], mask=alpha_mask) + blue = np.ma.average(channel_masked) + del channel_masked + + return red, green, blue def calculate(pxarray: np.ndarray) -> list: @@ -175,7 +191,6 @@ def calculate(pxarray: np.ndarray) -> list: Return: Returns a list of the calculated values from the """ - return_list = [excess_greenness_index(pxarray), green_leaf_index(pxarray), cive(pxarray), normalized_difference_index(pxarray), excess_red(pxarray), exgr(pxarray), combined_indices_1(pxarray), combined_indices_2(pxarray), vegetative_index(pxarray), From adce5d53b83e5383aa5883309174b03571b33e7a Mon Sep 17 00:00:00 2001 From: Chris Schnaufer Date: Wed, 30 Sep 2020 13:35:13 -0700 Subject: [PATCH 3/5] Added clarification to comment --- algorithm_rgb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/algorithm_rgb.py b/algorithm_rgb.py index 4b0d6ef..12cd603 100644 --- a/algorithm_rgb.py +++ b/algorithm_rgb.py @@ -148,7 +148,7 @@ def percent_green(pxarray: np.ndarray) -> float: else: # Handle Alpha channel masking # Get redness, greenness, and blueness values - alpha_mask = np.where(pxarray[:, :, 3] == 0, 1, 0) # Convert alpha channel to numpy.ma format + alpha_mask = np.where(pxarray[:, :, 3] == 0, 1, 0) # Convert alpha channel to numpy.ma acceptable format channel_masked = np.ma.array(pxarray[:, :, 0], mask=alpha_mask) red = np.ma.sum(channel_masked) channel_masked = np.ma.array(pxarray[:, :, 1], mask=alpha_mask) @@ -172,7 +172,7 @@ def get_red_green_blue_averages(pxarray: np.ndarray) -> tuple: else: # Handle Alpha channel masking # Get redness, greenness, and blueness values - alpha_mask = np.where(pxarray[:, :, 3] == 0, 1, 0) # Convert alpha channel to numpy.ma format + alpha_mask = np.where(pxarray[:, :, 3] == 0, 1, 0) # Convert alpha channel to numpy.ma acceptable format channel_masked = np.ma.array(pxarray[:, :, 0], mask=alpha_mask) red = np.ma.average(channel_masked) channel_masked = np.ma.array(pxarray[:, :, 1], mask=alpha_mask) From f34fa872370e621252554cec325a3079f0f99df0 Mon Sep 17 00:00:00 2001 From: Chris Schnaufer Date: Wed, 30 Sep 2020 16:39:45 -0700 Subject: [PATCH 4/5] Updating test check for species terminology change --- .github/workflows/docker_test_check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker_test_check.sh b/.github/workflows/docker_test_check.sh index b81c12d..7ee279b 100755 --- a/.github/workflows/docker_test_check.sh +++ b/.github/workflows/docker_test_check.sh @@ -36,7 +36,7 @@ BEGIN { FPAT = "([^,]+)|(\"[^\"]+\")" } { - if ($1 != "germplasmName") { # Skipping the header line + if ($1 != "species") { # Skipping the header line printf("(%s %s %s %s %s %s %s %s %s %s %s)\n", $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) } } From 9f960f3d2280059891b60c939b33e0c82c2d5b54 Mon Sep 17 00:00:00 2001 From: Chris Schnaufer Date: Wed, 30 Sep 2020 16:44:55 -0700 Subject: [PATCH 5/5] Updating test check --- .github/workflows/docker_test_check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker_test_check.sh b/.github/workflows/docker_test_check.sh index 7ee279b..8028cd9 100755 --- a/.github/workflows/docker_test_check.sh +++ b/.github/workflows/docker_test_check.sh @@ -37,7 +37,7 @@ BEGIN { } { if ($1 != "species") { # Skipping the header line - printf("(%s %s %s %s %s %s %s %s %s %s %s)\n", $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) + printf("(%s %s %s %s %s %s %s %s %s %s %s)\n", $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) } } END {