Skip to content

Commit e81ab50

Browse files
author
aglavic
committed
- Arc integration
- xy-offset - normalization
1 parent c529617 commit e81ab50

File tree

9 files changed

+144
-26
lines changed

9 files changed

+144
-26
lines changed

bash_completion.d/plotpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ _plot() {
1010
"dns") COMPREPLY=($(compgen -G "$curw*.d_dat") $(compgen -G "$curw*.d_dat.gz") $(compgen -S/ -d -- $curw));;
1111
"mbe") COMPREPLY=($(compgen -G "$curw*.dat") $(compgen -G "$curw*.png") $(compgen -G "$curw*.log") $(compgen -S/ -d -- $curw));;
1212
"4circle") COMPREPLY=($(compgen -G "$curw*.spec") $(compgen -G "$curw*.spec.gz") $(compgen -G "$curw*.[0-9][0-9][0-9][0-9]") $(compgen -G "$curw*.fio") $(compgen -G "$curw*.fio.gz") $(compgen -S/ -d -- $curw));;
13-
"kws2") COMPREPLY=($(compgen -G "$curw*.DAT") $(compgen -G "$curw*.edf") $(compgen -G "$curw*.cmb") $(compgen -G "$curw*.bin") $(compgen -G "$curw*.gz") $(compgen -S/ -d -- $curw));;
14-
"gisas") COMPREPLY=($(compgen -G "$curw*.DAT") $(compgen -G "$curw*.edf") $(compgen -G "$curw*.cmb") $(compgen -G "$curw*.bin") $(compgen -G "$curw*.gz") $(compgen -S/ -d -- $curw));;
13+
"kws2") COMPREPLY=($(compgen -G "$curw*.DAT") $(compgen -G "$curw*.edf") $(compgen -G "$curw*.cmb") $(compgen -G "$curw*.bin") $(compgen -G "$curw*.gz") $(compgen -G "$curw*.mat") $(compgen -S/ -d -- $curw));;
14+
"gisas") COMPREPLY=($(compgen -G "$curw*.DAT") $(compgen -G "$curw*.edf") $(compgen -G "$curw*.cmb") $(compgen -G "$curw*.bin") $(compgen -G "$curw*.gz") $(compgen -G "$curw*.mat") $(compgen -S/ -d -- $curw));;
1515
"in12") COMPREPLY=($(compgen -o default));;
1616
"refl") COMPREPLY=($(compgen -G "$curw*.[Uu][Xx][Dd]") $(compgen -G "$curw*.raw") $(compgen -G "$curw*.xrdml") $(compgen -G "$curw*.txt") $(compgen -G "$curw*.gz") $(compgen -S/ -d -- $curw));;
1717
"sas") COMPREPLY=($(compgen -G "$curw*.dat") $(compgen -G "$curw*.txt") $(compgen -G "$curw*.gz") $(compgen -S/ -d -- $curw));;

mime_types/gisas.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<glob pattern="*.edf.gz"/>
77
<glob pattern="*.cmb"/>
88
<glob pattern="*.cmb.gz"/>
9+
<glob pattern="*.mat"/>
910
</mime-type>
1011
</mime-info>

