I was wondering if the matplotlib users would be able to help with a numpy problem.
I have 2 dimensional arrays of latitudes and longitude named lon and lat and only want to extract
lats and lons within a certain domain
It is easy to apply the mask
But I am not sure how to clip rows and column of mask data to reduce size of resulting array.
The compress, extract etc functions all seem to work with 1D arrays and I don;t know how to get from my 1D array back to a 2D array.
I hope this is making sense.
Marjolaine.
···
--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.
glb_mask is 2D, with True where the data is selected and False otherwise.
Of course, that'll only work if the initial arrays have the same shape.
Now, you can check whether all the rows are False (no data selected)
row_clipper = glb_mask.any(axis=1)
row_clipper is 1D, with the same length as glb_mask, and False where now data
is selectd and True otherwise: we can use row_clipper to select only the rows
that have at least one unmasked data:
clipped_rows = original_array[row_clipper]
Then, rinse and repeat, this time on the columns:
col_clipper = glb_mask.any(axis=0)
clipped_cols = clipped_rows.T[col_clipper].T
Note the double .T.
You can also decide to use .all instead of any, to select the rows/cols where
all data are valid.
Let us know how it works.
P.
···
On Friday 12 September 2008 10:02:56 Marjolaine Rouault wrote:
Hi,
I was wondering if the matplotlib users would be able to help with a numpy
problem.
I have 2 dimensional arrays of latitudes and longitude named lon and lat
and only want to extract lats and lons within a certain domain
It is easy to apply the mask