How to use the pygmt.exceptions.GMTCLibError function in pygmt

To help you get started, we’ve selected a few pygmt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GenericMappingTools / pygmt / pygmt / clib / session.py View on Github external
0.

        """
        c_put_matrix = self.get_libgmt_func(
            "GMT_Put_Matrix",
            argtypes=[ctp.c_void_p, ctp.c_void_p, ctp.c_uint, ctp.c_int, ctp.c_void_p],
            restype=ctp.c_int,
        )

        gmt_type = self._check_dtype_and_dim(matrix, ndim=2)
        matrix_pointer = matrix.ctypes.data_as(ctp.c_void_p)
        status = c_put_matrix(
            self.session_pointer, dataset, gmt_type, pad, matrix_pointer
        )
        if status != 0:
            raise GMTCLibError("Failed to put matrix of type {}.".format(matrix.dtype))
github GenericMappingTools / pygmt / pygmt / clib / session.py View on Github external
)

        family_int = self._parse_constant(family, valid=FAMILIES, valid_modifiers=VIAS)
        geometry_int = self._parse_constant(geometry, valid=GEOMETRIES)
        status = c_write_data(
            self.session_pointer,
            family_int,
            self["GMT_IS_FILE"],
            geometry_int,
            self[mode],
            (ctp.c_double * 6)(*wesn),
            output.encode(),
            data,
        )
        if status != 0:
            raise GMTCLibError("Failed to write dataset to '{}'".format(output))
github GenericMappingTools / pygmt / pygmt / clib / session.py View on Github external
# and put_matrix.
        data_ptr = c_create_data(
            self.session_pointer,
            family_int,
            geometry_int,
            mode_int,
            dim,
            ranges,
            inc,
            registration_int,
            self._parse_pad(family, kwargs),
            None,
        )

        if data_ptr is None:
            raise GMTCLibError("Failed to create an empty GMT data pointer.")

        return data_ptr
github GenericMappingTools / pygmt / pygmt / clib / session.py View on Github external
status = c_open_virtualfile(
            self.session_pointer, family_int, geometry_int, direction_int, data, buff
        )

        if status != 0:
            raise GMTCLibError("Failed to create a virtual file.")

        vfname = buff.value.decode()

        try:
            yield vfname
        finally:
            status = c_close_virtualfile(self.session_pointer, vfname.encode())
            if status != 0:
                raise GMTCLibError("Failed to close virtual file '{}'.".format(vfname))
github GenericMappingTools / pygmt / pygmt / exceptions.py View on Github external
"""


class GMTOSError(GMTError):
    """
    Unsupported operating system.
    """


class GMTCLibError(GMTError):
    """
    Error encountered when running a function from the GMT shared library.
    """


class GMTCLibNotFoundError(GMTCLibError):
    """
    Could not find the GMT shared library.
    """


class GMTCLibNoSessionError(GMTCLibError):
    """
    Tried to access GMT API without a currently open GMT session.
    """


class GMTInvalidInput(GMTError):
    """
    Raised when the input of a function/method is invalid.
    """
github GenericMappingTools / pygmt / pygmt / clib / session.py View on Github external
# flush to make sure the messages are printed even if we have a
            # crash.
            print(message, file=sys.stderr, flush=True)
            return 0

        # Need to store a copy of the function because ctypes doesn't and it
        # will be garbage collected otherwise
        self._print_callback = print_func

        padding = self["GMT_PAD_DEFAULT"]
        session_type = self["GMT_SESSION_EXTERNAL"]

        session = c_create_session(name.encode(), padding, session_type, print_func)

        if session is None:
            raise GMTCLibError(
                "Failed to create a GMT API session:\n{}".format(self._error_message)
            )

        self.session_pointer = session
github GenericMappingTools / pygmt / pygmt / clib / session.py View on Github external
If the parameter doesn't exist.

        """
        c_get_default = self.get_libgmt_func(
            "GMT_Get_Default",
            argtypes=[ctp.c_void_p, ctp.c_char_p, ctp.c_char_p],
            restype=ctp.c_int,
        )

        # Make a string buffer to get a return value
        value = ctp.create_string_buffer(10000)

        status = c_get_default(self.session_pointer, name.encode(), value)

        if status != 0:
            raise GMTCLibError(
                "Error getting default value for '{}' (error code {}).".format(
                    name, status
                )
            )

        return value.value.decode()