Skip to content

Commit

Permalink
Updated sim
Browse files Browse the repository at this point in the history
  • Loading branch information
jmp1985 committed Jun 3, 2021
1 parent a2b1b9f commit 776c1b3
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/parakeet/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,12 @@ def compute_image(psi, microscope, simulation, x_fov, y_fov, offset, device):
elif self.simulation["inelastic_model"] == "mp_loss":

# Set the filter width
filter_width = self.simulation["mp_loss_width"]
filter_width = self.simulation["mp_loss_width"] # eV

# Compute the energy and spread of the plasmon peak
peak, sigma = parakeet.inelastic.most_probable_loss(
microscope.beam.energy, shape, angle
)
) # eV
# if filter_width is not None:
# normal = scipy.stats.norm(loc=0, scale=sigma)
# inelastic_fraction = normal.cdf(filter_width) - normal.cdf(
Expand Down Expand Up @@ -971,14 +971,13 @@ def compute_image(psi, microscope, simulation, x_fov, y_fov, offset, device):
# spread = sigma / (microscope.beam.energy * 1000)

# Save the energy and energy spread
beam_energy = microscope.beam.energy
beam_energy_spread = microscope.beam.energy_spread
beam_energy_sigma = beam_energy_spread * microscope.beam.energy * 1000
beam_energy = microscope.beam.energy # keV
beam_energy_spread = microscope.beam.energy_spread # dE / E
beam_energy_sigma = beam_energy_spread * microscope.beam.energy * 1000 # eV

# Compute the peak and spread
peak /= 1000.0
peak = min(peak, microscope.beam.energy * 0.1)
spread = sigma / (microscope.beam.energy * 1000)
peak = min(peak, 1000 * microscope.beam.energy * 0.1) # eV
spread = sigma / (microscope.beam.energy * 1000) # dE / E

# Compute the spread using the filter width
if filter_width is not None:
Expand All @@ -1005,20 +1004,26 @@ def compute_image(psi, microscope, simulation, x_fov, y_fov, offset, device):
inelastic_sigma = sigma

# Compute the spread
elastic_spread = elastic_sigma / (microscope.beam.energy * 1000)
inelastic_spread = inelastic_sigma / (microscope.beam.energy * 1000)
microscope.beam.energy_spread = beam_energy_spread + elastic_spread
elastic_spread = elastic_sigma / (microscope.beam.energy * 1000) # dE / E
inelastic_spread = inelastic_sigma / (
microscope.beam.energy * 1000
) # dE / E
microscope.beam.energy_spread = (
beam_energy_spread + elastic_spread
) # dE / E

# Compute the zero loss image
image1 = compute_image(
psi, microscope, self.simulation, x_fov, y_fov, offset, self.device
)

# Add the energy loss
microscope.beam.energy = beam_energy - peak
microscope.beam.energy = beam_energy - peak / 1000.0 # keV

# Compute the energy spread of the plasmon peak
microscope.beam.energy_spread = beam_energy_spread + inelastic_spread
microscope.beam.energy_spread = (
beam_energy_spread + inelastic_spread
) # dE / E
print("Energy: %f keV" % microscope.beam.energy)
print("Energy spread: %f ppm" % microscope.beam.energy_spread)

Expand All @@ -1044,21 +1049,20 @@ def compute_image(psi, microscope, simulation, x_fov, y_fov, offset, device):
# Compute the energy and spread of the plasmon peak
peak, sigma = parakeet.inelastic.most_probable_loss(
microscope.beam.energy, shape, angle
)
peak /= 1000.0
peak = min(peak, microscope.beam.energy * 0.1)
spread = sigma / (microscope.beam.energy * 1000)
) # eV
peak = min(peak, 1000 * microscope.beam.energy * 0.1) # eV
spread = sigma / (microscope.beam.energy * 1000) # dE / E

# Compute the zero loss image
image1 = compute_image(
psi, microscope, self.simulation, x_fov, y_fov, offset, self.device
)

# Add the energy loss
microscope.beam.energy -= peak
microscope.beam.energy -= peak / 1000 # keV

# Compute the energy spread of the plasmon peak
microscope.beam.energy_spread += spread
microscope.beam.energy_spread += spread # dE / E
print("Energy: %f keV" % microscope.beam.energy)
print("Energy spread: %f ppm" % microscope.beam.energy_spread)

Expand Down

0 comments on commit 776c1b3

Please sign in to comment.