Skip to content
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

Closed
wants to merge 120 commits into from

Conversation

mrakitin
Copy link
Contributor

@mrakitin mrakitin commented Mar 2, 2016

Dear Oleg,

Please revise the suggested changes to your code, which will allow better integration with Sirepo.

Thanks,
Maksim

@@ -342,6 +342,12 @@ def get_K(self):
sumBdNe2 += curBdN*curBdN
return mult*self.per*sqrt(sumBdNe2)

def K_2_B(self, K):
Copy link
Owner

@ochubar ochubar Jul 31, 2016

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)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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):
Copy link
Owner

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.

'data': data,
'raw_image': raw_image,
'limit_value': limit_value,
}
Copy link
Owner

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.

Copy link
Contributor Author

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.

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!')
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this function.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

_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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

'units': units,
}
# data, mode, allrange, arLabels, arUnits
return d, None, [], [], []
Copy link
Owner

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.

return _file_load(fname, read_labels)
else:
return _traj_file_load(fname, traj_axis)
return _multicolumn_file_load(fname)
Copy link
Owner

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
Copy link
Owner

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).

Copy link
Contributor Author

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)
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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,
Copy link
Owner

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.

fi

# Test of multielectron simulation for nan/inf values:
example_py="multielectron_test.py"
Copy link
Owner

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.


# Test of multielectron simulation for nan/inf values:
example_py="multielectron_test.py"
data_d="multielectron_test"
Copy link
Owner

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
Copy link
Owner

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"


opT.input_parms = input_parms

return opT
Copy link
Owner

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).

Copy link
Contributor Author

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:
Copy link
Owner

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.

Copy link
Contributor Author

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.


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
Copy link
Owner

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'

Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0aa2404.

mrakitin added a commit to radiasoft/SRW-light that referenced this pull request Nov 18, 2017
@mrakitin
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants