Discussion:
[Gwyddion-users] Multi section cuts
Andrés Muñiz Piniella
2015-04-16 18:30:47 UTC
Permalink
Hello all,

Has anybody come up with a script that can do multiple sections in on go?

Example: I have several step features in an image.

I want to do three parallel one pixel wide sections on each step feature. I will then average. This way I avoid nasty features.

Ways that I figure doing it:
A) do a script that will do 2 paralell sections at a certain distance from the already existing section lines.
B) change the average feature so it only takes3 sections to do the average. Middle point of data and edges points of data. Less visual but more automatic.

Any suggestions?

Regards,
Andrés.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
David Nečas (Yeti)
2015-04-20 20:02:30 UTC
Permalink
Post by Andrés Muñiz Piniella
I want to do three parallel one pixel wide sections on each step
feature. I will then average.
Why would you want to take three one-pixel sections on each feature and
average? DataField.get_profile() can average in the direction
orthogonal to the line direction – see argument thickness, which has the
same meaning as in the Profile tool.

Maybe I misunderstand and you just want take three sections, one on each
step feature.

To modify the selection in a script:
1) Get the selection, e.g

sel = container['/0/select/line']

2) Use get_data() to obtain the coordinates:

coords = sel.get_data()

The resulting array has length nselections*ncoords, where ncoords = 4
for lines is the number of coordinates describing each selection object
(line here).

3) Do whatever with coords.

4) Set the selection data

sel.set_data(len(coords)/4, coords)

The number 4 has the same meaning as above. For obscure reasons it is
necessary to pass it back.

E.g.

c = gwy.gwy_app_data_browser_get_current(gwy.APP_CONTAINER)
sel = c['/0/select/line']
coords = sel.get_data()
coords = coords + [x + 1e-7 for x in coords]
sel.set_data(len(coords)/4, coords)

Yeti
Andrés Muñiz Piniella
2015-04-20 20:32:09 UTC
Permalink
Post by David Nečas (Yeti)
Post by Andrés Muñiz Piniella
I want to do three parallel one pixel wide sections on each step
feature. I will then average.
Why would you want to take three one-pixel sections on each feature and
average? DataField.get_profile() can average in the direction
orthogonal to the line direction – see argument thickness, which has the
same meaning as in the Profile tool.
I wanted discrete sections because my features are fairly regular. It is not the case, but imagine I wanted three sections that use the average orthogonal to the section.

I guess this might be only useful for measuring calibrating artifacts.

The paralell section lines might not be the best solution it is just something I recall seeing on SPIP
Post by David Nečas (Yeti)
Maybe I misunderstand and you just want take three sections, one on each
step feature.
Yes!
Post by David Nečas (Yeti)
1) Get the selection, e.g
sel = container['/0/select/line']
coords = sel.get_data()
The resulting array has length nselections*ncoords, where ncoords = 4
for lines is the number of coordinates describing each selection object
(line here).
3) Do whatever with coords.
4) Set the selection data
sel.set_data(len(coords)/4, coords)
The number 4 has the same meaning as above. For obscure reasons it is
necessary to pass it back.
E.g.
c = gwy.gwy_app_data_browser_get_current(gwy.APP_CONTAINER)
sel = c['/0/select/line']
coords = sel.get_data()
coords = coords + [x + 1e-7 for x in coords]
sel.set_data(len(coords)/4, coords)
Yeti
Thank you very much, I am sure this will get me going!
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
David Nečas (Yeti)
2015-04-22 14:51:47 UTC
Permalink
Post by Andrés Muñiz Piniella
Thank you very much, I am sure this will get me going!
I should add how to create a new selection from scratch. This is a bit
tricky because the selection classes are dynamically loaded from modules
and there are no direct concrete constructors. You need to use the
generic GObject contructor gobject.new():

import gobject

sel = gobject.new('GwySelectionLine') # Replaces sel = SelectionLine()
sel.set_data(1, [0.0, 0.0, 1e-6, 1e-6])
c = gwy.gwy_app_data_browser_get_current(gwy.APP_CONTAINER)
c['/0/select/line'] = sel

Regards,

Yeti

Continue reading on narkive:
Loading...