| Re: where function [message #74523 is a reply to message #4152] |
Sun, 23 January 2011 13:12  |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
On 23/01/2011 3:26 PM, smuzz wrote:
> Hi --
>
> I am a beginner programmer trying to write a code involving the where
> function. My dataset includes call detections made by whales from 1
> month. I am trying to search within this dataset for a particular call
> type, let's call it a moan. Then I want to search 1 hour before or
> after a detected moan and tally up all the other whale calls I hear --
> this is the part I am stuck on. How do you use the where function to
> search 1 hour before or after? I am only familiar with using gt and
> lt.
>
> This is what I have so far...
>
> n=n_elements(auto) ; auto is my dataset with all whale calls
>
> for i=0, n-1 do begin
> k = where(auto(*).manual_species eq 0 and auto(*).manual_call_type eq
> 1 and auto(*).time gt stime and auto(*).time lt etime,kcount) ; this
> is looking for all moans within a specified start and end time of the
> 1 month study
>
> if(kcount gt 0) then begin
>
> j=where(auto(*).mdist lt 3.0 and auto(*).avg_amplitude ge 12.0 and
> auto(*).time gt stime and auto(*).time lt etime and
> auto(*).manual_species eq 7 and auto(*).manual_call_type eq
> 1,jcount) ; this is looking for all other whale calls within the
> dataset
>
> ....right now j is tallying up all the calls in the dataset, but now I
> want to add in a part asking for only calls that occur 1 hour before
> or after a moan detection?
>
> Any ideas?
>
> Thanks, smuzz
Hi Smuzz,
glad to see I am not the only one working this Sunday :-)
First, sorry, but the 1st loop is useless ( for i=0, n-1 do begin)
... indeed, you are never using i!
Here is what you want to do (it could probably be optimized though)
1) Select the entries from the dataset that have the proper time (month)
and call type. Count the number of results
2) Loop through these results, and make your 2nd selection by
adding/removing time
3) process
------------------------
to use your code, it would look like this
k = where(auto(*).manual_species eq 0 and auto(*).manual_call_type eq
1 and auto(*).time gt stime and auto(*).time lt etime,kcount) ; this
is looking for all moans within a specified start and end time of the
1 month study
for entry = 0, kcount -1 do begin
linkedWhalesID = where(auto(*).mdist lt 3.0 and auto(*).avg_amplitude
ge 12.0 and
auto(*).time gt auto[k[entry]].time - 60 and auto(*).time lt
auto[k[entry]].time + 60 and
auto(*).manual_species eq 7 and auto(*).manual_call_type eq
1,jcount)
WhalesToAnalyze = auto[linkedWhalesID]
endfor
Jean
|
|
|
|