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

Michaelgemmell/bayes workflow #285

Closed
wants to merge 203 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
b7425f1
initial commit
michael-gemmell Mar 28, 2023
aae4c47
magnetic recon tests
michael-gemmell Mar 28, 2023
3100262
use error attribute if it is given
michael-gemmell Mar 30, 2023
ba574ec
Added poisson noise and adjusted calibration factor
michael-gemmell Mar 30, 2023
d5fec79
changed name magnetic_recon -> equilibrium_reconstruction
michael-gemmell Mar 30, 2023
56c769a
diagnostic data with channel dim are treated as individual measurements
michael-gemmell Mar 30, 2023
91d7e66
added function of example LOS
michael-gemmell Mar 31, 2023
37cd733
refactoring
michael-gemmell Mar 31, 2023
6dbebc6
refactoring
michael-gemmell Mar 31, 2023
57c6a66
refactoring
michael-gemmell Mar 31, 2023
ac904b6
initial commit
michael-gemmell Mar 31, 2023
4fa0bb1
removed obsolete attributes
michael-gemmell Mar 31, 2023
4a5c5b3
Setting up testflow
michael-gemmell Mar 31, 2023
31f306b
more tests
michael-gemmell Mar 31, 2023
66e6b22
more test stubs
michael-gemmell Mar 31, 2023
b9e61c2
small fix
michael-gemmell Apr 12, 2023
1e51df8
Merge branch 'michaelgemmell/magnetic_recon_diagnostic' into michaelg…
michael-gemmell Apr 25, 2023
ccfe635
cosmetic changes
michael-gemmell Apr 25, 2023
c8cd11b
changed marker style
michael-gemmell Apr 25, 2023
b386b48
merged with st40
michael-gemmell Apr 25, 2023
dced6d5
Merge branch 'st40' into michaelgemmell/bayes_dev
michael-gemmell Apr 27, 2023
5655cef
small fix
michael-gemmell Apr 27, 2023
40e5cb5
adjusting alpha
michael-gemmell Apr 27, 2023
60f26f9
Merge branch 'st40' into michaelgemmell/bayes_dev
michael-gemmell May 3, 2023
210bf7c
black reformatting
michael-gemmell May 3, 2023
efe2281
fixing formatting
michael-gemmell May 3, 2023
7ac95c4
flake8 fix
michael-gemmell May 3, 2023
cea6161
flake8 fix
michael-gemmell May 3, 2023
5baea04
fixing merge conflicts
michael-gemmell May 3, 2023
0aac384
boolean indexing -> xarray.where in call
michael-gemmell May 3, 2023
0259f22
fixing tests
michael-gemmell May 3, 2023
8cf4567
removing import
michael-gemmell May 3, 2023
8170cdd
precommit fixes
michael-gemmell May 3, 2023
96f1f5c
stashing for quick result
michael-gemmell May 12, 2023
7e1fda1
added calc_impurity for generating profiles from concentrations to up…
michael-gemmell May 22, 2023
402cd2d
added conditional handling of diagnostics in data pipeline
michael-gemmell May 22, 2023
fb7704f
moved calc_impurity to plasma method
michael-gemmell May 22, 2023
4997194
tweaking calibration factor
michael-gemmell May 22, 2023
c8e821f
tweaking calibration factor
michael-gemmell May 22, 2023
5bb0b51
tweaking calibration factor
michael-gemmell May 22, 2023
457da6b
changed burn_in to burn_in_fraction
michael-gemmell May 23, 2023
4b88ffe
added violinplots
michael-gemmell May 23, 2023
86e3784
removed comment
michael-gemmell May 23, 2023
eb13c00
included dictionary logic for fitting impurities scaled by concentrat…
michael-gemmell May 23, 2023
8987311
changed name cxff_pi.ti_0d to cxff_pi.ti0
michael-gemmell May 23, 2023
a9b6b18
new option for initialising at maximum-likelihood estimate
michael-gemmell May 24, 2023
1fa8427
added xlim for violin plot
michael-gemmell May 24, 2023
db2d0e1
tweaking calibration
michael-gemmell May 31, 2023
ce73ee5
fixed neutral density units
michael-gemmell May 31, 2023
eda445a
added set plot functions
michael-gemmell May 31, 2023
2555605
added center mass sampling and Ti/Te y0_ref options
michael-gemmell May 31, 2023
20ae704
plot formatting changed
michael-gemmell May 31, 2023
e0b9c03
black formatting
michael-gemmell May 31, 2023
dfabdd0
deleted example bayes_opt
michael-gemmell May 31, 2023
b21b66d
moved sample with autocorr function to bayes_dev_workflow
michael-gemmell May 31, 2023
2f78d9d
renamed bayesworkflow
michael-gemmell May 31, 2023
9ed488e
stashing
michael-gemmell Jun 13, 2023
533a44a
multiplot formatting
michael-gemmell Jun 22, 2023
751ca81
generalised writing kinetic profiles to blobs
michael-gemmell Jun 27, 2023
59c8316
function autocorr plot added
michael-gemmell Jun 27, 2023
b2dee2d
ion density added to kinetic profiles saved
michael-gemmell Jun 27, 2023
8eee24e
inital commit of abstract workflow and example of usage
michael-gemmell Jun 27, 2023
408b619
doc strings
michael-gemmell Jun 27, 2023
de237dd
renaming workflow
michael-gemmell Jun 27, 2023
06c0746
Ti_ref as default
michael-gemmell Jun 30, 2023
5435769
abstract methods added
michael-gemmell Jun 30, 2023
ee3a62e
Changed to new MDSPlus structure
michael-gemmell Jul 4, 2023
a8ca5fa
Adding default methods
michael-gemmell Jul 4, 2023
6f1e330
moved sampling to it's own function in abstract class
michael-gemmell Jul 4, 2023
dd3abdf
moved sampling to it's own function in abstract class
michael-gemmell Jul 4, 2023
6f9d4a8
renamed abstract class to AbstractBayesWorkflow
michael-gemmell Jul 4, 2023
55e2f8f
comments
michael-gemmell Jul 4, 2023
d3bf315
added high density sampling as method
michael-gemmell Jul 4, 2023
430a44b
added attributes to __init__
michael-gemmell Jul 4, 2023
d633ae5
error handling __init__
michael-gemmell Jul 4, 2023
35b64cf
error handling __init__
michael-gemmell Jul 4, 2023
633b36c
moved read data to abstract class
michael-gemmell Jul 4, 2023
2ce1c58
initial commit
michael-gemmell Jul 7, 2023
08cf081
kwargs added
michael-gemmell Jul 7, 2023
82eb00b
xrcs wavelength units corrected
michael-gemmell Jul 7, 2023
666387b
background to int
michael-gemmell Jul 7, 2023
3690efb
stash
michael-gemmell Jul 11, 2023
3c23661
renamed impurities
michael-gemmell Jul 11, 2023
bf3bfb9
stashing
michael-gemmell Jul 12, 2023
fbfafe5
stashing
michael-gemmell Jul 13, 2023
9f62a78
stashing
michael-gemmell Jul 14, 2023
3828c49
fixing key names
michael-gemmell Jul 14, 2023
310a440
updating and testing example
michael-gemmell Jul 14, 2023
d8f9be5
added background as attribute of helike model
michael-gemmell Jul 14, 2023
1f0a0f9
fixed phantom methods
michael-gemmell Jul 14, 2023
7623a54
rearranged methods
michael-gemmell Jul 14, 2023
b3b7a26
moved background to call kwarg
michael-gemmell Aug 2, 2023
4a7e022
params and kwargs now are given as model_{var} and model prefix is re…
michael-gemmell Aug 2, 2023
e78f638
adding _phantom_data and _exp_data abstract methods
michael-gemmell Aug 2, 2023
82d6fee
renaming to BayesWorkflowExample
michael-gemmell Aug 2, 2023
2c1c48a
initial commit
michael-gemmell Aug 2, 2023
c7a2ca5
renamed phantom_params to profile_params
michael-gemmell Aug 2, 2023
db25e70
renamed bayesopt -> bayesmodel
michael-gemmell Aug 2, 2023
b1c5bd3
renamed bayesopt -> bayesmodel
michael-gemmell Aug 2, 2023
f78ce64
moved start point sampling to its own method _sample_start_points
michael-gemmell Aug 2, 2023
c3a418b
fixed variable name
michael-gemmell Aug 2, 2023
196eb60
fixed bug with start_points being overwritten
michael-gemmell Aug 2, 2023
31542b0
removed workflow_dev
michael-gemmell Aug 8, 2023
cc218b4
moving equilibrium to workflow object
michael-gemmell Aug 8, 2023
9cb0266
when reading raw data save transforms to their own attribute
michael-gemmell Aug 8, 2023
68c1872
transforms saved to workflow class
michael-gemmell Aug 8, 2023
f0f561f
fixed name
michael-gemmell Aug 8, 2023
3b2eaee
renamed example transform
michael-gemmell Aug 8, 2023
ae200d3
made example los function
michael-gemmell Aug 8, 2023
3d9d540
minor name fix
michael-gemmell Aug 8, 2023
cd04fb1
made read_test_data function
michael-gemmell Aug 8, 2023
dfdd791
made example los function
michael-gemmell Aug 8, 2023
4c6c1c2
minor type
michael-gemmell Aug 8, 2023
0ce85fa
added reader to read_test_data method
michael-gemmell Aug 8, 2023
fa5ac44
fixed copying workflow object states
michael-gemmell Aug 8, 2023
7d343a4
updated example to work with assign_profiles
michael-gemmell Aug 8, 2023
489d14a
can now run with pulse = None and synthetic transforms/equilibrium
michael-gemmell Aug 8, 2023
e04fe9b
formatting
michael-gemmell Aug 8, 2023
6fcff75
refactoring names
michael-gemmell Aug 8, 2023
eba8ca7
deleted old bayes_models tests
michael-gemmell Aug 8, 2023
b6ece95
reformatted _build_bckc for readability
michael-gemmell Aug 8, 2023
2bd93bf
moved percentage error to class attribute
michael-gemmell Aug 8, 2023
e46ac8a
fixing init percent error
michael-gemmell Aug 8, 2023
cc0aafd
black formatting
michael-gemmell Aug 8, 2023
acc50b5
renamed kin_prof -> plasma_profiles
michael-gemmell Aug 10, 2023
223a526
refactored window handling
michael-gemmell Aug 10, 2023
c9333ae
replaced doppler_broaden with physics.ev_doppler
michael-gemmell Aug 10, 2023
80bc391
removed methods from __init__
michael-gemmell Aug 10, 2023
3f5c089
stashing
michael-gemmell Aug 11, 2023
766825a
setup_plasma now takes kwargs
michael-gemmell Aug 15, 2023
cb93ae8
adding plasma to models now happens in setup_opt_data
michael-gemmell Aug 15, 2023
cf1c127
workflow broken up into methods
michael-gemmell Aug 15, 2023
3019e45
Merge branch 'st40' into michaelgemmell/bayes_workflow
michael-gemmell Aug 15, 2023
260a515
removed redundant kwargs
michael-gemmell Aug 15, 2023
0821b9d
fixed non_plasma call option
michael-gemmell Aug 15, 2023
78800c6
fixed plasma_initialisation
michael-gemmell Aug 15, 2023
62d6727
fixing violin plotting
michael-gemmell Aug 15, 2023
98190dd
units for xrcs.spectra.wavelength fixed
michael-gemmell Aug 15, 2023
f732da0
nchannels added to example_los
michael-gemmell Aug 17, 2023
ec1c9ca
adding print message for fake data reading
michael-gemmell Aug 17, 2023
b0fac37
adjusting example los
michael-gemmell Aug 17, 2023
03d68c7
bckc method not printing spectra/fit not available everytime
michael-gemmell Aug 17, 2023
72e6e7e
adjusting priors
michael-gemmell Aug 17, 2023
d5ebe08
moved kwargs to sample function
michael-gemmell Aug 17, 2023
056b7f5
nsamples kwarg added to sample_from_high_density_region
michael-gemmell Aug 17, 2023
e1b35c5
mocked bda_tree module
michael-gemmell Aug 17, 2023
3733bc6
fixed import
michael-gemmell Aug 17, 2023
b0f3fae
fixed import
michael-gemmell Aug 17, 2023
ad9400a
black formatting
michael-gemmell Aug 17, 2023
f0a1d65
black formatting
michael-gemmell Aug 17, 2023
3b1dcd8
fixed where mocked module is imported
michael-gemmell Aug 17, 2023
b8b6cee
black formatting
michael-gemmell Aug 17, 2023
d3e4e5c
mocking bda_tree import
michael-gemmell Aug 17, 2023
a7ec4cd
precommit
michael-gemmell Aug 17, 2023
b1babc4
precommit
michael-gemmell Aug 17, 2023
8e2f2d8
moving read_data tvector to kwargs
michael-gemmell Aug 17, 2023
519c4ed
precommit formatting
michael-gemmell Aug 17, 2023
f7623ce
precommit formatting
michael-gemmell Aug 17, 2023
67bd35c
precommit types
michael-gemmell Aug 17, 2023
d1afc87
precommit types
michael-gemmell Aug 17, 2023
1f38f27
precommit types
michael-gemmell Aug 17, 2023
c555f6b
precommit types
michael-gemmell Aug 17, 2023
b5d5840
precommit types
michael-gemmell Aug 17, 2023
9d12492
precommit types
michael-gemmell Aug 17, 2023
15c4aac
precommit types
michael-gemmell Aug 17, 2023
4362cd5
moving kwargs/args around
michael-gemmell Aug 17, 2023
37fff66
adding mode/run to main call
michael-gemmell Aug 22, 2023
d5b5eb5
pressure/stored energy are now saved/written
michael-gemmell Aug 22, 2023
07c6895
removing for loops from pressure/ion density/zeff calculations
michael-gemmell Aug 22, 2023
845954b
removing for loops from ion density calculations
michael-gemmell Aug 22, 2023
83ede9e
defaulting to using cached calculations -> factor 2 speed upgit add i…
michael-gemmell Aug 22, 2023
ca5900c
example transform moved to own function
michael-gemmell Aug 22, 2023
741808e
t = time_to_calculate and bckc don't print if chi2 not included
michael-gemmell Aug 22, 2023
cf3b01f
Thompson Scattering added
michael-gemmell Aug 23, 2023
e4fe2bc
error checking for missing data
michael-gemmell Aug 23, 2023
b316163
in _make_spectra moved sorting wavelengths to end of method and fixed…
michael-gemmell Aug 24, 2023
bc56b39
integrating spectra was removing nans so added them back post integra…
michael-gemmell Aug 24, 2023
5368990
pixel offset added as __call__ option
michael-gemmell Aug 24, 2023
82208ca
time vector in INPUTS added
michael-gemmell Aug 24, 2023
da94202
adjusting calibration factor
michael-gemmell Sep 4, 2023
0abbaaa
max-min ranges now 0.5-99.5
michael-gemmell Sep 4, 2023
6114dc4
high_density_sampling now uses 3 best points
michael-gemmell Sep 4, 2023
d210b28
Gelmin-Rubin diagnostic added to optimisation node
michael-gemmell Sep 4, 2023
7e7d02d
Gelman-Rubin diagnostic added to tree
michael-gemmell Sep 4, 2023
e3c2abf
stashing
michael-gemmell Sep 4, 2023
cb0df2a
now accepts variable number of input parameters and fills missing val…
michael-gemmell Sep 6, 2023
b48ea95
priors now more constrained for wped/wcenter
michael-gemmell Sep 6, 2023
90c38fb
priors now more constrained for wped/wcenter
michael-gemmell Sep 6, 2023
51ee0d9
fast particles from ASTRA included
michael-gemmell Sep 11, 2023
3979531
Merge branch 'st40' into michaelgemmell/bayes_workflow
marcosertoli Sep 11, 2023
b9d09e2
ASTRA options added to BDA
michael-gemmell Sep 12, 2023
4089d41
chers added
michael-gemmell Sep 12, 2023
e74ed9a
chers added
michael-gemmell Sep 12, 2023
f4bc980
Extra ASTRA options implemented
michael-gemmell Sep 13, 2023
875293c
prior for ne.wped increased to 30
michael-gemmell Sep 13, 2023
6545540
not automatically adding equil to transforms now
michael-gemmell Sep 13, 2023
fd859b5
Fixed plotting for multiple time points
michael-gemmell Sep 21, 2023
01ea6b4
save_pickle now takes dictionary as argument
michael-gemmell Sep 21, 2023
ada6ce0
stashing
michael-gemmell Sep 21, 2023
5609b93
stashing
michael-gemmell Sep 21, 2023
1e18dc3
merging
michael-gemmell Sep 21, 2023
ecdbb65
Rough batch script for running BDA
michael-gemmell Sep 21, 2023
9cd5d26
merging
michael-gemmell Sep 21, 2023
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
23 changes: 14 additions & 9 deletions indica/bayesmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
warnings.simplefilter("ignore", category=FutureWarning)


