xzos / PyZDDE

Zemax/ OpticStudio Extension using Python
MIT License
154 stars 64 forks source link

Functionalities #92

Closed LucVV closed 5 years ago

LucVV commented 5 years ago

Hi Indranil,

I've added some functionalities to the zDDE library, which might be of interest. The functionalities include:

1) The addition of a property to check the current connection status

2) I ran into problems with some command that are based on writing the result to a text file and then reading the textfile (such as zGetZernike()). On some computers, the decimal separators in these files are commas in stead of points. This resulted in ValueErrors, for instance in meta.append(float(_re.search(r'\d{1,3}\.\d{4,8}', meta_line).group())) in line 9790 of the zdde code.

To circumvent this valueError, I added the function checkDecimalSeparators(string) to pyzdde/zfileutils.py and implemented it in the _getDecodedLineFromFile() function in pyzdde/zdde.py.

The function uses the regular expression '((?<=\d)|(?<=\A)|(?<=-)|(?<=\s))' to search for commas in strings that represent decimal separators and replace them by points.

It will do perform the following conversions: '0,0' --> '0.0' ',0' --> '.0' ' ,0' --> ' .0' '-,0' --> '-.0'

It will not perform the following conversions: '1,' --> 1.

This separator is not expected to be a decimal separator, but rather a word separator, e.g. in: A = 1, B= 2

'a,1' --> a.1 '1,a' -->1.a 'a,a' --> 'a.a' 'a,' --> 'a.' ',a' --> '.a ' ,a' --> ' .a

I've updated the regex twice in additional commits, if necessary, it can be updated for different behavior.

3) I updated zGetZernike() to handle instances where the Zernikes cannot be traced. For now, I chose to return a namedTuple filled with np.NaN on these occurrences, where the tuple is filled with the maximum amount of Zernike coefficients that you can acquire (37 for fringe, 231 for standard and annular Zernikes), in order to circumvent loops from running into errors.

Kind regards,

Luc