[Thread Prev][Thread Next][Index]

Re: [ferret_users] restrict polymark to transect




Hi,

If the total number of points (nstations*nobs) isn't too large (say < 10^8 ) then this problem can be easily solved by using a brute force nearest neighbour approach.

The trick is to define the x axis to be stations and the y axis to be observations. You then spread the station locations to a 2D grid, subtract the locations of the obs and check the differences against your criteria giving you a mask.

Something like

let lon_2d = 0*longitude + ysequence(TransLon) ! 2D. Could also reshape onto a proper grid.
let lat_2d = 0*latitude + ysequence(TransLat)

let d_lon = abs(lon_2d-longitude)
let d_lat = abs(lat_2d-latitude)


! Check that x and y criteria are met simultaneously

let mask_2d = if d_lon le dx and d_lat le dy then 1

! Reduce to 1D. The distance criterion only needs to be satisfied once.

let mask = if mask_2d[j=1:`nstations`@ngd] ge 1 then 1

If you have a lot of obs and stations (say nobs*nstations > 10^9 or so) then it would probably be best to use dedicated nearest neighbour software like kdtree2 ( https://github.com/jmhodges/kdtree2 ) and do the culling of points outside ferret. Ansley's approach should be fine
if things aren't too large.


Cheers,
Russ


On 15/10/15 05:40, Ansley Manke wrote:
Hi,
You might do better cycling through your points checking whether each one is near the transect, and plotting them separately, rather than trying to define one mask that covers them all. Long recursive definitions get unwieldy.

-Ansley

On 10/8/2015 8:12 AM, Marco van Hulten wrote:
Le 2015-10-08 Marco a écrit:
Hello,

I regularly plot transects of model output with observations plotted
on top of these as dots.  So the last command is

   go polymark polygon/over Latitude, Depth, myvar circle 1.0

for a transect that is monotonic in latitude.  Observational data from
all longitudes are plotted.  This works fine when using only the
transect observational data.  If I use a dataset that includes
observations at longitudes far away from the transect (but within the
latitude range of the transect), these are also included on the plot.

While this is expected behaviour, I would like to limit the longitudes
to close to the transect.  So I am thinking of including a criterium
that limits plotting of points near the transect.  How would such a
criterium look like?
[...]
Paulo and Ryo suggested that I could define a mask for this.  I am
trying to extend this to an arbitrary number of stations with
coordinates (TransLon, TransLat).  The coordinates of my data are
(Longitude, Latitude).  Of the latter I have many more points, so the
two datasets do not share a common shape, so Ryo's method will not work
in my case.

The allowed domain is the union of subsets of the neighbourhoods of the
transect station coordinates.  So for a transect that is monotonic in
latitude, this could be done as follows:

let TransLon = Longitude[d=transect.csv]
let TransLat = Latitude[d=transect.csv]
let dx = 1
let dy = 3
set data many_observations_throughout_the_ocean.csv
let nStations = `TransLon,return=size`
def symb TransMask = (Longitude ge TransLon[i=1]-dx and Longitude le TransLon[i=1]+dx\ and Latitude ge TransLat[i=1]-dy and Latitude le TransLat[i=1]+dy)
repeat/range=2:`nStations`/name=ind ( \
     def symb TransMask = ($TransMask) or \
(Longitude ge TransLon[i=`ind`]-dx and Longitude le TransLon[i=`ind`]+dx\ and Latitude ge TransLat[i=`ind`]-dy and Latitude le TransLat[i=`ind`]+dy))
def symb myvar = if ($TransMask) then ($myvar) else 1/0
go polymark polygon/over Latitude, Depth, "($myvar)" circle 1.0

Typically one would choose the variance of the monotonic coordinate
(dy in °) somewhat higher than the other one (dx in °), as you want to
be sure any intermediate points that are more or less on the transect
are plotted, but points far from the transect should not be plotted.

I initialise the definition with the condition for the first set of
station coordinates.  Then I add subsequent coordinates with a loop
starting from 2 upto the number of stations, by appending "OR ..." to
the condition.  I redefine the myvar symbol and plot that.  The
citation marks around ($myvar) are necessary because the symbol
contains spaces and otherwise the POLYGON subcommand only sees the
first IF instead of the whole ($TransMask) criterium as the third and
final argument (interpreting circle 1.0 as POLYMARK arguments).

There is still a problem.  With more than 12 stations it appears that I
go beyond the maximum allowed symbol length:

  **ERROR: invalid command: symbol substitution makes line too long

I can increase this by several stations by removing whitespace in my
script, but typically I have more than fifty stations that I would like
to plot.  What does it mean that the line is too long?  I can SAY a
very large string e.g. without any problems.

Marco





[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement