def parse_value(self, value):
        if isinstance(value, list):
            value = np.array(value)

        if isinstance(value, bool):
            if self.dtype == np.bool:
                try:
                    self.__value = np.bool(value)

                except:
                    raise Exception('Util2d:could not cast ' +
                                    'boolean value to type "np.bool": ' +
                                    str(value))
            else:
                raise Exception('Util2d:value type is bool, ' +
                                ' but dtype not set as np.bool')
        elif isinstance(value, str):
            if os.path.exists(value):
                self.__value = value
                return
            elif self.dtype == np.int:
                try:
                    self.__value = int(value)
                except:
                    raise Exception("Util2d error: str not a file and " +
                                    "couldn't be cast to int: {0}".format(value))

            else:
                try:
                    self.__value = float(value)
                except:
                    raise Exception("Util2d error: str not a file and " +
                                    "couldn't be cast to float: {0}".format(value))

        elif np.isscalar(value):
            if self.dtype == np.int:
                try:
                    self.__value = np.int(value)
                except:
                    raise Exception('Util2d:could not cast scalar ' +
                                    'value to type "int": ' + str(value))
            elif self.dtype == np.float32:
                try:
                    self.__value = np.float32(value)
                except:
                    raise Exception('Util2d:could not cast ' +
                                    'scalar value to type "float": ' +
                                    str(value))

        elif isinstance(value, np.ndarray):
            # if value is 3d, but dimension 1 is only length 1,
            # then drop the first dimension
            if len(value.shape) == 3 and value.shape[0] == 1:
                value = value[0]
            if self.shape != value.shape:
                raise Exception('Util2d:self.shape: ' + str(self.shape) +
                                ' does not match value.shape: ' +
                                str(value.shape))
            if self.dtype != value.dtype:
                value = value.astype(self.dtype)
            self.__value = value

        else:
            raise Exception('Util2d:unsupported type in util_array: ' +
                            str(type(value)))
parses and casts the raw value into an acceptable format for __value
dataset/ETHPy150Open modflowpy/flopy/flopy/utils/util_array.py/Util2d.parse_value