Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
structured_beams
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Nunez Barreto
structured_beams
Commits
284d7b21
Commit
284d7b21
authored
Nov 06, 2024
by
Nicolas Nunez Barreto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
agrego codigo
parents
Pipeline
#79
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
0 deletions
+139
-0
fullcode_patterns.py
fullcode_patterns.py
+139
-0
No files found.
fullcode_patterns.py
0 → 100644
View file @
284d7b21
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 16 11:51:21 2024
@author: nicon
"""
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
scipy
import
signal
def
Grating
(
k
,
l
,
size
,
Binary
=
True
,
Blaze
=
False
,
powerblaze
=
1
,
BinaryFactor
=
0.25
,
Nx
=
10000
,
Ny
=
5000
,
phase1storder
=
0
,
mini
=
0
,
maxi
=
255
,
x0
=
0
,
y0
=
0
):
x
=
np
.
linspace
(
-
size
,
size
,
Nx
)
y
=
np
.
linspace
(
-
size
,
size
,
Ny
)
if
Binary
:
Pattern
=
[[
maxi
if
0.5
*
(
1
-
np
.
cos
(
k
*
xi
-
l
*
np
.
arctan2
(
xi
,
yj
)
-
phase1storder
))
>
BinaryFactor
else
mini
for
xi
in
x
]
for
yj
in
y
]
else
:
if
Blaze
:
Pattern
=
[]
for
yj
in
y
:
Pat
=
[]
for
xi
in
x
:
grati
=
maxi
*
0.5
*
(
1
-
arbpower_sawtooth
(
k
*
(
xi
-
x0
)
-
l
*
np
.
arctan2
(
xi
-
x0
,
yj
-
y0
)
-
phase1storder
,
power
=
powerblaze
,
width
=
1
))
Pat
.
append
(
grati
)
Pattern
.
append
(
Pat
)
else
:
Pattern
=
[]
for
yj
in
y
:
Pat
=
[]
for
xi
in
x
:
Pat
.
append
(
0.5
*
(
1
-
np
.
cos
(
k
*
(
xi
-
x0
)
-
l
*
np
.
arctan2
(
xi
-
x0
,
yj
-
y0
)
-
phase1storder
)))
Pattern
.
append
(
Pat
)
return
Pattern
,
x
,
y
def
arbpower_sawtooth
(
t
,
power
,
width
=
1
):
"""
Función para armar patrones de difracción con blaze
-power: parámetro de potencia. debe ser positivo. si está entre 0 y 1 es una función raiz. si es 1, es lineal. si es más de 1, potencia.
-width: si es 1 tiene una orientación y si es 0 tiene otra. no poner valores intermedios (por ahora)
"""
# Normaliza el valor de t a un rango de 0 a 1
t_mod
=
np
.
mod
(
t
,
2
*
np
.
pi
)
/
(
2
*
np
.
pi
)
# Para la parte creciente del ciclo: función de raíz cuadrada
positive_part
=
t_mod
**
power
# Para la parte decreciente del ciclo: invertimos la raíz cuadrada
negative_part
=
-
(
1
-
t_mod
)
**
power
# Combina ambas partes
result
=
2
*
np
.
abs
(
np
.
where
(
t_mod
<
width
,
positive_part
,
negative_part
))
-
1
return
result
def
on_key
(
event
):
xlim
=
ax
.
get_xlim
()
ylim
=
ax
.
get_ylim
()
step_sizex
=
(
max
(
xlim
)
-
min
(
xlim
))
/
len
(
x
)
# Ajusta este valor para cambiar la velocidad de desplazamiento
step_sizey
=
(
max
(
ylim
)
-
min
(
ylim
))
/
len
(
y
)
if
event
.
key
==
"right"
:
ax
.
set_xlim
(
xlim
[
0
]
+
step_sizex
,
xlim
[
1
]
+
step_sizex
)
# Mover derecha
elif
event
.
key
==
"left"
:
ax
.
set_xlim
(
xlim
[
0
]
-
step_sizex
,
xlim
[
1
]
-
step_sizex
)
# Mover izquierda
elif
event
.
key
==
"up"
:
ax
.
set_ylim
(
ylim
[
0
]
+
step_sizey
,
ylim
[
1
]
+
step_sizey
)
# Mover arriba
elif
event
.
key
==
"down"
:
ax
.
set_ylim
(
ylim
[
0
]
-
step_sizey
,
ylim
[
1
]
-
step_sizey
)
# Mover abajo
fig
.
canvas
.
draw_idle
()
# Redibujar la imagen sin regenerarla
#%%
size
=
1
#esto en realidad no cambia absolutamente nada
Nx
=
600
Ny
=
800
linewidth
=
150
k
=
1
*
np
.
pi
/
((
linewidth
/
10000
)
*
size
)
l
=
1
#para usar redes comunes pone l=0
mini
,
maxi
=
0
,
255
#numeros de 0 a 255 que definen los tonos de gris de las franjas
binary
=
'binary'
#posibles: binary o notbinary. para usar blaze usa notbinary
'''
si pones inverted cambiá Nx y Ny también!! Ny 800, Nx 600
'''
orientation
=
'inverted'
#posibles: inverted o notinverted si se quiere poner a 90° el patron
Blaze
=
False
bfactor
=
2
# Phase = [0,45,90,135,180]
Phase
=
[
0
]
for
p
in
Phase
:
# p = 90
phase
=
p
*
np
.
pi
/
180
binaryfactor
=
0.5
if
binary
==
'binary'
:
Pattern
,
x
,
y
=
Grating
(
np
.
pi
/
((
linewidth
/
10000
)
*
size
),
l
,
size
,
Binary
=
True
,
Blaze
=
Blaze
,
powerblaze
=
bfactor
,
BinaryFactor
=
binaryfactor
,
Nx
=
Nx
,
Ny
=
Ny
,
phase1storder
=
phase
,
mini
=
mini
,
maxi
=
maxi
)
else
:
Pattern
,
x
,
y
=
Grating
(
np
.
pi
/
((
linewidth
/
10000
)
*
size
),
l
,
size
,
Binary
=
False
,
Blaze
=
Blaze
,
powerblaze
=
bfactor
,
BinaryFactor
=
binaryfactor
,
Nx
=
Nx
,
Ny
=
Ny
,
phase1storder
=
phase
,
mini
=
mini
,
maxi
=
maxi
)
if
orientation
==
'inverted'
:
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
6
,
8
),
dpi
=
100
)
c
=
plt
.
pcolor
(
np
.
transpose
(
Pattern
),
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
255
)
else
:
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
8
,
6
),
dpi
=
100
)
c
=
plt
.
pcolor
(
Pattern
,
cmap
=
'gray'
,
vmin
=
0
,
vmax
=
255
)
plt
.
xticks
([])
plt
.
yticks
([])
plt
.
gca
()
.
set_position
([
0
,
0
,
1
,
1
])
#plt.subplots_adjust(left=0, right=1, top=1. bottom=0)
#plt.rcParams["figure.autolayout"] = False
manager
=
plt
.
get_current_fig_manager
()
manager
.
full_screen_toggle
()
print
(
f
'done {p}'
)
# Conectar la función al evento de teclado
fig
.
canvas
.
mpl_connect
(
"key_press_event"
,
on_key
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment