I’ve been making animations of satellite images of the aurora (VIIRS DNB on the SUOMI-NPP and NOAA-20 satellites), which are provided as NetCDFs with three 2D grids of which the x- and y-coordinates represent the scan-lines and the pixels along the scan-lines of this instrument, respectively. One grid contains the measured brightness, and two others the longitudes and latitudes of these pixels. So these are regular grids, but with irregularly spaced longitudes and latitudes.
Since I’m interested in the aurora visible in these images, I’ve chosen orthographic projections centred on the North and South poles, and with the central longitude of the projection to be the longitude of the sub-solar point (e.g. using f-string substitution in the pygmt.grdimage call: projection=f"G90/{subsolar_lon}/15c"). In this way I can create animations of the Earth’s surface rotating beneath the swath of the satellites. Examples are available here:
That second example shows a problem, because the swath goes over the pole. I’ve used pygmt.xyz2grd to convert each data file to something that grdimage can handle, but the output of that uses a regular latitude/longitude grid, so near the pole the output grid’s pixels represent very small areas. This results in the noise and star-like pattern of grid pixels containing NaNs at the pole. The projection/-J argument to pygmt.xyz2grd does not seem to make any difference.
I tried using mapproject (using os.system in python, since it’s not yet in pygmt) to create a grid directly in the desired orthographic projection, and then plotting the result with grdimage with -JX projection (since the grid coordinates no longer represent lat/lon). This looks good, but since the subsolar point changes for each frame, this means the projection changes for each frame, and I would have to run mapproject for every input file and for every time step of the animation. At that point, it takes longer than real-time to produce an animation. I think this is also slow because mapproject uses an ASCII table for its input, so I need an intermediate step to convert the input NetCDFs to this ASCII format.
Would there be a more computationally efficient way to circumvent this problem? Perhaps with other tools? Can I plot the mapproject output with a fixed central longitude with grdimage, but applying a rotation to align with the sub-solar point in some other way?
I think ideally grdimage would just understand the format in which the latitudes and longitudes of the input data are provided in separate arrays, and/or pygmt.xyz2grd would make clever use of the desired projection.
I see this convention of separately provided lat and lon grids for each pixel in other satellite data and model output NetCDF files as well, so I wonder if others have found a better solution.
Source code, in the form of Jupyter notebooks, is available here: https://gitlab.com/KNMI-OSS/spaceweather/notebooks/-/tree/main/viirs_day_night_band