Can I work with a .txt file for grdimage in gmt6?

Hello Everyone!
I have been trying to find a solution to this question. In GMT6, can i use the txt files as input to the grdimage function in gmt6? I am new to GMT6, unable to plot geographic lat lon gridded data, since its saying to use netcdf4 format for the grid.

Can anyone please tell me how can I work with a text file/ csv file data. My data has first two columns as the latitude and longitude with the third column as the data to be plotted (z value).

Please help me out!

You can not. grdimage expects a grid or an image.
If your data actually represents a grid then run xyz2grd on it to make a grid. If your data is not already on an equidistant grid then you must grid it first, e.g., via blockmean then surface, for instance. See gallery examples for some ways to do this.

Dear sir, Thank you very much for giving the reply.
Mean while, I used Pygmt to solve the problem using grdimage. I converted my lat/lon data to a xarray and the plotted the data. Everything is working perfect, however there are some horizontal lines are coming and making the figure irrelavant. I am attaching an image of the figure below, please see this.

The code I used to produce this is as follows:
data1=xr.DataArray(data=datf[0,:,:],dims=[‘x’,‘y’],coords={‘y’:np.arange(-178,182,2),‘x’:np.arange(-90,90,2)})

fig=pygmt.Figure()
pygmt.makecpt(cmap=“jet”, series=[0, 1, 0.1])
fig.grdimage(grid=data1,projection=“N0/12c”,nan_transparent=True, frame=“f”,shading=True)
fig.coast(shorelines=True,water=“snow2”)

fig.colorbar(position=‘JMR’,
frame=[“af”,“x+l#CDHWe”],
scale=1,)
fig.show()

the image that is produced is below.


The problem I noticed is with the Shorelines= True command. If I am keeping the shoreline=False, there are no horizontal lines in the plot. But for my publication-related figure, I need to have the shorelines=True option for better quality plots.

Can you please share your ideas about this, I will be much obliged.

I believe simple things are made very very complicated in GMT6. because the user should directly input the lat/ lon and z data to get the image from a simple text file.

you can use. just convert it in a grid file(.nc formate) by using ‘blockmean’ and ‘surface’ modules.

Hello Anirban,
Thank you for replying. I guess you didn’t understand my problem. I have already the data. I am giving you a screenshot of the data as below. first column- Longitude, 2nd column- Latitude, third column- data value to be plotted as a colormap.

I want to create a colormap using the grd image. However I cant use a textfile (.txt extention) to plot the data. Therefore, Can you help me how can I do that. I will be very much obliged for your help.

If you can give a simple code to show can I do the same, it will be very very useful.

It’s not true (it never was true) that to use grids in GMT they have to be in netCDF. But they need to be that, GRIDS, and the program must be able to recognize that. You can use GRIDS in lon lat z (one triplet per row) text format IF the file extension is .xyz (GDAL will step in to save the day). This is the most inefficient way of using grids, and they should be converted to any binary format, but it is possible.

Not sure why there are horizontal lines. On the command line I get no such lines:

gmt coast -R-178/182/-90/90 -JN0/15c -B -W0.25p -Ssnow2 -pdf map

but I do not know exactly what PyGMT is calling.