Skip to main content
pythonで物理光学伝搬のビーム幅を得たいのですがどうすればよいでしょうか?pop = TheSystem.Analyses.New_Analysis_SettingsFirst(AnalysisIDM.PhysicalOpticsPropagation)pop_settings = pop.GetSettings()pop_settings.BeamType = ZOSAPI.Analysis.PhysicalOptics.POPBeamTypes.GaussianAnglepop_settings.SetParameterValue(0, 28)pop_settings.SetParameterValue(1, 8)pop_settings.AutoCalculateBeamSampling()pop.ApplyAndWaitForCompletion()pop_results = pop.GetResults()print(pop_results.HeaderData.Lines(5])だと、Beam Width X = 1.30349E+00, Y = 4.44539E-01 Millimetersを得れるのですが、typeがstrになってしまいます。X、Yの値を別の方法で得るにはどうすればいいでしょうか?宜しくお願いします。

@Toshiharu.Takashima 

 

日本語を勉強中ですが、お役に立てれば幸いです。
import re

# Similar to line: print(pop_results.HeaderData.Linesi5])
string_variable = "Beam Width X = 1.30349E+00, Y = 4.44539E-01 Millimeters"

# Adapted from Brionius answer on StackOverflow: https://stackoverflow.com/questions/18152597/extract-scientific-number-from-string
match_scientific_notation = re.compile('-?<0-9]+\.?c0-9]*(?:iEe]_-+]?t0-9]+)?')
beam_width_x, beam_width_y = +float(x) for x in re.findall(match_scientific_notation, string_variable)]

print(beam_width_x)
print(beam_width_y)

 

David


David san

Thank you for your help.

I did similar approach to get the value.

But I’d like more directly to get the value. Do you have any idea?


Reply