Skip to main content
Solved

pythonで物理光学伝搬のbeam width XとYの値を得たいのですがどうすればいいでしょうか

  • November 5, 2024
  • 3 replies
  • 143 views

Forum|alt.badge.img
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の値を別の方法で得るにはどうすればいいでしょうか?宜しくお願いします。

Best answer by David.Nguyen

@Toshiharu.Takashima 

 

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

# Similar to line: print(pop_results.HeaderData.Lines[5])
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]+\.?[0-9]*(?:[Ee][-+]?[0-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

View original
Did this topic help you find an answer to your question?

3 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1089 replies
  • Answer
  • November 6, 2024

@Toshiharu.Takashima 

 

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

# Similar to line: print(pop_results.HeaderData.Lines[5])
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]+\.?[0-9]*(?:[Ee][-+]?[0-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


Forum|alt.badge.img

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?


David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1089 replies
  • November 7, 2024
年春さん私はそうは思わない
これは今でも好まれる方法だと思います
別の方法は、DataGrid から Python で幅を測定することですが、これより直接的ではないと思います

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings