|
4 | 4 |
|
5 | 5 | Generally, PyGMT accepts two different types of data inputs: tables and grids.
|
6 | 6 |
|
7 |
| -- A table is a 2-D array with rows and columns. Each column represents a |
8 |
| - different variable (e.g., *x*, *y* and *z*) and each row represents a |
9 |
| - different record. |
10 |
| -- A grid is a 2-D array of data that is regularly spaced in the x and y |
11 |
| - directions (or longitude and latitude). |
12 |
| -
|
13 |
| -In this tutorial, we'll focus on working with table inputs, and cover grid |
14 |
| -inputs in a separate tutorial. |
15 |
| -
|
16 |
| -PyGMT supports a variety of table input types that allow you to work with data |
17 |
| -in a format that suits your needs. In this tutorial, we'll explore the |
18 |
| -different table input types available in PyGMT and provide examples for each. |
19 |
| -By understanding the different table input types, you can choose the one that |
20 |
| -best fits your data and analysis needs, and work more efficiently with PyGMT. |
| 7 | +- A table is a 2-D array with rows and columns. Each column represents a different |
| 8 | + variable (e.g., *x*, *y* and *z*) and each row represents a different record. |
| 9 | +- A grid is a 2-D array of data that is regularly spaced in the x and y directions (or |
| 10 | + longitude and latitude). |
| 11 | +
|
| 12 | +In this tutorial, we'll focus on working with table inputs, and cover grid inputs in a |
| 13 | +separate tutorial. |
| 14 | +
|
| 15 | +PyGMT supports a variety of table input types that allow you to work with data in a |
| 16 | +format that suits your needs. In this tutorial, we'll explore the different table input |
| 17 | +types available in PyGMT and provide examples for each. By understanding the different |
| 18 | +table input types, you can choose the one that best fits your data and analysis needs, |
| 19 | +and work more efficiently with PyGMT. |
21 | 20 | """
|
22 | 21 |
|
23 | 22 | # %%
|
|
32 | 31 | # ASCII table file
|
33 | 32 | # ----------------
|
34 | 33 | #
|
35 |
| -# Most PyGMT functions/methods that accept table input data have a ``data`` |
36 |
| -# parameter. The easiest way to provide table input data to PyGMT is by |
37 |
| -# specifying the file name of an ASCII table (e.g., ``data="input_data.dat"``). |
38 |
| -# This is useful when your data is stored in a separate text file. |
| 34 | +# Most PyGMT functions/methods that accept table input data have a ``data`` parameter. |
| 35 | +# The easiest way to provide table input data to PyGMT is by specifying the file name of |
| 36 | +# an ASCII table (e.g., ``data="input_data.dat"``). This is useful when your data is |
| 37 | +# stored in a separate text file. |
39 | 38 |
|
40 | 39 | # Create an example file with 3 rows and 2 columns
|
41 | 40 | data = np.array([[1.0, 2.0], [5.0, 4.0], [8.0, 3.0]])
|
|
51 | 50 | Path("input_data.dat").unlink()
|
52 | 51 |
|
53 | 52 | # %%
|
54 |
| -# Besides a plain string to a table file, the following variants are also |
55 |
| -# accepted: |
| 53 | +# Besides a plain string to a table file, the following variants are also accepted: |
56 | 54 | #
|
57 | 55 | # - A :class:`pathlib.Path` object.
|
58 | 56 | # - A full URL. PyGMT will download the file to the current directory first.
|
59 |
| -# - A file name prefixed with ``@`` (e.g., ``data="@input_data.dat"``), which |
60 |
| -# is a special syntax in GMT to indicate that the file is a remote file |
61 |
| -# hosted on the GMT data server. |
| 57 | +# - A file name prefixed with ``@`` (e.g., ``data="@input_data.dat"``), which is a |
| 58 | +# special syntax in GMT to indicate that the file is a remote file hosted on the GMT |
| 59 | +# data server. |
| 60 | +# |
| 61 | +# Additionally, PyGMT also supports a list of file names, :class:`pathlib.Path` objects, |
| 62 | +# URLs, or remote files, to provide more flexibility in specifying input files. |
62 | 63 |
|
63 | 64 | # %%
|
64 | 65 | # 2-D array: `list`, `numpy.ndarray`, and `pandas.DataFrame`
|
|
92 | 93 | # -------------------------------
|
93 | 94 | #
|
94 | 95 | # If you're working with geospatial data, you can read your data as a
|
95 |
| -# :class:`geopandas.GeoDataFrame` object and pass it to the ``data`` |
96 |
| -# parameter. This is useful if your data is stored in a geospatial data format |
97 |
| -# (e.g., GeoJSON, etc.) that GMT and PyGMT do not support natively. |
| 96 | +# :class:`geopandas.GeoDataFrame` object and pass it to the ``data`` parameter. This is |
| 97 | +# useful if your data is stored in a geospatial data format (e.g., GeoJSON, etc.) that |
| 98 | +# GMT and PyGMT do not support natively. |
98 | 99 |
|
99 | 100 | # Example GeoDataFrame
|
100 | 101 | gdf = gpd.GeoDataFrame(
|
|
114 | 115 | # Scalar values or 1-D arrays
|
115 | 116 | # ---------------------------
|
116 | 117 | #
|
117 |
| -# In addition to the ``data`` parameter, some PyGMT functions/methods also |
118 |
| -# provide individual parameters (e.g., ``x`` and ``y`` for data coordinates) |
119 |
| -# which allow you to specify the data. These parameters accept individual |
120 |
| -# scalar values or 1-D arrays (lists or 1-D numpy arrays). |
| 118 | +# In addition to the ``data`` parameter, some PyGMT functions/methods also provide |
| 119 | +# individual parameters (e.g., ``x`` and ``y`` for data coordinates) which allow you to |
| 120 | +# specify the data. These parameters accept individual scalar values or 1-D arrays |
| 121 | +# (lists or 1-D numpy arrays). |
121 | 122 |
|
122 | 123 | fig = pygmt.Figure()
|
123 | 124 | fig.basemap(region=[0, 10, 0, 5], projection="X10c/5c", frame=True)
|
|
139 | 140 | # Conclusion
|
140 | 141 | # ----------
|
141 | 142 | #
|
142 |
| -# In PyGMT, you have the flexibility to provide data in various table input |
143 |
| -# types, including file names, 2-D arrays (2-D :class:`list`, |
144 |
| -# :class:`numpy.ndarray`, :class:`pandas.DataFrames`), scalar values or a |
145 |
| -# series of 1-D arrays, and :class:`geopandas.GeoDataFrame`. Choose the input |
146 |
| -# type that best suits your data source and analysis requirements. |
| 143 | +# In PyGMT, you have the flexibility to provide data in various table input types, |
| 144 | +# including file names, 2-D arrays (2-D :class:`list`, :class:`numpy.ndarray`, |
| 145 | +# :class:`pandas.DataFrames`), scalar values or a series of 1-D arrays, and |
| 146 | +# :class:`geopandas.GeoDataFrame`. Choose the input type that best suits your data |
| 147 | +# source and analysis requirements. |
0 commit comments