Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added layer dialog and experiment dialog #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/_examples/step/tethered.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
S2 = Experiment(sample=sample, probe=probe,
dz=1, dA=10, step_interfaces=True,
name="dz=1; dA=10; step interfaces")

models=[M0,M1,M2,S0,S1,S2]
#models=[S1]
problem = MultiFitProblem(models=models)
Expand Down
25 changes: 21 additions & 4 deletions refl1d/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,36 @@ def __init__(self, sample=None, probe=None, name=None,
self.sample = sample
self._substrate=self.sample[0].material
self._surface=self.sample[-1].material
self.probe = probe
self.roughness_limit = roughness_limit
if dz is None:
dz = nice((2*pi/probe.Q.max())/10)
if dz > 5: dz = 5
self.dz = dz
# TODO: probe and dz are mutually dependent
self._slabs = profile.Microslabs(1, dz=dz)
self.probe = probe
self.dA = dA
self.step_interfaces = step_interfaces
self._slabs = profile.Microslabs(len(probe.unique_L) if probe.unique_L is not None else 1, dz=dz)
self._probe_cache = material.ProbeCache(probe)
self._cache = {} # Cache calculated profiles/reflectivities
self._name = name

@property
def probe(self):
return self._probe

@probe.setter
def probe(self, probe):
self._probe = probe
self._probe_cache = material.ProbeCache(probe)
self._slabs.nprobe = len(probe.unique_L) if probe.unique_L is not None else 1

@property
def dz(self):
return self._slabs.dz

@dz.setter
def dz(self, value):
self._slabs.dz = value

@property
def ismagnetic(self):
slabs = self._render_slabs()
Expand Down
4 changes: 3 additions & 1 deletion refl1d/fitplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def load_model(filename):
return None

def new_model():
stack = refl.silicon(0,10) | refl.air
silicon = refl.SLD('Si', 2.07)
air = refl.SLD('air', 0)
stack = silicon(0, 10) | air
instrument = refl.NCNR.NG1()
probe = instrument.probe(T=numpy.linspace(0,5,200),
Tlo=0.2, slits_at_Tlo=2)
Expand Down
9 changes: 8 additions & 1 deletion refl1d/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# => smaller roughness
# => thickness depends on where the beam spot hits the sample
# Xray thickness variance = neutron roughness - xray roughness
from refl1d.material import SLD


__all__ = ['Repeat','Slab','Stack','Layer']
Expand All @@ -34,6 +35,7 @@
import periodictable.nsf as nsf

from bumps.parameter import Parameter as Par, IntegerParameter as IntPar, Function
from bumps.gui import signal

from . import material

Expand Down Expand Up @@ -455,14 +457,19 @@ def __setitem__(self, idx, other):
def __delitem__(self, idx):
stack,idx = self._lookup(idx)
# works the same for slices and individual indices
del stack._layers[idx]
if(len(stack)>2 and (idx>=0 and idx < len(stack))):
del stack._layers[idx]
else:
raise ValueError("You cannot remove this layer. You need at least 2 layers!")


def insert(self, idx, other):
"""
Insert structure into a stack. If the inserted element is
another stack, the stack will be expanded to accommodate. You
cannot make nested stacks.
"""

stack,idx = self._lookup(idx)
if isinstance(other,Stack):
for i,L in enumerate(other._layers):
Expand Down
4 changes: 2 additions & 2 deletions refl1d/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ def __init__(self, Q, dQ, data=None, name=None,
self.back_absorption = Parameter.default(back_absorption,
name="back_absorption"+qualifier,
limits=[0,1])
self.theta_offset = Constant(0,name="theta_offset"+qualifier)
self.theta_offset = Constant(0, name="theta_offset"+qualifier)

self.back_reflectivity = back_reflectivity

Expand All @@ -1045,7 +1045,6 @@ def __init__(self, Q, dQ, data=None, name=None,
self.calc_Qo = self.Qo
self.name = name


def measurement_union(xs):
"""
Determine the unique (T,dT,L,dL) across all datasets.
Expand Down Expand Up @@ -1175,6 +1174,7 @@ def oversample(self, n=6, seed=1):
T = T.flatten()
L = L.flatten()
self._set_calc(T,L)

oversample.__doc__ = Probe.oversample.__doc__

@property
Expand Down
8 changes: 8 additions & 0 deletions refl1d/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def __init__(self, nprobe, dz=1):
self._z_offset = 0
self._magnetic_sections = []

@property
def nprobe(self):
return self._slabs_rho.shape[1]
@nprobe.setter
def nprobe(self, n):
if self.nprobe != n:
self._slabs_rho = numpy.empty(shape=(0,nprobe,2))

def microslabs(self, thickness=0):
"""
Return a set of microslabs for a layer of the given *thickness*.
Expand Down
3 changes: 2 additions & 1 deletion refl1d/view/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .config import interface_color, pick_radius
from .interactor import BaseInteractor
from .util import clip, setpar
import numpy

MAX_ROUGH=3

Expand All @@ -24,7 +25,7 @@ def __init__(self, profile):
color = interface_color,
alpha = 0.6,
pickradius = pick_radius,
zorder = 8, #Prefer this to other lines
zorder = numpy.inf, #Prefer this to other lines
visible = False,
)
self.markers=[ax.plot([0],[0.05], label=label, **style)[0]
Expand Down
Loading