PROFILES = [
PLASMA_ATTRIBUTES = [
"electron_temperature",
"electron_density",
"ion_temperature",
Expand All @@ -17,6 +17,10 @@
"fast_density",
"neutral_density",
"zeff",
"wp",
"wth",
"ptot",
"pth",
]


Expand Down Expand Up @@ -196,10 +200,11 @@ def sample_from_priors(self, param_names, size=10):
def sample_from_high_density_region(
self, param_names: list, sampler, nwalkers: int, nsamples=100
):
# TODO: implement smarter MLE (maximum likelihood estimate)
start_points = self.sample_from_priors(param_names, size=nsamples)

ln_prob, _ = sampler.compute_log_prob(start_points)
num_best_points = int(nsamples * 0.05)
num_best_points = 3
index_best_start = np.argsort(ln_prob)[-num_best_points:]
best_start_points = start_points[index_best_start, :]
best_points_std = np.std(best_start_points, axis=0)
Expand All @@ -209,7 +214,7 @@ def sample_from_high_density_region(
while samples.size < param_names.__len__() * nwalkers:
sample = np.random.normal(
np.mean(best_start_points, axis=0),
best_points_std * 2,
best_points_std,
size=(nwalkers * 5, len(param_names)),
)
start = {name: sample[:, idx] for idx, name in enumerate(param_names)}
Expand Down Expand Up @@ -249,14 +254,14 @@ def ln_posterior(self, parameters: dict, **kwargs):
ln_likelihood = self._ln_likelihood() # compare results to data
ln_posterior = ln_likelihood + ln_prior

plasma_profiles = {}
for profile_key in PROFILES:
if hasattr(self.plasma, profile_key):
plasma_profiles[profile_key] = getattr(self.plasma, profile_key).sel(
plasma_attributes = {}
for plasma_key in PLASMA_ATTRIBUTES:
if hasattr(self.plasma, plasma_key):
plasma_attributes[plasma_key] = getattr(self.plasma, plasma_key).sel(
t=self.plasma.time_to_calculate
)
else:
raise ValueError(f"plasma does not have attribute {profile_key}")
raise ValueError(f"plasma does not have attribute {plasma_key}")

blob = deepcopy({**self.bckc, **plasma_profiles})
blob = deepcopy({**self.bckc, **plasma_attributes})
return ln_posterior, blob
14 changes: 9 additions & 5 deletions indica/models/helike_spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(
name: str,
instrument_method="get_helike_spectroscopy",
etendue: float = 1.0,
calibration: float = 8.0e-20,
calibration: float = 1.0e-18,
element: str = "ar",
window_len: int = 1030,
window_lim=None,
Expand Down Expand Up @@ -204,18 +204,18 @@ def _make_spectra(self, calc_rho: bool = False):
),
)
spectra = xr.concat([_spectra, empty], "wavelength")
spectra = spectra.sortby("wavelength")

self.spectra = spectra

measured_spectra = self.los_transform.integrate_on_los(
self.spectra,
t=self.spectra.t,
calc_rho=calc_rho,
)
self.measured_spectra = measured_spectra.assign_coords(
{"wavelength": self.window.wavelength}
measured_spectra = measured_spectra.assign_coords(
{"wavelength": self.spectra.wavelength}
)
measured_spectra[measured_spectra==0] = np.nan
self.measured_spectra = measured_spectra.sortby("wavelength")
self.spectra_los = self.los_transform.along_los

def _moment_analysis(self):
Expand Down Expand Up @@ -386,6 +386,7 @@ def __call__(
calc_rho: bool = False,
moment_analysis: bool = False,
background: int = None,
pixel_offset: int = None,
**kwargs,
):
"""
Expand Down Expand Up @@ -462,6 +463,9 @@ def __call__(
if background is not None:
self.measured_spectra = self.measured_spectra + background

if pixel_offset is not None:
self.measured_spectra = self.measured_spectra.shift(wavelength=round(pixel_offset), fill_value=np.nan)

self._build_bckc_dictionary()
return self.bckc

Expand Down
67 changes: 41 additions & 26 deletions indica/models/plasma.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,28 @@ def initialize_variables(self):
],
)

self.Pth = CachedCalculation(
self.calc_pth,
[
self.electron_density,
self.ion_density,
self.electron_temperature,
self.ion_temperature,
],
)

self.Ptot = CachedCalculation(
self.calc_ptot,
[
self.electron_density,
self.ion_density,
self.electron_temperature,
self.ion_temperature,
self.pressure_fast,
],
)


self.Lz_tot = CachedCalculation(
self.calc_lz_tot,
[
Expand Down Expand Up @@ -545,13 +567,7 @@ def pressure_el(self):

@property
def pressure_th(self):
ion_density = self.ion_density
self._pressure_th.values = self.pressure_el
for elem in self.elements:
self._pressure_th.values += ph.calc_pressure(
ion_density.sel(element=elem).values,
self.ion_temperature.sel(element=elem).values,
)
self._pressure_th = ph.calc_pressure(self.ion_density, self.ion_temperature).sum("element") + self.pressure_el
return self._pressure_th

@property
Expand All @@ -569,6 +585,9 @@ def pressure_fast(self):

@property
def pth(self):
return self.Pth()

def calc_pth(self):
pressure_th = self.pressure_th
for t in np.array(self.time_to_calculate, ndmin=1):
self._pth.loc[dict(t=t)] = np.trapz(
Expand All @@ -578,6 +597,9 @@ def pth(self):

@property
def ptot(self):
return self.Ptot()

def calc_ptot(self):
pressure_tot = self.pressure_tot
for t in np.array(self.time_to_calculate, ndmin=1):
self._ptot.loc[dict(t=t)] = np.trapz(
Expand All @@ -599,7 +621,8 @@ def wp(self):

@property
def fz(self):
return self.calc_fz() # self.Fz()
return self.Fz()
# return self.calc_fz() # self.Fz()

def calc_fz(self):
for elem in self.elements:
Expand All @@ -622,37 +645,29 @@ def calc_fz(self):

@property
def zeff(self):
return self.calc_zeff() # Zeff()
return self.Zeff()
# return self.calc_zeff()

def calc_zeff(self):
electron_density = self.electron_density
ion_density = self.ion_density
meanz = self.meanz
for elem in self.elements:
self._zeff.loc[dict(element=elem)] = (
(ion_density.sel(element=elem) * meanz.sel(element=elem) ** 2)
/ electron_density
).values
self._zeff = (self.ion_density * self.meanz) ** 2 / self.electron_density
return self._zeff

@property
def ion_density(self):
return self.calc_ion_density() # self.Ion_density()
return self.Ion_density()
# return self.calc_ion_density()

def calc_ion_density(self):
meanz = self.meanz
main_ion_density = self.electron_density - self.fast_density * meanz.sel(
element=self.main_ion
)
for elem in self.impurities:
self._ion_density.loc[dict(element=elem)] = self.impurity_density.sel(
element=elem
).values
main_ion_density -= self.impurity_density.sel(element=elem) * meanz.sel(
element=elem
)

self._ion_density.loc[dict(element=self.main_ion)] = main_ion_density.values
main_ion_density = self.electron_density - self.fast_density * meanz.sel(element=self.main_ion) \
- (self.impurity_density * meanz).sum("element")

self._ion_density.loc[dict(element=self.main_ion)] = main_ion_density
return self._ion_density

@property
Expand Down Expand Up @@ -753,6 +768,7 @@ def calc_sxr_radiation(self):
@property
def meanz(self):
fz = self.fz

for elem in self.elements:
self._meanz.loc[dict(element=elem)] = (
(fz[elem] * fz[elem].ion_charges).sum("ion_charges").values
Expand Down Expand Up @@ -1234,7 +1250,6 @@ def __init__(self, operator: Callable, dependencies: list, verbose: bool = False

@lru_cache()
def __call__(self):
print("Recalculating")
if self.verbose:
print("Recalculating")
return self.operator()
Expand Down
31 changes: 17 additions & 14 deletions indica/models/thomson_scattering.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def _build_bckc_dictionary(self):
self.bckc[quantity] = self.Te_at_channels
long_name = "Te"
units = "eV"
elif quant == "chi2":
# Placeholder
continue
else:
print(f"{quant} not available in model for {self.instrument_method}")
continue
Expand Down Expand Up @@ -82,7 +85,7 @@ def __call__(
"""
if self.plasma is not None:
if t is None:
t = self.plasma.t
t = self.plasma.time_to_calculate
Ne = self.plasma.electron_density.interp(t=t)
Te = self.plasma.electron_temperature.interp(t=t)
else:
Expand Down Expand Up @@ -111,6 +114,18 @@ def __call__(

return self.bckc

def ts_transform_example(nchannels):
x_positions = np.linspace(0.2, 0.8, nchannels)
y_positions = np.linspace(0.0, 0.0, nchannels)
z_positions = np.linspace(0.0, 0.0, nchannels)
transform = TransectCoordinates(
x_positions,
y_positions,
z_positions,
"ts",
machine_dimensions=((0.15, 0.95), (-0.7, 0.7)),
)
return transform

def example_run(
pulse: int = None,
Expand All @@ -124,19 +139,7 @@ def example_run(
if plasma is None:
plasma = example_plasma(pulse=pulse)

# Create new interferometers diagnostics
nchannels = 11
x_positions = np.linspace(0.2, 0.8, nchannels)
y_positions = np.linspace(0.0, 0.0, nchannels)
z_positions = np.linspace(0.0, 0.0, nchannels)

transect_transform = TransectCoordinates(
x_positions,
y_positions,
z_positions,
diagnostic_name,
machine_dimensions=plasma.machine_dimensions,
)
transect_transform = ts_transform_example(11)
transect_transform.set_equilibrium(plasma.equilibrium)
model = ThomsonScattering(
diagnostic_name,
Expand Down
4 changes: 4 additions & 0 deletions indica/profiles_gauss.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
self.xend = xend
self.coord = f"rho_{coord}"
self.x = np.linspace(0, 1, 15) ** 0.7
# self.x = 1-np.logspace(0, -2, 30)
self.datatype = datatype
if xspl is None:
xspl = np.linspace(0, 1.0, 30)
Expand All @@ -55,6 +56,9 @@ def __init__(

if parameters is None:
parameters = get_defaults(datatype)
elif {"y0", "y1", "yend", "wcenter", "wped", "peaking",} >= set(parameters):
_parameters = get_defaults(datatype)
parameters = dict(_parameters, **parameters)

for k, p in parameters.items():
setattr(self, k, p)
Expand Down
4 changes: 2 additions & 2 deletions indica/readers/read_st40.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def get_raw_data(self, uid: str, instrument: str, revision: RevisionLike = 0):
continue

transform = data[quant].transform
if hasattr(transform, "set_equilibrium"):
transform.set_equilibrium(self.equilibrium)
# if hasattr(transform, "set_equilibrium"):
# transform.set_equilibrium(self.equilibrium)
self.transforms[instrument] = transform
self.raw_data[instrument] = data

Expand Down
Loading
Loading