Skip to main content

Is there a way to define several wavelengths that is more efficient than adding them one by one in the System Explorer?

If you open go to the System Explorer and double click on Wavelengths, you can open the Wavelength data in a table.





From here, you can enable as many fields as you want by checking the box on the left and define the wavelengths and weights for each one.



 


Sounds like the answer is “no”.


Currently only the bottom block has some built-in wavelength settings. If there is no data you need here, you have to enter it manually.

 


Hi everyone,

 

To complement this answer, whenever there’s a task that is easy, and repetitive, I use ZPL macros. In the case of the wavelength data editor, the value is limited because there is a maximum of 24 wavelengths that can be defined. That being said, the main keyword for this task is SYSP, it enables modifying system explorer data, such as the wavelengths. SYSP should be used with a code identifying the parameter to be modifed, and its associated value. For the wavelength data, 200 is the primary wavelength, 201 is the number of active wavelengths, 202 is the wavelength in micrometers, and 203 is the weight for the wavelength (more details in the Help File under The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > SETSYSTEMPROPERTY, SYSP). I’ve made a simple example to illustrate how one can automatically create a Gaussian spectrum centred about 0.55 um with a 0.05 um standard deviation in the visible (0.45-0.65 um) region over the 24 wavelengths that editor permits:

 

# Codes definition for SYSP keyword
wave_primary = 200
wave_number = 201
wave_um_code = 202
wave_weight_code = 203

# Gaussian spectrum definition in micrometers
mean_spec = 0.55
std_spec = 0.05

# Number of wavelengths
n_wave = 24

# Apply the number of wavelengths to the system explorer and place the primary wave at the center
SYSP wave_primary, n_wave/2+1
SYSP wave_number, n_wave

# Wavelength range
start_wave = 0.45
stop_wave = 0.65

# Loop over the wavelengths
FOR wave_id, 1, n_wave, 1
    # Calculate current wavelength in micrometers
    wavelength = start_wave + (wave_id-1) * (stop_wave-start_wave) / (n_wave-1)
    
    # Calculate corresponding weight from a Gaussian distribution
    weight = EXPE(-POWR(wavelength-mean_spec, 2) / (2 * POWR(std_spec, 2)))
    
    # Apply to system explorer
    SYSP wave_um_code, wave_id, wavelength
    SYSP wave_weight_code, wave_id, weight
NEXT

 

I’ve also attached the macro to my post. To install it, download, extract, and copy this file to your Documents\Zemax\Macros folder, and from OpticStudio go to the Programming tab, and press Edit/Run in the ZPL Macros ribbon. Then,  browse to the macro file, and press Execute. It should automatically populate the wavelength editor.

I hope this helps.

Take care,

 

David

 


@David.Nguyen Thank you for the macro! Is there a way to define multiple wavelengths with equal weight?


Hi @mcwikla,

 

The weights in my macros are calculated inside the FOR-loop with this line of code:

weight = EXPE(-POWR(wavelength-mean_spec, 2) / (2 * POWR(std_spec, 2)))

By taking the weight variable out of this loop and giving it a constant value, all the wavelengths inside the loop will be asigned the same weight. This is the code if I just slightly modify the original macro:

# Codes definition for SYSP keyword
wave_primary = 200
wave_number = 201
wave_um_code = 202
wave_weight_code = 203

# Number of wavelengths
n_wave = 24

# Apply the number of wavelengths to the system explorer and place the primary wave at the center
SYSP wave_primary, n_wave/2+1
SYSP wave_number, n_wave

# Wavelength range
start_wave = 0.45
stop_wave = 0.65

# Constant weight
weight = 1.234

# Loop over the wavelengths
FOR wave_id, 1, n_wave, 1
# Calculate current wavelength in micrometers
wavelength = start_wave + (wave_id-1) * (stop_wave-start_wave) / (n_wave-1)

# Apply to system explorer
SYSP wave_um_code, wave_id, wavelength
SYSP wave_weight_code, wave_id, weight
NEXT

And this is what the result would be:

As you can see, all wavelengths have a weight of 1.234 now.

Hope this helps, and take care,

 

David


As a complement to this topic, I made very similar program to @David.Nguyen’s one, but in Python. It allows to create .wav file which can be further loaded into Zemax via “Load” button in wavelength settings. Maybe someone would find it useful.

import csv
import os

n = 24 # number of wavelengths to be generated
weight = 1.0 # weight of each wavelength
step = 0.010 # step between wavelengths eum]
wav_cen = 0.575 # central wavelength lum]
wav_start = (wav_cen-n/2*step) # first wavelength lum]

with open ('wavelength_Zemax.csv', 'w') as file:
    writer=csv.writer(file, delimiter='\t', lineterminator='\n')
    writer.writerow('1') # adding weird row filed with '1', that Zemax needs
    wav = wav_start
    for i in range(n):
        wav = round(wav, 3) # round wavelength to 3 decimal digits
        row = bwav, weight] # fill the row with wavelength value and weight
        wav = wav + step # temporal wavelength is increased by step value
        writer.writerow(row) # write the row

#convering file extension from .csv to .wav
file = 'wavelength_Zemax.csv'
base = os.path.splitext(file)/0]
os.rename(file, base + '.wav')

Cheers.

 


Reply