comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: How to create a 2D mask that automatically half’s an irregularly shaped 2D array from top to bottom?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to create a 2D mask that automatically half’s an irregularly shaped 2D array from top to bottom? [message #78370] Fri, 18 November 2011 13:59 Go to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On 11/18/11 2:53 PM, Jeremy Bailin wrote:
> On 11/18/11 10:04 AM, Dr G. wrote:
>> Hi Folks,
>>
>> Q: Can the IDL geometry geniuses out there think of a fast way to
>> create a 2D mask that automatically half�s an irregularly shaped 2D
>> array along its x axis (i.e., from top to bottom) Eg:
>>
>> [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0]
>> [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
>> [0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0]
>> [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
>> [0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0]
>> [0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0]
>> [0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0]
>> [0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0]
>> [0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0]
>> [0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0]
>> [0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0]
>> [0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0]
>>
>> Merci.
>>
>> Gf
>
> If the input mask is "inmask":
>
> ; how many 1s are there?
> rowtot = total(inmask, 1, /int)
> ; and it by checking if the cumulative total along the row is less
> ; than half of rowtot
> outmask = inmask and (total(inmask, 1, /int, /cumul) le $
> rebin(transpose(rowtot/2), masksize, /sample))
>
> -Jeremy.

Oops, missed the first line when I copied that in:

masksize = size(inmask, /dimen)

-Jeremy.
Re: How to create a 2D mask that automatically half’s an irregularly shaped 2D array from top to bottom? [message #78371 is a reply to message #78370] Fri, 18 November 2011 11:53 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On 11/18/11 10:04 AM, Dr G. wrote:
> Hi Folks,
>
> Q: Can the IDL geometry geniuses out there think of a fast way to
> create a 2D mask that automatically half�s an irregularly shaped 2D
> array along its x axis (i.e., from top to bottom) Eg:
>
> [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0]
> [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
> [0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0]
> [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
> [0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0]
> [0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0]
> [0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0]
> [0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0]
> [0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0]
> [0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0]
> [0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0]
> [0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0]
>
> Merci.
>
> Gf

If the input mask is "inmask":

; how many 1s are there?
rowtot = total(inmask, 1, /int)
; and it by checking if the cumulative total along the row is less
; than half of rowtot
outmask = inmask and (total(inmask, 1, /int, /cumul) le $
rebin(transpose(rowtot/2), masksize, /sample))

-Jeremy.
Re: How to create a 2D mask that automatically half’s an irregularly shaped 2D array from top to bottom? [message #78486 is a reply to message #78370] Tue, 22 November 2011 14:47 Go to previous message
Dr G. is currently offline  Dr G.
Messages: 2
Registered: November 2011
Junior Member
On Nov 19, 7:59 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On 11/18/11 2:53 PM, Jeremy Bailin wrote:
>
>
>
>
>
>
>
>
>
>> On 11/18/11 10:04 AM, Dr G. wrote:
>>> Hi Folks,
>
>>> Q: Can the IDL geometry geniuses out there think of a fast way to
>>> create a 2D mask that automatically half’s an irregularly shaped 2D
>>> array along its x axis (i.e., from top to bottom) Eg:
>
>>> [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0]
>>> [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
>>> [0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0]
>>> [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
>>> [0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0]
>>> [0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0]
>>> [0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0]
>>> [0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0]
>>> [0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0]
>>> [0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0]
>>> [0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0]
>>> [0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0]
>
>>> Merci.
>
>>> Gf
>
>> If the input mask is "inmask":
>
>> ; how many 1s are there?
>> rowtot = total(inmask, 1, /int)
>> ; and it by checking if the cumulative total along the row is less
>> ; than half of rowtot
>> outmask = inmask and (total(inmask, 1, /int, /cumul) le $
>> rebin(transpose(rowtot/2), masksize, /sample))
>
>> -Jeremy.
>
> Oops, missed the first line when I copied that in:
>
> masksize = size(inmask, /dimen)
>
> -Jeremy.

Hi Jeremy,

This is pretty amazing. Much better than a nasty for-next for each
row. Thank you. This is truly geometry genius. My intention is to
apply your method to masks 60,000 rows deep!!! So far in my tests,
your solution rapidly works for most situations, but the output is a
little strange when the input mask is very strangely shaped. One
alternative to this, is to rotate the mask 90 degrees so that columns
become rows, and then apply it.

Jeremy, can you please take a moment and explain to me how the rebin &
transpose combo works? I've read the help file on these but cannot
figure it out the geometry genius you use.

Additionally, you write "...and it by checking if the cumulative
total ..." do you mean 'add it...'?

Thank you for your consideration.

Dr G.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: random forest implementation in IDL
Next Topic: Re: Plotting one ps file with different plots in separate pages

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:39:58 PDT 2025

Total time taken to generate the page: 0.00392 seconds