How to give Datafile Path?

Hello,

I’m trying to follow the tutorial of the site (Plotting data points) but with my own data:“Massin_M4_clean”. I work on jupyter lab.
However at the first step, when you have to provide access to these datasets through the pygmt.datasets package. The following message is displayed:

import pygmt
data = pygmt.datasets.Massin_M4_clean()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1964/3180419661.py in <module>
     21 
     22 
---> 23 data = pygmt.datasets.Massin_M4_clean()
     24 
     25 

AttributeError: module 'pygmt.datasets' has no attribute 'Massin_M4_clean'

So I think it must be a path problem, pygmt can’t find the file “Massin_M4_clean”. I look for the pygmt command to add a path file and I find the pygmt.which module.
When I run this command :

pygmt.which(Massin_M4_clean.txt,Users/burlotr)

NameError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1964/1913713950.py in <module>
     16 
     17 
---> 18 pygmt.which(Massin_M4_clean.txt,Users/burlotr)
     19 #pygmt.which(Massin_M4_clean)
     20 #pygmt.which.Massin_M4_clean.dat

NameError: name 'Massin_M4_clean' is not defined

Does anyone know the solution? :grin:

I think the “Massin_M4_clean” data is not packaged with PyGMT/GMT, if this data is provided by yourself, you need read the file directly via Pandas or just the raw open and read python function.

Thank you for your answer @leeyupeng.

I managed to import my data in the following way:

import pygmt
import pandas as pd
from pygmt.src import which

def Massin_M4_clean():
    
    fname = which("Massin_M4_clean.dat")
    data = pd.read_csv(fname, header=1, sep=r"\s+")
    data.columns = [
        "year",
        "latitude",
        "longitude",
        "depth_km",
        "magnitude",
    ]
    return data

data = pandas.DataFrame(Massin_M4_clean())

print (data)

pygmt import

It’s great!