Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I have arrays associated with both A and B which store the (x,y) positions of the gridpoints for each.</p> </blockquote> <p>In that case, the answer should be fairly simple...</p> <p>Are the two grids strictly on the same gridding scheme? Assuming they are, you can just do something like:</p> <pre><code>np.argwhere((Ax == Bx.min()) &amp; (Ay == By.min())) </code></pre> <p>Assuming the world coordinates of the two grids increase in the same direction as the indicies of the grids, this gives the lower left corner of the subsetted grid. (And if they don't increase in the same direction (i.e. negative <code>dx</code> or <code>dy</code>), it just gives one of the other corners)</p> <p>In the example below, we could obviously just calculate the proper indicies from <code>ix = (Bxmin - Axmin) / dx</code>, etc, but assuming you have a more complex gridding system, this will still work. However, this is assuming that the two grids <em>are on the same gridding scheme</em>! It's slightly more complex if they're not...</p> <pre><code>import numpy as np # Generate grids of coordinates from a min, max, and spacing dx, dy = 0.5, 0.5 # For the larger grid... Axmin, Axmax = -180, 180 Aymin, Aymax = -90, 90 # For the smaller grid... Bxmin, Bxmax = -5, 10 Bymin, Bymax = 30, 40 # Generate the indicies on a 2D grid Ax = np.arange(Axmin, Axmax+dx, dx) Ay = np.arange(Aymin, Aymax+dy, dy) Ax, Ay = np.meshgrid(Ax, Ay) Bx = np.arange(Bxmin, Bxmax+dx, dx) By = np.arange(Bymin, Bymax+dy, dy) Bx, By = np.meshgrid(Bx, By) # Find the corner of where the two grids overlap... ix, iy = np.argwhere((Ax == Bxmin) &amp; (Ay == Bymin))[0] # Assert that the coordinates are identical. assert np.all(Ax[ix:ix+Bx.shape[0], iy:iy+Bx.shape[1]] == Bx) assert np.all(Ay[ix:ix+Bx.shape[0], iy:iy+Bx.shape[1]] == By) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload