Skip to content

Commit

Permalink
Add MANIFEST.in and clean /JTM
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmbeta committed Jul 7, 2022
1 parent ae84bc4 commit bfbd1f5
Show file tree
Hide file tree
Showing 41 changed files with 14,601 additions and 4,983 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,7 @@ dmypy.json
# Folders to ignore
matlab/
lit/
data/
asano/
img/

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graft pysilsub
19 changes: 0 additions & 19 deletions README.rst

This file was deleted.

90 changes: 50 additions & 40 deletions bin/StimulationDevice_STLAB_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

# StimulationDevice class demonstration
# =====================================
#
#
# Assumptions:
# - This is intended to function as a generic device class for multiprimary stimulators.
# - This is intended to function as a generic device class for multiprimary stimulators.
# - devices are additive
# - calibration is stationary
# - expect values as W/m2/nm
Expand All @@ -14,7 +14,8 @@


import sys
sys.path.insert(0, '../')

sys.path.insert(0, "../")
import random

import matplotlib.pyplot as plt
Expand All @@ -25,8 +26,8 @@
from silentsub.CIE import get_CIES026
from silentsub import colorfunc

sns.set_context('notebook')
sns.set_style('whitegrid')
sns.set_context("notebook")
sns.set_style("whitegrid")


# Load data with pandas -- this is our starting point
Expand All @@ -35,10 +36,12 @@
# In[2]:


spds = pd.read_csv('../data/S2_corrected_oo_spectra.csv', index_col=['led','intensity'])
spds.index.rename(['Primary', 'Setting'], inplace=True)
spds = pd.read_csv(
"../data/S2_corrected_oo_spectra.csv", index_col=["led", "intensity"]
)
spds.index.rename(["Primary", "Setting"], inplace=True)
spds.columns = pd.Int64Index(spds.columns.astype(int))
spds.columns.name = 'Wavelength'
spds.columns.name = "Wavelength"
spds = spds.sort_index()
spds

Expand All @@ -50,15 +53,22 @@


# list of colors for the primaries
colors = ['blueviolet', 'royalblue', 'darkblue', 'blue', 'cyan',
'green', 'lime', 'orange', 'red', 'darkred']
colors = [
"blueviolet",
"royalblue",
"darkblue",
"blue",
"cyan",
"green",
"lime",
"orange",
"red",
"darkred",
]

# instantiate the class
device = StimulationDevice(
resolutions=[4095]*10,
colors=colors,
spds=spds,
spd_binwidth=1
resolutions=[4095] * 10, colors=colors, spds=spds, spd_binwidth=1
)


Expand Down Expand Up @@ -87,11 +97,9 @@


primary_spd = device.predict_primary_spd(
primary=7,
setting=.5,
name='Primary 7 (half power)'
primary=7, setting=0.5, name="Primary 7 (half power)"
)
primary_spd.plot(legend=True, ylabel='W/m$^2$/nm', color=device.colors[7]);
primary_spd.plot(legend=True, ylabel="W/m$^2$/nm", color=device.colors[7])


# Predict output for random device settings
Expand All @@ -100,19 +108,21 @@
# In[7]:


settings = [random.randrange(s) for s in device.resolutions] # Using a list of integers
device_spd = device.predict_multiprimary_spd(settings, 'Random SPD')
device_spd.plot(legend=True, ylabel='W/m$^2$/nm');
print(f'Predicted output for device settings: {settings}')
settings = [
random.randrange(s) for s in device.resolutions
] # Using a list of integers
device_spd = device.predict_multiprimary_spd(settings, "Random SPD")
device_spd.plot(legend=True, ylabel="W/m$^2$/nm")
print(f"Predicted output for device settings: {settings}")


# In[8]:


weights = device.settings_to_weights(settings) # Convert settings to float
device_spd = device.predict_multiprimary_spd(weights, 'Random SPD')
device_spd.plot(legend=True, ylabel='W/m$^2$/nm');
print(f'Predicted output for device settings: {weights}')
weights = device.settings_to_weights(settings) # Convert settings to float
device_spd = device.predict_multiprimary_spd(weights, "Random SPD")
device_spd.plot(legend=True, ylabel="W/m$^2$/nm")
print(f"Predicted output for device settings: {weights}")


# Predict *a*-opic irradiances for a list of device settings and plot with nice colours
Expand All @@ -123,7 +133,7 @@

device_ao = device.predict_multiprimary_aopic(settings)
ao_colors = list(device.aopic_colors.values())
device_ao.plot(kind='bar', color=ao_colors, ylabel='W/m$^2$');
device_ao.plot(kind="bar", color=ao_colors, ylabel="W/m$^2$")


# Convert settings to weights and weights to settings
Expand All @@ -147,34 +157,34 @@
# In[12]:


xy = [.3127, .3290] # D65
luminance = 600. # Lux
xy = [0.3127, 0.3290] # D65
luminance = 600.0 # Lux
res = device.find_settings_xyY(
xy=xy,
xy=xy,
luminance=luminance,
tollerance=1e-6,
plot_solution=True,
verbose=True
verbose=True,
)


# In[13]:
import numpy as np

bg = device.predict_multiprimary_spd(
[.2 for val in range(10)],
'background',
nosum=True)
[0.2 for val in range(10)], "background", nosum=True
)

