From 0e3571eb69cf5bdc1ddd41ae1168619628fc3793 Mon Sep 17 00:00:00 2001
From: "Daniel.Frisinghelli" <daniel.frisinghelli@eurac.edu>
Date: Wed, 12 Aug 2020 17:34:37 +0200
Subject: [PATCH] Added a new utility function to check if an item exists in an
 enum.Enum

---
 pysegcnn/core/utils.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/pysegcnn/core/utils.py b/pysegcnn/core/utils.py
index 8be2d19..617aff1 100644
--- a/pysegcnn/core/utils.py
+++ b/pysegcnn/core/utils.py
@@ -490,3 +490,14 @@ def doy2date(year, doy):
             datetime.timedelta(days=(int(doy) - 1)))
 
     return date
+
+def item_in_enum(name, enum):
+
+    # check whether the input name exists in the enumeration
+    if name not in enum.__members__:
+        raise ValueError('{} is not in {} enumeration. Valid names are: \n {}'
+                         .format(name, enum.__name__,
+                                 '\n'.join('- {}'.format(n) for n in
+                                           enum.__members__)))
+    else:
+        return enum.__members__[name].value
-- 
GitLab