Merge pull request #254 from pkgw/cmap-serialization

Include image colormap selection in JSON serialization
This commit is contained in:
Peter Williams 2020-02-11 09:09:22 -05:00 коммит произвёл GitHub
Родитель e30be0289e bedf85cb66
Коммит 1b3e8bb226
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -1037,9 +1037,12 @@ class ImageLayer(HasTraits):
state['settings'][wwt_name] = trait.get(self)
if self.vmin is not None and self.vmax is not None:
state['stretch_info'] = {'vmin': self.vmin,
'vmax': self.vmax,
'stretch':VALID_STRETCHES.index(self.stretch)}
state['stretch_info'] = {
'vmin': self.vmin,
'vmax': self.vmax,
'stretch': VALID_STRETCHES.index(self.stretch),
'cmap': self.cmap.name,
}
return state

Просмотреть файл

@ -167,10 +167,11 @@ function loadImageLayer(layerInfo) {
var id = layerInfo['id'];
var url = 'data/' + id + '.fits';
var onFitsLoad = function (layer) {
var stertchInfo = layerInfo['stretch_info'];
wwtLayer.setImageScale(stertchInfo['stretch'],
stertchInfo['vmin'],
stertchInfo['vmax']);
var stretchInfo = layerInfo['stretch_info'];
wwtLayer.setImageScale(stretchInfo['stretch'],
stretchInfo['vmin'],
stretchInfo['vmax']);
wwtLayer.set_colorMapperName(stretchInfo['cmap']);
layer.getFitsImage().transparentBlack = false;
var settings = layerInfo['settings'];
for (name in settings) {
@ -284,4 +285,4 @@ function handleConfigLoadError() {
//TODO replace with something a bit nicer before releasing this feature
$("#wwt-canvas").hide;
$("#wwt-error-text").append("<p>Unable to load configuration file wwt_figure.json</p>");
}
}

Просмотреть файл

@ -382,6 +382,7 @@ def test_image_setting_serialization():
layer.opacity = 0.3
layer.vmin = -1
layer.vmax = 1
layer.cmap = 'plasma'
layer_state = widget.quick_serialize()['layers'][0]
assert layer_state['id'] == layer.id
@ -390,6 +391,7 @@ def test_image_setting_serialization():
assert layer_state['stretch_info']['vmin'] == -1
assert layer_state['stretch_info']['vmax'] == 1
assert layer_state['stretch_info']['stretch'] == 0
assert layer_state['stretch_info']['cmap'] == 'plasma'
assert 'settings' in layer_state
settings = layer_state['settings']