xzos / PyZDDE

Zemax/ OpticStudio Extension using Python
MIT License
159 stars 67 forks source link

Problem getting zGetZernike about list indices #101

Open g-velarde opened 4 years ago

g-velarde commented 4 years ago

First of all thank you for this amazing code! :) I am getting this error code: 9775, in zGetZernike meta_line = line_list[_getFirstLineOfInterest(line_list, pat)]

TypeError: list indices must be integers or slices, not NoneType

When I write: zInfo, zCoeff = ln.zGetZernike(which='fringe')

Thank you in advance!

LucVV commented 4 years ago

Hi @g-velarde, sorry for the delayed reply.

It looks like the pattern does not match any part of the file. Could you check that Zemax actually has a result for your analysis? When to many rays are vignetted, it could be that the analysis was not performed, in which case the output might not be handled correctly. I fixed this issue in this pull request, which is merged online, but not released yet. Does that work for you?

g-velarde commented 3 years ago

still some issues with this topic but I get them just dumping the file zernike 'txt' file and searching lines for the zernike coeffs. Thanks anyway!

turygj commented 2 years ago

still some issues with this topic but I get them just dumping the file zernike 'txt' file and searching lines for the zernike coeffs. Thanks anyway!

I have the same problem. Have you solved this problem? If so, could you please provide the solution?

LucVV commented 2 years ago

I'm not sure what is causing your errors if it's not an empty text file. Which OpticStudio version are you on?

@turygj, if you are looking for a function that finds the Zernike coefficients for you, I have implemented one for the Standard Zernike Coefficients here. I assume you should be able to apply this function without many modifications.

turygj commented 2 years ago

I'm not sure what is causing your errors if it's not an empty text file. Which OpticStudio version are you on?

@turygj, if you are looking for a function that finds the Zernike coefficients for you, I have implemented one for the Standard Zernike Coefficients here. I assume you should be able to apply this function without many modifications.

The OpticStudio version is 181119. I have got the zernike 'txt' by zGetTextFile. Thank you for taking the time to respond to my questions!

LucVV commented 2 years ago

Just to be sure, if you open the textfile yourself, does it contain the analysis result that you would also see in OpticStudio?

turygj commented 2 years ago

Just to be sure, if you open the textfile yourself, does it contain the analysis result that you would also see in OpticStudio?

Yes. But If you have any more code after that, python will output an error and cannot run.

LucVV commented 2 years ago

I see, I guess that one of the following meta patterns is not found:

meta_patterns = ["Peak to Valley\s+\(to chief\)",
                 "Peak to Valley\s+\(to centroid\)",
                 "RMS\s+\(to chief\)",
                 "RMS\s+\(to centroid\)",
                 "Variance",
                 "Strehl Ratio",
                 "RMS fit error",
                 "Maximum fit error"]

As a results, it tries to index with a None, which is not possible. I have adressed that in this pull request, but the version on PyPi does not have that. You could try to change your line 9775 to:

if line_index is not None:
    meta_line = line_list[line_index]
    meta.append(float(_re.search(r'\d{1,3}\.\d{4,8}', meta_line).group()))
else:
    meta.append(_math.nan)

Which should handle the NoneTypes

turygj commented 2 years ago

Your guess is right. Now I can output the "zCoeff", but the "zInfo" becomes "nan" for everyone.

LucVV commented 2 years ago

Oke, I guess the regex patterns are failing for some reason. Could you upload/post an example of the output?

turygj commented 2 years ago

When I imput "zInfo, zCoeff = ln.zGetZernike(which='fringe')" and "print(zInfo, zCoeff)", the output is that "zInfo(pToVChief=nan, pToVCentroid=nan, rmsTochief=nan,……) andzCoeff(Z1=0.0012021, Z2=0, Z3=-0.77952288,……)" Thank you for taking the time to respond to my questions!

LucVV commented 2 years ago

I understand, but could you paste the content of the actual .txt file? I assume something goes wrong in reading it in.