-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated srwl_bl.py and srwlib.py added to allow correct import in Sirepo #7
Conversation
…y.so copied from rs/SRW-light.
… are ignored now.
…nd core+pylib (make).
env/work/srw_python/srwlib.py
Outdated
@@ -342,6 +342,12 @@ def get_K(self): | |||
sumBdNe2 += curBdN*curBdN | |||
return mult*self.per*sqrt(sumBdNe2) | |||
|
|||
def K_2_B(self, K): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Implemented fully (added member-function def K_2_B(self, K)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
env/work/srw_python/srwlib.py
Outdated
@@ -3769,7 +3772,7 @@ def srwl_uti_write_data_cols(_file_path, _cols, _str_sep, _str_head=None, _i_col | |||
if(nLines < newLen): nLines = newLen | |||
|
|||
strSep = '\t' | |||
if(_str_sep != None): | |||
if(_str_sep is not None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. "== None" / "!= None" is fixed in all places.
env/work/srw_python/uti_io.py
Outdated
'data': data, | ||
'raw_image': raw_image, | ||
'limit_value': limit_value, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done. Updated this.
It's good to see the previous processing (cutting label, etc.) was removed from here. "read_image()" has just read an image from file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you like it. Yes, the simpler this function, the better. All the processing is done in the Sample library.
env/work/srw_python/uti_math.py
Outdated
return { | ||
'fwhm': abs(list_of_roots[-1] - list_of_roots[0]), | ||
'x_range': list_of_roots, | ||
} | ||
else: | ||
raise Exception('Number of roots is less than 2!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done.
BTW, do we really need the "fwhm_scipy(x, y)" function that goes after this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be removed, it's not used anywhere. The function was originally created by Timur with the scipy
dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
env/work/srw_python/uti_plot.py
Outdated
_backend.uti_data_file_plot(_fname, _read_labels, _e, _x, _y, _graphs_joined, _traj_report, _traj_axis) #MR29072016 | ||
_backend.uti_data_file_plot(_fname, _read_labels, _e, _x, _y, _graphs_joined, | ||
_multicolumn_data, _column_x, _column_y, #MR31102017 | ||
_scale, _width_pixels) #MR20012017 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done.
env/work/srw_python/uti_plot_com.py
Outdated
'units': units, | ||
} | ||
# data, mode, allrange, arLabels, arUnits | ||
return d, None, [], [], [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I added "_multicolumn_file_load(fname)", but also left the "_traj_file_load(fname, traj_axis='x')" for backwards compatibility. I marked the latter one as OBSOLETE.
env/work/srw_python/uti_plot_com.py
Outdated
return _file_load(fname, read_labels) | ||
else: | ||
return _traj_file_load(fname, traj_axis) | ||
return _multicolumn_file_load(fname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done.
data = np.reshape(data, (data.shape[0] * data.shape[1]), order='C') | ||
except: | ||
print('Cannot resize the image - scipy.ndimage.zoom() cannot be imported.') | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, updated this; though it is not clear which exactly lines had to be deleted (I made a guess).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I only added the code, didn't remove anything in this place since there are only green lines with +
symbols, no red color with -
.
for c in [_column_x, _column_y]: | ||
if c not in available_cols: | ||
raise ValueError('Incorrect column specified: {}.\nAvailable columns: {}'.format(c, available_cols)) | ||
fig = self._plot_1D_XvsY(data, _column_x, _column_y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, added this.
ax.grid() | ||
ax.set_xlabel(data[column_x]['label']) | ||
ax.set_ylabel(data[column_y]['label']) | ||
return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, added this.
return self._maybe_savefig(fig) | ||
|
||
def _enum(self, *sequential, **named): #Had to copy this in uti_plot_com | ||
enums = dict(zip(sequential, range(len(sequential))), **named) | ||
return type('Enum', (), enums) | ||
|
||
def _plot_1D_XvsY(self, data, column_x, column_y, figsize=(8, 5), typ=111): #MR31102017 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this function would rather be called "_plot_1D_YvsX". But OK, I left it "as is" for the moment.
|
||
#print(opt.joined) | ||
uti_plot_init('TkAgg') | ||
#uti_data_file_plot(opt.infile, opt.readlab, opt.e, opt.x, opt.y, opt.joined) | ||
uti_data_file_plot(opt.infile, opt.readlab, opt.e, opt.x, opt.y, opt.joined, opt.traj_report, opt.traj_axis) #MR29072016 | ||
uti_data_file_plot(opt.infile, opt.readlab, opt.e, opt.x, opt.y, opt.joined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other main functions in this module start from "uti_plot" prefix. So I've changed the name of this main function to "uti_plot_data_file", but also left the "uti_data_file_plot" version for backwards-compatibility.
env/work/srw_python/basic-test.sh
Outdated
fi | ||
|
||
# Test of multielectron simulation for nan/inf values: | ||
example_py="multielectron_test.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've modified this file name: "multielectron_test.py" -> "srwl_test_multi_e.py" and made the corresponding correction here.
env/work/srw_python/basic-test.sh
Outdated
|
||
# Test of multielectron simulation for nan/inf values: | ||
example_py="multielectron_test.py" | ||
data_d="multielectron_test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I changed this directory name to "data_test" - to obey general naming conventions used in SRW.
Makefile
Outdated
cd $(root_dir); \ | ||
rm -rf $(example10_data_dir); \ | ||
fi; | ||
timeout_s=$(timeout) bash $(examples_dir)/basic-test.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the bash file name here: "basic-test.sh" -> "srwl_test_basic.sh"
env/work/srw_python/srwl_uti_smp.py
Outdated
|
||
opT.input_parms = input_parms | ||
|
||
return opT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I took the entire file (without testing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested it with Sirepo yesterday, seems to work fine.
if not _multicolumn_data: | ||
data = np.array(data) | ||
if mode == 3: | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "mode == 3"? It may have values of _enum('T','V','H','E','HV','EV','EH','EHV')
We don't seem to need FWHM printed here. E.g. it is confusing in the case of spectrum over photon energy.
I commented this part out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode=3
was for E
, just convenience I used for myself. It's fine it's commented out for me.
env/work/srw_python/uti_math.py
Outdated
|
||
def is_positive(num): | ||
return True if num > 0 else False | ||
|
||
# Normalize values first: | ||
y = (y - min(y)) / (max(y) - min(y)) - shift # roots are at Y=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maksim, this doesn't seem to work with Python native array.array()...
This is what I get when trying to execute SRWLIB_Example15.py:
Traceback (most recent call last):
File "C:\SoftwareDevelopments\SRW_Dev\env\work\srw_python\SRWLIB_Example15.py", line 191, in
xRMS.append(fwhm(x, arIxh))
File "C:\SoftwareDevelopments\SRW_Dev\env\work\srw_python\uti_math.py", line 636, in fwhm
y = (y - min(y)) / (max(y) - min(y)) - shift # roots are at Y=0
TypeError: unsupported operand type(s) for -: 'list' and 'float'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are busy, I'll fix this myself. I want to update SRW on GitHub today or tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0aa2404.
I synchronized the changes with my repo, there is no difference in files, closing the pull request (PR). In the future I'll be submitting each PR from a separate branch to allow easier and automatic synchronization. |
Dear Oleg,
Please revise the suggested changes to your code, which will allow better integration with Sirepo.
Thanks,
Maksim