Using .jpg/.jpw files with pygmt?

Basic question: I have a .jpg file and an associated .jpw file. How do I use the two of these to properly project the .jpg file into my figure? If I just call grdimage with the .jpg, it shows up, but is not properly positioned or scaled.

Hi @ijbrewster, have you tried using fig.image? This might be better for JPG files than using grdimage, see https://www.pygmt.org/v0.4.0/api/generated/pygmt.Figure.image.html for more info.

I’m not sure if fig.image will read the .jpw JPEG world file properly, though the documentation at https://docs.generic-mapping-tools.org/6.2/image.html mentions it uses GDAL for raster files, so maybe? Otherwise you could set a projection/-J argument based on the contents of the .jpw file and that could position your image correctly on the map. Feel free to post the contents of the .jpw below if you need any help.

Thanks for the suggestions. I couldn’t get Image to work at all - it failed with an error of:
image [ERROR]: Option -D: Must specify image width (+w) or dpi (+r)
The impression I get from that is that it is expecting me to specify the location and size of the image, rather than getting it from the .jgw file, if so that’s a non-starter (for a one-off map that might be fine, but this is for an automated process that could produce any number of different maps)

Specifying the projection (I’m TOLD this is supposed to be UTM zone 1) results in a blank white map image with only a grid overlay - even the coast command I issue after calling grdimage doesn’t show up.

Here’s where it really gets confusing for me. Looking at the .jgw file I was provided, my understanding is that the last two lines should be the image origin (upper left pixel). Given the image and location I am working with, that should be somewhere around -178.88º longitude, 51.84º latitude. But if I assume that I was told correctly that this is UTM zone 1, the coordinates in the .jgw file translate to something like -196.3º longitude, 4.45º latitude, which doesn’t even make sense. So either I’m doing something wrong here, or I was told an incorrect projection.

The .jgw file contains these values:

1.72438213773314231
0
0
-1.72438213773314231
-1690267.51584235997870564
521710.00700893113389611

And currently the test code I am running is the following (has gone through many iterations):

    bounds = [
        -178.88,
        -178.72,
        51.73,
        51.84
    ]

    fig = pygmt.Figure()
    fig.basemap(projection="U1U/8i", region=bounds, frame=('WeSn', 'afg'))
    fig.grdimage("May_31_2021_Sent2_SR.jpg")
    fig.coast(rivers = 'r/2p,#0000FF', water = "#00FFFF", resolution = "f")
    fig.show(method = "external", width = 100, dpi = 100)

Ok, I’ve made some progress here. After digging into things more deeply, I discovered that the projection on the file was NOT UTM, as I was told, but actually “Alaska Albers”, EPSG:3338. Armed with that information, I was then able to use gdalwarp to convert to a geotiff in lat/lon coordinates, which then displayed properly using grdimage

This is all good, and I can work with that, but I would still be interested in knowing if there was a way to use the .jpg/.jpw files directly. So far I have not had any luck with that, even when specifying projection in the grdimage or image call.