How to unset default 'compress' option during save

core

(Murat Maga) #13

Thank you. Based on the example, this works:

#set the default 3D model format to PLY (instead of VTK)
defaultModelStorageNode = slicer.vtkMRMLModelStorageNode()
defaultModelStorageNode.SetDefaultWriteFileExtension(‘ply’)
#to turn off compression for the models
defaultModelStorageNode.SetUseCompression(0)
slicer.mrmlScene.AddDefaultNode(defaultModelStorageNode)

But I couldn’t figure out how to use the provided Change file type for saving for all volumes (with already existing storage nodes) example to work with fresh scenes with no volume loaded.

defaultVolumeNode = slicer.vtkMRMLScalarVolumeNode()
defaultVolumeNode.SetDefaultWriteFileExtension(‘mha’)

fails with AttributeError: ‘vtkCommonCorePython.vtkMRMLScalarVolumeNode’ object has no attribute ‘SetDefaultWriteFileExtension’


(Andras Lasso) #14

You need to change the default volume storage node (not the default volume node).


(Murat Maga) #15

Thanks, but looks like I need more guidance…

defaultStorageNode = slicer.vtkMRMLStorageNode()

fails with TypeError: this is an abstract class and cannot be instantiated

and I can’t locate a vtkMRMLVolumeStorageNode() (or rather how/where to find it).


(Steve Pieper) #16

Here’s an example:

#set the default volume storage to not compress by default
defaultVolumeStorageNode = slicer.vtkMRMLSegmentationStorageNode()
defaultVolumeStorageNode.SetUseCompression(0)
slicer.mrmlScene.AddDefaultNode(defaultVolumeStorageNode)
logging.info("Segmentation nodes will be stored uncompressed 

This is also in theScript Repository now.


(Isaiah Norton) #17

This came up in another thread recently:

We could potentially get a big performance boost at minimal file size cost by changing the default gz compression level to 1. In some small-scale tests I did a few months ago, there was a major time cost between high and low settings, for only a tiny compression improvement (e.g. 90-> 26 MB at level 9 in 34s, vs 90->27 MB at level 1 in <1s). This was only a small test on a few brain MR datasets, but it seems reasonable.


(Andras Lasso) #18

Using a low compression level would make a lot of sense, as one of the main reasons I would keep compression enabled is to deflate blank voxels around images that have a non-rectangular shape.

Is there an API to change compression level in ITK IO classes?


Slicer 4.10.1: Summary, Highlights and Changelog
(Isaiah Norton) #19

Looks like only for a few specific formats (MINC, PNG). For NRRD we can set it in teem directly.


(Steve Pieper) #20

@muratmaga tomorrow’s nightly build will have this commit which changes the default nrrd compression to ‘low’ so it should be faster and still pretty good compression. Let us know how it works in your use cases.


(Murat Maga) #21

downloading right now!


(Murat Maga) #22

So, I don’t need to do anything to enable this right? I am seeing about 10% gain over the behavior in 4.8.1 for a dataset about 1.8GB. (took 40 seconds on 4.8.1 to save, 36 second wtth todays nightly). Perhaps gains are more for larger dataset. I will try with a larger one.

Also, there is problem with file renaming at the save dialog box. Whatever I type, it reverts to the original file name when I click save.


(Steve Pieper) #23

Thanks for testing @muratmaga - what’s the original size of the data and maybe @ihnorton can comment if that’s in line with his expectations.

Regarding the save dialog it works for me here on my local build (mac). I can change the name of the file in the save dialog and the file is saved under that name. But the node name is slicer is unchanged. If I change the name in slicer then the suggested file name is updated next time I go into the save dialog.


(Murat Maga) #24

This is what I see when I hit save:

I click the checkbox and type and alternate name (I don’t want to overwrite).

The moment I click save, this appears, and note that name has reverted

In fact name gets reverted to the original the moment I unfocus from the text field.


(Steve Pieper) #25

Ah - I think I see - here you are changing the extension to ‘.save’ and so it changes back. What if you change it to ‘testing.nrrd’ ?


(Murat Maga) #26

Yep, it doesn’t do if I don’t use a ‘.’ to separate words.
But 4.8.1 happily accepted multiple '.'s in a file name, and appended its proper extension.
Is this change intentional?


(Steve Pieper) #27

I don’t think it’s intentional, but it may have be related to the use of compound names like file.seg.nrrd for segmentations. @lassoan any comments?

But I find it I type something like testing.save.nrrd it works as expected so if there’s a reason it needs to be like this the workaround doesn’t seem too bad (granted it’s another thing to learn so it’s not ideal).


(James Butler) #28

Another user recently had problems (see Save scene with written name) regarding the file name being reverted without their knowledge. The name isn’t reverted until the file name field is no longer being actively edited. It can be confusing when going from actively editing to pressing the save button. If the file doesn’t already exist, it will use the reverted name which the user won’t know and the dialog immediately closes. At least here @muratmaga was able to notice that it wasn’t using the file name “testing.save” because an “already exists” warning appeared for the reverted file name.


(Murat Maga) #29

I agree this can potentially frustrate a lot of new people. The change is too quick to notice if you hit save directly, and it there is no older version it will get written with a different file name than you intended.


(Andras Lasso) #30

Name of the column is “file name” because it actually contains the file name, including extension. You cannot enter a filename with an invalid extension, such as volume.abc or volume.nrrd.abc. I understand that you would expect to edit the file base name there. Maybe adding a “show extension” checkbox would help (that would switch between showing the file base name and complete file name)?

I don’t like the current behavior of resetting file name based on node name. Unfortunately, if we don’t do it then it may lead to other problems: you may not be able to find your data easily, may mix up data sets because you only renamed the node in the scene but not the filename. I don’t know if there is an easy solution to this.


(Murat Maga) #31

The use case is someone importing a new stack, and then saving it as an nrrd, where they may want to rename the imported dataset as more appropriate for their workflow. If you are not going to let them do this at the save time, then I think actually it will be better to make the save as filename box not editable at all, and force them to make the change at the node level using data or subject hierarchy. As it is, it is confusing…


(Andras Lasso) #32

You may be right. Currently, Save dialog in Slicer serves two purposes: Save and Export. It could help if these two functions would be more clearly separated (allow saving with a single click, without asking anything; use the current Save dialog for export only).