plot_script/gtkgui/file_actions.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def cross_section(self, x, x_0, y, y_0, w, binning,
169169
except ValueError:
170170
return False
171171

172-
def radial_integration(self, x_0, y_0, dr, max_r, at_end=False):
172+
def radial_integration(self, x_0, y_0, dr, max_r,
173+
phi_0=0., dphi=180., symmetric=True,
174+
at_end=False):
173175
'''
174176
Create a radial integration around one point of a dataset
175177
@@ -182,11 +184,17 @@ def radial_integration(self, x_0, y_0, dr, max_r, at_end=False):
182184
'''
183185
data=self.window.measurement[self.window.index_mess]
184186
try:
185-
cs_object=self.create_radial_integration(x_0, y_0, dr, max_r)
187+
cs_object=self.create_radial_integration(x_0, y_0, dr, max_r,
188+
phi_0, dphi, symmetric)
186189
if cs_object is None:
187190
return False
188191
cs_object.number=data.number
189-
cs_object.short_info='%s - Radial integration around (%g,%g)'%(
192+
if dphi<180.:
193+
cs_object.short_info='%s - Arc integration with φ=%g±%g from (%g,%g)'%(
194+
data.short_info, phi_0, dphi,
195+
x_0, y_0)
196+
else:
197+
cs_object.short_info='%s - Radial integration around (%g,%g)'%(
190198
data.short_info, x_0, y_0)
191199
cs_object.sample_name=data.sample_name
192200
cs_object.info=data.info
@@ -608,16 +616,19 @@ def create_cross_section(self, x, x_0, y, y_0, w, binning, gauss_weighting=False
608616
out_dataset.append_column(PhysicalProperty(dataset.y.dimension, dataset.y.unit, data[2]))
609617
return out_dataset
610618

611-
def create_radial_integration(self, x_0, y_0, dr, max_r):
619+
def create_radial_integration(self, x_0, y_0, dr, max_r,
620+
phi_0=0., dphi=180., symmetric=True):
612621
'''
613622
Create a radial integration around one point (x_0,y_0)
614623
615624
:param x_0: x-position of the center point
616625
:param y_0: y-position of the center point
617626
:param dr: Step size in radius for the created plot
618627
:param max_r: Maximal radius to integrate to
628+
:param phi: Direction of radian
629+
:param dphi: Width of arc
630+
:param symmetric: Join negative and positive directions
619631
'''
620-
from numpy import sqrt
621632
data=self.window.measurement[self.window.index_mess].get_filtered_data_matrix()
622633
dims=self.window.measurement[self.window.index_mess].dimensions()
623634
units=self.window.measurement[self.window.index_mess].units()
@@ -627,13 +638,15 @@ def create_radial_integration(self, x_0, y_0, dr, max_r):
627638
self.window.measurement[self.window.index_mess].yerror)
628639
# new_cols=[(dims[col], units[col]) for col in cols]
629640
# Distances to the point
630-
dist_r=sqrt((data[cols[0]]-x_0)**2+(data[cols[1]]-y_0)**2)
631-
max_r=min(dist_r.max(), max_r)
641+
r=numpy.sqrt((data[cols[0]]-x_0)**2+(data[cols[1]]-y_0)**2)
632642
values=data[cols[2]]
633643
errors=data[cols[3]]
644+
max_r=min(r.max(), max_r)
634645
first_dim="r"
635646
first_unit=units[cols[0]]
636-
new_cols=[(first_dim, first_unit), (dims[cols[2]], units[cols[2]]), (dims[cols[3]], units[cols[3]])]
647+
new_cols=[(first_dim, first_unit),
648+
(dims[cols[2]], units[cols[2]]),
649+
(dims[cols[3]], units[cols[3]])]
637650
output=MeasurementData([],
638651
[],
639652
0,
@@ -644,15 +657,28 @@ def create_radial_integration(self, x_0, y_0, dr, max_r):
644657
# the result is than calculated as hist(intensity)/hist(1)
645658
# and sqrt(hist(error²))/hist(1)
646659
points=int(max_r/dr)+1
647-
hy, ignore=numpy.histogram(dist_r, points, weights=values)
648-
hdy, ignore=numpy.histogram(dist_r, points, weights=errors**2)
660+
if dphi<180.:
661+
# take out just one arc region for the integration
662+
phi=numpy.arctan2(data[cols[1]]-y_0, data[cols[0]]-x_0)/numpy.pi*180.
663+
phi_region=numpy.where(((phi-phi_0)%180.)<=dphi)
664+
r=r[phi_region]
665+
values=values[phi_region]
666+
errors=errors[phi_region]
667+
if not symmetric:
668+
phi=phi[phi_region]
669+
r[((phi-phi_0)%360.)>180]*=-1.
670+
points=int(max_r/dr)*2+1
671+
hy, ignore=numpy.histogram(r, points, weights=values)
672+
hdy, ignore=numpy.histogram(r, points, weights=errors**2)
649673
hdy=numpy.sqrt(hdy)
650-
count, hx=numpy.histogram(dist_r, points)
674+
count, hx=numpy.histogram(r, points)
651675
hy/=count
652676
hdy/=count
653677
hx=(hx[:-1]+hx[1:])/2.
654678
output.data.append(PhysicalProperty(new_cols[0][0], new_cols[0][1], hx))
655679
output.data.append(PhysicalProperty(new_cols[1][0], new_cols[1][1], hy, hdy))
680+
if self.window.measurement[self.window.index_mess].logz:
681+
output.logy=True
656682
if len(output)==0:
657683
return None
658684
else:

plot_script/gtkgui/main_window_data_treatment.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,58 @@ def extract_cross_section(self, action):
671671
self.replot()
672672
return gotit
673673

674+
def correct_offset(self, action):
675+
'''
676+
Simple xy-offset correction.
677+
'''
678+
data=self.active_dataset
679+
dimension_names=[]
680+
dims=data.dimensions()
681+
dimension_names.append(dims[data.xdata])
682+
dimension_names.append(dims[data.ydata])
683+
dialog=SimpleEntryDialog('Correct xy-Offset:',
684+
[
685+
('x-offset', 0., float),
686+
('y-offset', 0., float),
687+
],
688+
description='Click to select the xy-origin'
689+
)
690+
dialog.register_mouse_callback(self, [[('x-offset', 0), ('y-offset', 1)]])
691+
values, result=dialog.run()
692+
dialog.destroy()
693+
if result:
694+
data.x-=values['x-offset']
695+
data.y-=values['y-offset']
696+
self.replot()
697+
698+
def normalize_data(self, action):
699+
'''
700+
Simple xy-offset correction.
701+
'''
702+
data=self.active_dataset
703+
dimension_names=[]
704+
dims=data.dimensions()
705+
dimension_names.append(dims[data.xdata])
706+
dimension_names.append(dims[data.ydata])
707+
dialog=SimpleEntryDialog('Normalize Data:',
708+
[
709+
('Normalization', 1., float),
710+
],
711+
description='Click to select value'
712+
)
713+
dialog.register_mouse_callback(self, [[('Normalization', 1)]])
714+
values, result=dialog.run()
715+
dialog.destroy()
716+
if result:
717+
norm=values['Normalization']
718+
ynorm=data.y/norm
719+
ynorm.unit='a.u.'
720+
ynorm.dimension=ynorm.dimension+'_{Norm}'
721+
data.data.append(ynorm)
722+
data.ydata=len(data.data)-1
723+
self.rebuild_menus()
724+
self.replot()
725+
674726
def extract_radial_integration(self, action):
675727
'''
676728
Open a dialog to select point as center of a radial integration.
@@ -688,6 +740,9 @@ def extract_radial_integration(self, action):
688740
('y0', 0, float),
689741
('Δr', 0.001, float),
690742
('r_max', 1e10, float),
743+
('φ (x-axis)', 0., float),
744+
('Δφ', 180., float),
745+
('Symmetric', True),
691746
],
692747
description='Click on the graph to select a xy-position.'
693748
)
@@ -699,8 +754,12 @@ def extract_radial_integration(self, action):
699754
x0=values['x0']
700755
y0=values['y0']
701756
mr=values['r_max']
757+
phi=values['φ (x-axis)']
758+
dphi=values['Δφ']
759+
symmetric=values['Symmetric']
702760
gotit=self.file_actions.activate_action('radial_integration',
703-
x0, y0, dr, mr, False
761+
x0, y0, dr, mr,
762+
phi, dphi, symmetric, False
704763
)
705764
if not gotit:
706765
message=gtk.MessageDialog(parent=self,

plot_script/gtkgui/main_window_ui.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def build_menu(self):
7373
None, # tooltip
7474
self.change),
7575
("FilesMenu", None, # name, stock id
76-
"_Change", None, # label, accelerator
76+
"Change", None, # label, accelerator
7777
None, # tooltip
7878
None),)
7979
# Menus allways present
@@ -265,6 +265,10 @@ def build_menu(self):
265265
<placeholder name='z-actions'/>
266266
<placeholder name='y-actions'>
267267
<menuitem action='CombinePoints'/>
268+
<menu action='SimpleCorrections'>
269+
<menuitem action='XYOffset'/>
270+
<menuitem action='Normalize'/>
271+
</menu>
268272
<menuitem action='Integrate'/>
269273
<menuitem action='Derivate'/>
270274
<menuitem action='PeakInfo'/>
@@ -378,7 +382,7 @@ def create_action_group(self):
378382
("ViewMenu", None, "_View"), # name, stock id, label
379383
("AxesMenu", None, "_Axes"), # name, stock id, label
380384
("TreatmentMenu", None, "_Data treatment"), # name, stock id, label
381-
("ExtrasMenu", None, "E_xtras"), # name, stock id, label
385+
("ExtrasMenu", None, "Extras"), # name, stock id, label
382386
("HelpMenu", None, "_Help"), # name, stock id, label
383387
("ToolBar", None, "Toolbar"), # name, stock id, label
384388
("Navigate", None, "Navigate"), # name, stock id, label
@@ -522,7 +526,7 @@ def create_action_group(self):
522526
None, # tooltip
523527
self.unit_transformation),
524528
("CrossSection", None, # name, stock id
525-
"Cross-Section...", None, #'s', # label, accelerator
529+
"Cross-Section...", '<alt>C', #'s', # label, accelerator
526530
None, # tooltip
527531
self.extract_cross_section),
528532
("InterpolateSmooth", None, # name, stock id
@@ -534,17 +538,29 @@ def create_action_group(self):
534538
None, # tooltip
535539
self.rebin_3d_data_dialog),
536540
("RadialIntegration", None, # name, stock id
537-
"Calculate Radial Integration...", None, # label, accelerator
541+
"Calculate Radial/Arc Integration...", "<alt>R", # label, accelerator
538542
None, # tooltip
539543
self.extract_radial_integration),
540544
("IntegrateIntensities", None, # name, stock id
541545
"Integrat Intensities...", None, # label, accelerator
542546
None, # tooltip
543547
self.extract_integrated_intensities),
544548
("CombinePoints", None, # name, stock id
545-
"Combine points", None, # label, accelerator
549+
"Combine points", '<alt>C', # label, accelerator
546550
None, # tooltip
547551
self.combine_data_points),
552+
("SimpleCorrections", None, # name, stock id
553+
"Correct the Dataset", None, # label, accelerator
554+
None, # tooltip
555+
None),
556+
("XYOffset", None, # name, stock id
557+
"xy-Offset", '<alt>X', # label, accelerator
558+
None, # tooltip
559+
self.correct_offset),
560+
("Normalize", None, # name, stock id
561+
"Normalization", '<alt>N', # label, accelerator
562+
None, # tooltip
563+
self.normalize_data),
548564
("Derivate", None, # name, stock id
549565
"Derivate or Smoothe", '<control>D', # label, accelerator
550566
None, # tooltip

plot_script/plotpy_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
__copyright__="Copyright 2008-2012"
44
__license__="GPL v3"
5-
__version__="0.7.13.10"
5+
__version__="0.7.14"
66
__maintainer__="Artur Glavic"
77
__email__="[email protected]"

plot_script/read_data/circle.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ def read_scan(scan_lines, last_comments):
150150
output.scan_line=1
151151
output.filters=[(9,-1.0, 0.5, False)]
152152
output=MeasurementData4D.from_md(output, y2=2)
153+
if scan_header['type'].split()[0]=='circle_mesh':
154+
output.scan_line_constant=0
155+
output.scan_line=1
153156
data=numpy.array(map(lambda line: numpy.fromstring(line, sep=" "), scan_data)).transpose()
154157
for i, col in enumerate(columns):
155158
output.data.append(PhysicalProperty(col[0], col[1], data[i]))
@@ -228,6 +231,9 @@ def get_type_columns(type_line, columns):
228231
first_index=columns.index(first_angle)
229232
second_index=columns.index(second_angle)
230233
return first_index, second_index, intensity_error, intensity
234+
elif type_=='circle_mesh':
235+
items=options.strip().split()
236+
return columns.index(items[0].lower()), columns.index(items[1].lower()), intensity_error, intensity
231237
elif type_=='mesh3d':
232238
items=options.strip().split()
233239
first_angle='Theta' #items[0]

plot_script/read_data/qtiplot.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ def process_tables(name, table, index):
4343
Read the data of one table using the header to define column names.
4444
'''
4545
header, data=table.split('<data>')
46-
data=data.split('</data>')[0].strip()
46+
data=data.strip().split('</data>')[0]
4747
header_info=process_header(header)
48+
# split data by lines and columns
4849
data_lines=data.splitlines()
49-
data_items=map(str.split, data_lines)
50+
data_items=map(lambda line: line.split('\t'), data_lines)
51+
# convert to numbers
5052
data=[map(float_convert, line) for line in data_items]
5153
data=numpy.array(data).transpose()
5254
column_names=header_info['columns']
@@ -88,5 +90,12 @@ def float_convert(item):
8890
try:
8991
return float(item)
9092
except ValueError:
91-
return 0.
93+
if ':' in item:
94+
try:
95+
h, m, s=item.split(':')
96+
return 3600.*float(h)+60.*float(m)+float(s)
97+
except:
98+
return 0.
99+
else:
100+
return 0.
92101

plot_script/sessions/kws2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class KWS2Session(GUI, GenericSession):
4747
#------------------ help text strings ---------------
4848

4949
#++++++++++++++++++ local variables +++++++++++++++++
50-
FILE_WILDCARDS=[('GISAS', '*.DAT', '*.DAT.gz', '*.cmb', '*.cmb.gz', '*.edf', '*.edf.gz', '*.tif', '*.bin', '*.bin.gz',
51-
'*.bmp'), ]
50+
FILE_WILDCARDS=[('GISAS', '*.DAT', '*.DAT.gz', '*.cmb', '*.cmb.gz',
51+
'*.edf', '*.edf.gz', '*.tif', '*.bin', '*.bin.gz',
52+
'*.mat', '*.bmp'), ]
5253
mds_create=False
5354
read_directly=True
5455

@@ -134,4 +135,4 @@ def autosubtract_background(self, dataset, fraction=5.):
134135
dataset.plot_options.zrange=(1., None)
135136
return fine_background
136137

137-
#++++++++++++++++++++++++++ data treatment functions ++++++++++++++++++++++++++++++++
138+
#++++++++++++++++++++++++++ data treatment functions ++++++++++++++++++++++++++++++++

0 commit comments

Comments
 (0)