Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the geographic global xarray.DataArray grid used in grdimage tests #3359

Closed
wants to merge 2 commits into from

Conversation

seisman
Copy link
Member

@seisman seisman commented Jul 29, 2024

Description of proposed changes

Originally proposed in #3358 (comment). This PR updates the xrgrid to be a true global grid. The new grid comes from #390.

import numpy as np
import xarray as xr


# The old xr.DataArray grid
longitude = np.arange(0, 360, 1)
latitude = np.arange(-89, 90, 1)
x = np.sin(np.deg2rad(longitude))
y = np.linspace(start=0, stop=1, num=179)
data = y[:, np.newaxis] * x

da1 = xr.DataArray(
    data,
    coords=[
        ("latitude", latitude, {"units": "degrees_north"}),
        ("longitude", longitude, {"units": "degrees_east"}),
    ],
    attrs={"actual_range": [-1, 1]},
)

# The new xr.DataArray grid
longitude = np.arange(0, 361, 1)
latitude = np.arange(-90, 91, 1)
lon_grid, lat_grid = np.meshgrid(longitude, latitude)
data = np.cos(np.deg2rad(lat_grid)) * np.sin(np.deg2rad(lon_grid))
# Consistent data points are North/South poles for all longitude
data[0, :] = 0.0
data[-1, :] = 0.0

da2 = xr.DataArray(
    data,
    coords=[
        ("latitude", latitude, {"units": "degrees_north"}),
        ("longitude", longitude, {"units": "degrees_east"}),
    ],
    attrs={"actual_range": [-1, 1]},
)

import pygmt
fig = pygmt.Figure()

fig.grdimage(da1, projection="H0/15c", region="g")
fig.shift_origin(xshift="w+2c")
fig.grdimage(da2, projection="H0/15c", region="g")
fig.show()

Left is old grid and right is the new grid:
map

Pros of the new grids:

  1. It's 0-360 range, and it's easy to get a 0-359 grid by grid slicing.
  2. It has consistent data points in the North/South poles.
  3. The xrgrid object is also used in test_grdimage_grid_and_shading_with_xarray but in that test we only add shading to a small region (i.e. region="GL"), so it's still unclear if adding a xrgrid shading grid to a global grid works or not.

@seisman seisman added maintenance Boring but important stuff for the core devs needs review This PR has higher priority and needs review. labels Jul 29, 2024
@seisman seisman added this to the 0.13.0 milestone Jul 29, 2024
Copy link
Contributor

github-actions bot commented Jul 29, 2024

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
modified pygmt/tests/baseline/test_grdimage_over_dateline.png

Image diff(s)

Added images

Modified images

Path Old New
test_grdimage_over_dateline.png

Report last updated at commit a7d08fc

@seisman seisman changed the title Improve the xrgrid used in grdimage tests Improve the xrgrid object used in grdimage tests Jul 29, 2024
@seisman seisman changed the title Improve the xrgrid object used in grdimage tests Improve the geographic global xarray.DataArray grid used in grdimage tests Jul 29, 2024
@seisman seisman removed the needs review This PR has higher priority and needs review. label Aug 1, 2024
@seisman seisman modified the milestones: 0.13.0, 0.14.0 Aug 1, 2024
@seisman seisman removed this from the 0.14.0 milestone Sep 5, 2024
@seisman seisman closed this Oct 2, 2024
@seisman seisman deleted the grdimage/xrgrid branch October 2, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants