# Drapping a grid file over

**URL:** <https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718>\
**Category:** PyGMT Q&A\
**Created:** [February 5, 2025, 1:46pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718 "2025-02-05T13:46:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![earthistics](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@earthistics](https://forum.generic-mapping-tools.org/u/earthistics)\
**Post date:** [February 5, 2025, 1:46pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/1 "2025-02-05T13:46:39Z")

</div>

Hello,

I’m trying to drape a grid (.tif) over a topographic grid to visualize it in 2D. However, I’m facing this issue:

→ if I use `grdview` I get this error message:

```auto
grdview [ERROR]: Using this data type (Float64) is not implemented
grdview (gmtapi_import_image): Bad measurement unit. Choose among c|i|p [/data_wgs84.tif]
[Session pygmt-session (20)]: Error returned from GMT API: GMT_IMAGE_READ_ERROR (22)
[Session pygmt-session (20)]: Error returned from GMT API: GMT_IMAGE_READ_ERROR (22)

```

→ But if I use `grdimage`, it successfully generates the plot (using the same .tif file).

Since I can’t obtain any plot with `grdview` to compare with the obtain with `grdimage`, I’m wondering what could be the key difference between `grdview` and `grdimage` in this case. How could I fix the issue when plotting with `grdview`?

This is the way I’m trying to use `grdview`:

```auto
region=[lon_min, lon_max, lat_min, lat_max]
grid_map = pygmt.datasets.load_earth_relief(resolution="01s", region=region)

data_file = "/data_wgs84.tif"

fig = pygmt.Figure()

pygmt.makecpt(cmap='jet', series=[-1.99, 1.99, 0.01])
shade1 = pygmt.grdgradient(grid=grid_map, azimuth="270", normalize="e0.6")
fig.grdimage(grid=grid_map,cmap="gray",shading=shade1)
fig.coast(water='lightblue')
pygmt.makecpt(cmap="gray", series=[0, 3500, 100])
#Draping data over topography
fig.grdview(
    projection="M15c",
    region=region,
    grid=grid_map,
    drapegrid=data_file,
    cmap="jet",
    transparency=25,
    surftype="s",
    frame="a0.2f0.1"
)

pygmt.makecpt(cmap='jet', series=[-1.99, 1.99, 0.01])
fig.colorbar(frame=["xa0.5+lEast", "y+lcm"])

```

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 5, 2025, 4:14pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/2 "2025-02-05T16:14:13Z")

</div>

This is more likely a GMT than a PyGMT thing, but not 100% sure. From error message, it’s trying to read the tif image instead of as a grid. So don’t know.

In general GMT doesn’t like Float64’s (for our field they are mostly a waste and too much work to transparently deal with both float types, 32 & 64, in the code), but some attempts are done to be at least be able to ingest them.

Can you post a **small** example of that .tif file? Use GDAL to cut a chunk of it. You can also try to convert the .tif to 32 bits and see if it works in your case.

---

<div class="post-metadata">

**Author:** ![earthistics](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@earthistics](https://forum.generic-mapping-tools.org/u/earthistics)\
**Post date:** [February 5, 2025, 4:44pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/3 "2025-02-05T16:44:05Z")

</div>

> [@Joaquim](#):
>
> convert the .tif to 32 bits

Thanks for replying. I have converted the .tif file to 32 bits and it still does not work (same error message:

```auto
grdview [ERROR]: Using this data type (Float32) is not implemented
grdview (gmtapi_import_image): Bad measurement unit. Choose among c|i|p

```

)  
Here is a snippet of the file:  
[chunk\_wgs84\_f32.tif](https://forum.generic-mapping-tools.org/uploads/short-url/6UeajY0f0c76lA1hTepyqw6UzSx.tif) (78.4 KB)  
Thanks for taking a look at this.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 5, 2025, 7:01pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/4 "2025-02-05T19:01:02Z")

</div>

Thanks. That shows some GMT bugs and dislike.

- dislike. GMT does not like a grid with a .tif extension used as `drapegrid`. We have to convert it to nc
- `grdview` is bugged when reading a remote @earth\_relief file. Must get it first into a file (remote mechanism does a lot of gymns to get the/assemble the data.

That found, this (plain GMR CLI) works.

```auto
grdconvert chunk_wgs84_f32.tif -Gchunk_wgs84_f32.grd
grdcut @earth_relief_01s -Rchunk_wgs84_f32.grd -Gt.grd
grd2cpt chunk_wgs84_f32.grd > lixo.cpt
gmt grdview t.grd -JX10 -p210/30 -JZ5 -Qi100 -Ba -Bza -Gchunk_wgs84_f32.grd -Clixo.cpt -png lixo

```

 ![lixo](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/a/a4a746cacc80cb668c8e815858edc586bf4f8449.png)

---

<div class="post-metadata">

**Author:** ![earthistics](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@earthistics](https://forum.generic-mapping-tools.org/u/earthistics)\
**Post date:** [February 5, 2025, 8:20pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/5 "2025-02-05T20:20:40Z")

</div>

Thanks for having a look at this. Is there any way to convert the .tif file to a .grd one with PyGMT? I didn’t find the PyGMT version of `grdconvert`.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 5, 2025, 10:06pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/6 "2025-02-05T22:06:20Z")

</div>

Having PyGMT means that you have GMT as well but not sure how to get access to it (I’m no PyGMT user). An easy alternative, since you already used it, is to convert the file with GDAL. Note that `.grd` is just a very old habit (in GMT and other latitudes) to name the extension of netCDF grids. If the file gets named `.nc` it work equally well.

---

<div class="post-metadata">

**Author:** ![earthistics](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@earthistics](https://forum.generic-mapping-tools.org/u/earthistics)\
**Post date:** [February 6, 2025, 11:45am UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/7 "2025-02-06T11:45:32Z")

</div>

Thank you! I converted it to a `.nc` file and now it works even without cutting the `@earth_relief` file. However, there’s another issue. I have to handle with NaN values in the drape file and ensure they are transparent, allowing the underlying topography to remain visible. However, it doesn’t work well even when using “c” for the parameter `surftype` according to the documentation of `pygmt.Figure.grdview` as you can see:

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/d/d3464ad1c4f38faddb960af7dc220bfd6c9051fb.jpeg)

I’m using `grdview` like this:

```auto
fig.grdview(
    grid=grid_map,
    region=region,
    projection="M12c",  
    frame=["af", "zaf+lElevation (m a.s.l.)"],
    drapegrid=cleaned_grid,
    cmap="disp.cpt",
    zsize="2c",
    surftype="i800",
    shading=True,
    plane="-3000+ggrey",
    interpolation="b",
    perspective=[-200, 35],
    contourpen="0.1p"
)

```

And this is how it looks without the draped file:

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/c/c2b573180839430483383ad6458a18fff92b6fa9.png)

I would appreciate any hint to solve this issue. Thanks!

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 6, 2025, 11:57pm UTC](https://forum.generic-mapping-tools.org/t/drapping-a-grid-file-over/5718/8 "2025-02-06T23:57:29Z")

</div>

Not present an immediate answer, and, as I referred PyGMT examples are not for me but search the docs (grdimage is better for that) about transparency modes.
