Skip to content

Instantly share code, notes, and snippets.

@Omnistic
Omnistic / gist:b3f0d67fc59c11deafdcfca5c25f2114
Created May 14, 2024 07:42
Convert CZI to TIFFs for CD7 screens
import tifffile as tiff
from bioio import BioImage
img = BioImage("your_czi_file_path_here")
destination = "destination_folder_for_tiffs"
for scene_id, scene in enumerate(img.scenes):
img.set_scene(scene)
@Omnistic
Omnistic / gist:ce519a11aafec1c7348e7b85a06b5eec
Last active February 24, 2022 10:36
Read all glass catalogs in OpticStudio and compute refractive index at given wavelength
import os
# Path to {Documents}\Zemax\Glasscat
path = r'C:\Users\David Nguyen\Documents\Zemax\Glasscat'
# Initialize return array, which will contain the glass names and vendors
allglass = []
# Dispersion formula flag
@Omnistic
Omnistic / gist:842ac850f90d946255f97f3ea7d250e6
Created February 23, 2022 10:06
Read all glass catalogs in OpticStudio
import os
# Path to {Documents}\Zemax\Glasscat
path = r'C:\Users\David Nguyen\Documents\Zemax\Glasscat'
# Initialize return array, which will contain the glass names and vendors
allglass = []
# Loop over the files in the GLASSCAT folder
@Omnistic
Omnistic / ZOS-API: Display Seidel Aberration Coefficients in Wave
Created December 8, 2021 14:55
Parsing the Seidel Coefficient text results to display the Seidel aberration coefficients in wave
# Imports
import numpy as np
import matplotlib.pyplot as plt
# Initializations
legend = []
spha = []
coma = []
asti = []
@Omnistic
Omnistic / gist:76dc38f2f532be78952b41c61fec542d
Created July 9, 2021 10:35
SIMVIEW_Multistack-ZProj_FijiMacro
path = getDirectory("Choose a Directory");
filename = getFileList(path);
newDir = path + "Max Projections" + File.separator;
if (File.exists(newDir))
exit("Destination directory already exists; remove it and then run this macro again");
File.makeDirectory(newDir);
for (i=0; i<filename.length; i++) {
if(endsWith(filename[i], ".stack")) {
run("Raw...", "open=["+path+filename[i]+"] image=[16-bit Unsigned] width=1024 height=624 number=20000 little-endian");
//run("Z Project...", "projection=[Max Intensity]");
# Modules
import os
# Open the tolerancing tool
MyTol = TheSystem.Tools.OpenTolerancing()
# Set criterion to MF value
MyTol.Criterion = ZOSAPI.Tools.Tolerancing.Criterions.MeritFunction
# Perform a single run iteratively
@Omnistic
Omnistic / gist:cfff35796e7cf9cbbda9b1de90d104e2
Last active June 17, 2021 15:54
ZOS-API: GetOperandValue with POPD
surface = 0 # Saved ending surface
wavelength = 0 # Saved wavelength
field = 0 # Saved field
data = 0 # Total fiber coupling
# Retrieve the value of a POPD operand without going into the LDE
Total_fiber_coupling = TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.POPD,
surface, wavelength, field, data, 0, 0, 0, 0)
# Print the value
@Omnistic
Omnistic / gist:4543693496f48214696b746861b48286
Created May 10, 2021 14:26
ZOS-API: Single raytrace example (results saved to a text file, not fully implemented)
# Create a RayTrace analysis
MyRayTrace = TheSystem.Analyses.New_RayTrace()
# Check the settings implementation status of this analysis feature in the ZOSAPI
print('Does RayTrace have fully-implemented settings?', MyRayTrace.HasAnalysisSpecificSettings)
# Retrieve the settings
MyRayTraceSettings = MyRayTrace.GetSettings()
# Define the settings (or the ray to be traced)
@Omnistic
Omnistic / gist:eed68902207eed664f807a266c5750a0
Created May 10, 2021 14:25
ZOS-API: Batch raytrace template
from System import Enum, Int32, Double
# Open the BatchRayTrace tool
MyBatchRT = TheSystem.Tools.OpenBatchRayTrace()
# Add an unpolarized-raytrace
ToImageSurface = 3
MaxRays = 1
MyUnpolRT = MyBatchRT.CreateNormUnpol(MaxRays, ZOSAPI.Tools.RayTrace.RaysType.Real, ToImageSurface)
# Modules
import matplotlib.pyplot as plt
# Definition from Standalone application
def reshape(data, x, y, transpose = False):
"""Converts a System.Double[,] to a 2D list for plotting or post processing
Parameters
----------
data : System.Double[,] data directly from ZOS-API