"""PyGMT is a library for processing geospatial and geophysical data and makingpublication quality maps and figures. It provides a Pythonic interface for theGeneric Mapping Tools (GMT), a command-line program widely used in the EarthSciences. Besides making GMT more accessible to new users, PyGMT aims toprovide integration with the PyData ecosystem as well as support for richdisplay in Jupyter notebooks.Main Features-------------Here are just a few of the things that PyGMT does well: - Easy handling of individual types of data like Cartesian, geographic, or time-series data. - Processing of (geo)spatial data including gridding, filtering, and masking - Allows plotting of a large spectrum of objects on figures including lines, vectors, polygons, and symbols (pre-defined and customized) - Generate publication-quality illustrations and make animations"""importatexitas_atexitfrompkg_resourcesimportget_distribution# Import modules to make the high-level GMT Python APIfrompygmtimportdatasetsfrompygmt.accessorsimportGMTDataArrayAccessorfrompygmt.figureimportFigure,set_displayfrompygmt.session_managementimportbeginas_beginfrompygmt.session_managementimportendas_endfrompygmt.srcimport(blockmean,blockmedian,config,grd2cpt,grdclip,grdcut,grdfill,grdfilter,grdgradient,grdinfo,grdlandmask,grdsample,grdtrack,info,makecpt,surface,which,x2sys_cross,x2sys_init,xyz2grd,)# Get semantic version through setuptools-scm__version__=f'v{get_distribution("pygmt").version}'# e.g. v0.1.2.dev3+g0ab3cd78__commit__=__version__.split("+g")[-1]if"+g"in__version__else""# 0ab3cd78# Start our global modern mode session_begin()# Tell Python to run _end when shutting down_atexit.register(_end)
[docs]defprint_clib_info():""" Print information about the GMT shared library that we can find. Includes the GMT version, default values for parameters, the path to the ``libgmt`` shared library, and GMT directories. """frompygmt.clibimportSessionlines=["GMT library information:"]withSession()asses:forkeyinsorted(ses.info):lines.append(" {}: {}".format(key,ses.info[key]))print("\n".join(lines))
[docs]defshow_versions():""" Prints various dependency versions useful when submitting bug reports. This includes information about: - PyGMT itself - System information (Python version, Operating System) - Core dependency versions (Numpy, Pandas, Xarray, etc) - GMT library information """importimportlibimportplatformimportsubprocessimportsysdef_get_module_version(modname):""" Get version information of a Python module. """try:ifmodnameinsys.modules:module=sys.modules[modname]else:module=importlib.import_module(modname)try:returnmodule.__version__exceptAttributeError:returnmodule.versionexceptImportError:returnNonedef_get_ghostscript_version():""" Get ghostscript version. """os_name=sys.platformifos_name.startswith(("linux","freebsd","darwin")):cmds=["gs"]elifos_name=="win32":cmds=["gswin64c.exe","gswin32c.exe"]else:returnNoneforgs_cmdincmds:try:version=subprocess.check_output([gs_cmd,"--version"],universal_newlines=True).strip()returnversionexceptFileNotFoundError:continuereturnNonedef_get_gmt_version():""" Get GMT version. """try:version=subprocess.check_output(["gmt","--version"],universal_newlines=True).strip()returnversionexceptFileNotFoundError:returnNonesys_info={"python":sys.version.replace("\n"," "),"executable":sys.executable,"machine":platform.platform(),}deps=["numpy","pandas","xarray","netCDF4","packaging"]print("PyGMT information:")print(f" version: {__version__}")print("System information:")forkey,valinsys_info.items():print(f" {key}: {val}")print("Dependency information:")formodnameindeps:print(f" {modname}: {_get_module_version(modname)}")print(f" ghostscript: {_get_ghostscript_version()}")print(f" gmt: {_get_gmt_version()}")print_clib_info()
[docs]deftest(doctest=True,verbose=True,coverage=False,figures=True):""" Run the test suite. Uses `pytest <http://pytest.org/>`__ to discover and run the tests. If you haven't already, you can install it with `conda <http://conda.pydata.org/>`__ or `pip <https://pip.pypa.io/en/stable/>`__. Parameters ---------- doctest : bool If ``True``, will run the doctests as well (code examples that start with a ``>>>`` in the docs). verbose : bool If ``True``, will print extra information during the test run. coverage : bool If ``True``, will run test coverage analysis on the code as well. Requires ``pytest-cov``. figures : bool If ``True``, will test generated figures against saved baseline figures. Requires ``pytest-mpl`` and ``matplotlib``. Raises ------ AssertionError If pytest returns a non-zero error code indicating that some tests have failed. """importpytestshow_versions()package=__name__args=[]ifverbose:args.append("-vv")ifcoverage:args.append("--cov={}".format(package))args.append("--cov-report=term-missing")ifdoctest:args.append("--doctest-modules")iffigures:args.append("--mpl")args.append("--pyargs")args.append(package)status=pytest.main(args)assertstatus==0,"Some tests have failed."