sss = get_CIES026()
mat = bg.T.dot(sss)
pinv_mat = np.linalg.pinv(mat)
mod = np.dot(pinv_mat.T, np.array([0, 0, 0, 0, 0]))
device.predict_multiprimary_spd([.5 for val in range(10)] + mod, 'mod').plot(legend=True);
device.predict_multiprimary_spd([.5 for val in range(10)], 'notmod').plot(legend=True);
device.predict_multiprimary_spd([0.5 for val in range(10)] + mod, "mod").plot(
legend=True
)
device.predict_multiprimary_spd([0.5 for val in range(10)], "notmod").plot(
legend=True
)


# In[ ]:




50 changes: 27 additions & 23 deletions bin/config_BCGAR_8_bit_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@

# Configure device
RESOLUTIONS = [255] * 5
COLORS = ['blue', 'cyan', 'green', 'orange', 'red']
CALIBRATION_FPATH= '/Users/jtm545/Projects/PySilSub/data/BCGAR_5_Primary_8_bit_linear.csv'
CALIBRATION_UNITS = 'W/m$^2$/nm'
NAME = 'BCGAR (8-bit, linear)'
JSON_NAME = 'BCGAR'
COLORS = ["blue", "cyan", "green", "orange", "red"]
CALIBRATION_FPATH = (
"/Users/jtm545/Projects/PySilSub/data/BCGAR_5_Primary_8_bit_linear.csv"
)
CALIBRATION_UNITS = "W/m$^2$/nm"
NAME = "BCGAR (8-bit, linear)"
JSON_NAME = "BCGAR"
WAVELENGTHS = [380, 781, 1]
NOTES = ('An artificial 8-bit linear calibration based on the maximum output '
+ 'of 5 STLAB channels.')
NOTES = (
"An artificial 8-bit linear calibration based on the maximum output "
+ "of 5 STLAB channels."
)


def device_config():

config = {
'calibration_fpath': CALIBRATION_FPATH,
'calibration_units': CALIBRATION_UNITS,
'name': NAME,
'json_name': JSON_NAME,
'wavelengths': WAVELENGTHS,
'colors': COLORS,
'resolutions': RESOLUTIONS,
'notes': NOTES
}
json.dump(config, open(f'../data/{JSON_NAME}.json', 'w'))

if __name__ == '__main__':
device_config()
"calibration_fpath": CALIBRATION_FPATH,
"calibration_units": CALIBRATION_UNITS,
"name": NAME,
"json_name": JSON_NAME,
"wavelengths": WAVELENGTHS,
"colors": COLORS,
"resolutions": RESOLUTIONS,
"notes": NOTES,
}

json.dump(config, open(f"../data/{JSON_NAME}.json", "w"))


if __name__ == "__main__":
device_config()
56 changes: 34 additions & 22 deletions bin/config_OneLight.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@

# Configure device
RESOLUTIONS = [256] * 56
COLORS = list(sns.color_palette('Spectral', n_colors=56))[::-1]
COLORS = list(sns.color_palette("Spectral", n_colors=56))[::-1]
# Absolute file path to permenant location of calibration file
CALIBRATION_FPATH = '/Users/jtm545/Projects/PySilSub/data/oneLight_artifical.csv'
CALIBRATION_UNITS = 'W/$m^2$/s/nm'
NAME = 'OneLight'
JSON_NAME = 'OneLight'
CALIBRATION_FPATH = (
"/Users/jtm545/Projects/PySilSub/data/oneLight_artifical.csv"
)
CALIBRATION_UNITS = "W/$m^2$/s/nm"
NAME = "OneLight"
JSON_NAME = "OneLight"
WAVELENGTHS = [380, 781, 2]
NOTES = ('Device used in Spitschan et al. papers. Highly linear with 52 '
+ 'primaries. Perfectly linear in this dataset.')
NOTES = (
"OneLight VISX Spectra, digital light synthesis engine used in Spitschan "
+ "et al. papers. Highly linear with 52 narrow-band (16 nm FWHM) "
+ "primaries and the capacity to modulate between spectra at 256 Hz. "
+ "Reinvented from original measurements here as a perfectly linear "
+ "device with 8-bit channel resolution. For further details, see "
+ "Spitschan, M., Aguirre, G. K., & Brainard, D. H. (2015). Selective "
+ "stimulation of penumbral cones reveals perception in the shadow of "
+ "retinal blood vessels. PLoS ONE, 10(4), 1–22. "
+ "https://doi.org/10.1371/journal.pone.0124328"
)



def device_config():
Expand All @@ -36,20 +48,20 @@ def device_config():
None.
"""

config = {
'calibration_fpath': CALIBRATION_FPATH,
'calibration_units':CALIBRATION_UNITS,
'name': NAME,
'json_name': JSON_NAME,
'wavelengths': WAVELENGTHS,
'colors': COLORS,
'resolutions': RESOLUTIONS,
'notes': NOTES
}
json.dump(config, open(f'../data/{JSON_NAME}.json', 'w'))
"calibration_fpath": CALIBRATION_FPATH,
"calibration_units": CALIBRATION_UNITS,
"name": NAME,
"json_name": JSON_NAME,
"wavelengths": WAVELENGTHS,
"colors": COLORS,
"resolutions": RESOLUTIONS,
"notes": NOTES,
}

json.dump(config, open(f"../data/{JSON_NAME}.json", "w"))


if __name__ == '__main__':
device_config()
if __name__ == "__main__":
device_config()
Loading

0 comments on commit bfbd1f5

Please sign in to comment.