Skip to content

Conversation

@CameronTEllis
Copy link
Contributor

Updated simulator extensively

This estimates what noise properties the volume has. The absolute size of
the autoregression, drift and system noise is not critical but rather
the relative amounts (because all temporal noise is z scored in the
average and multiplied by the 'overall' parameter).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the overall parameter? Where is it (it is not a parameter of this function)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a parameter used in generate_noise to control the overall noise level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this in the docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay updated

CameronTEllis added 2 commits December 13, 2016 13:15
No need to make any change to hyperparamopt
from itertools import product
import nibabel
from scipy import stats
import nitime.algorithms.autoregressive as ar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must add Nitime to the list of dependencies in setup.py.

def export_stimfunction(stimfunction,
filename,
):
""" Output a three column text file (onset time, event duration and weight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a tab-separated values file? If so, please change the docstring to say so.

# nifti into a numpy array
if isinstance(volume, str):
nifti = nibabel.load(volume) # Load the file
volume = nifti.get_data() # Pull out the data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only usage of Nibabel in your code (except for the example). Could you please remove it so we do not introduce a dependency on Nibabel? If so, please change the docstring and dependencies in setup.py accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was told that Nibabel is the method we will be using for loading (and in this case writing it is well) in niftis. If there is an alternative, I am happy to use it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed. However, so far we have only been using it in examples, not in BrainIAK code. I would prefer to not add it as a BrainIAK dependency yet, if it is not really necessary. The way I see it, here it is not necessary, because you can load the file outside BrainIAK, like you do now in the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay fair enough, I have removed it

setup.py Outdated
'numpy',
'scikit-learn>=0.18',
'scipy',
'statsmodels',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used. Please remove.

assert np.sum(stimfunction) == np.sum(event_durations * len(onsets)) / \
tr_duration, "Event number"
assert np.sum(stimfunction) == np.sum(event_durations * len(onsets)) * \
1000, "Event number"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mihaic
Copy link
Member

mihaic commented Dec 13, 2016

The testing error is because of a bug in Nitime:
nipy/nitime#141

Let's wait a couple of days for the Nitime maintainer to make a release including the bug fix before deciding how to proceed.

@mihaic
Copy link
Member

mihaic commented Dec 16, 2016

Jenkins, retest this please.

@mihaic
Copy link
Member

mihaic commented Dec 16, 2016

There is a new Nitime release which solves the installation problem.

@CameronTEllis, the failure is caused by low coverage now. Run pr-check.sh yourself followed by coverage report to see. (I will fix run-tests.sh to show the low coverage by itself.)

@CameronTEllis
Copy link
Contributor Author

CameronTEllis commented Dec 16, 2016 via email

timing_file : string
The filename (with path) to a three column timing file (FSL) to
make the events. Still requires tr_duration and total_time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr_duration is not a parameter of this function.

total_time,
tr_duration,
weights=[1],
timing_file=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a paragraph to the docstring (before the parameters) explaining there are two ways to call the function: either with a timing file, or with onsets.


# Pull out the weight, set as a float
weights[event_counter] = float(line[0:line.find('\t')])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, but not Pythonic. Consider something like this:

for line in f:
    onset, duration, weight = line.strip().split()
    onsets.append(float(onset))
    durations.append(float(duration))
    weights.append(float(weight))

stimfunction = [0] * round(total_time * temporal_resolution)

# Cycle through the onsets
for onset_counter in list(range(0, len(onsets))):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for list and 0.

Apply the convolution of the HRF and stimulus time course to the
volume.
volume. This requires discriti
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"discriti"?

What is the path to the mask to be loaded? If set to self then it
makes a mask from the volume supplied (by averaging across time
points and changing the range). If empty then it defaults to an
MNI152 grey matter mask.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives a special meaning to the path "self". It would be better to introduce an extra boolean parameter, perhaps called self_mask.

# tmp = str(noise_dict['physiological_sigma'] ** 2 / total_var * 100)[0:5]
# print('Physiological noise:\t' + tmp)
# tmp = str(noise_dict['system_sigma'] ** 2 / total_var * 100)[0:5]
# print('System noise:\t\t\t' + tmp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove or turn into debug log messages.

stimfunction,
tr_duration,
mask=None,
noise_dict={'overall': 0.1},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is only evaluated once and shared between all calls:
https://docs.python.org/3/tutorial/controlflow.html#default-argument-values
You should set None as the default value and make the assignment in the function body.

)

noise_system = _generate_noise_system(dimensions_tr=dimensions_tr,
) * noise_dict['system_sigma']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style is appropriate for code that is expected to change. Do you expect to keep adding parameters to the _generate_noise_system call? Otherwise, consider this for readability:

noise_system = _generate_noise_system(dimensions_tr=dimensions_tr)
               * noise_dict['system_sigma']

setup.py Outdated
install_requires=[
'cython',
'mpi4py',
'nibabel',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used in BrainIAK. Move it to examples/utils/requirements.txt.

@mihaic
Copy link
Member

mihaic commented Jan 9, 2017

@CameronTEllis, please speak up if you need help with the testing errors.

@CameronTEllis
Copy link
Contributor Author

CameronTEllis commented Jan 11, 2017 via email

@mihaic
Copy link
Member

mihaic commented Jan 11, 2017

Click on the "Details" link next to the failed Travis build. Then click on any of the failed jobs to see the logs. Here is an the relevant part from at the end of one of the logs:

flake8 --config setup.cfg brainiak
brainiak/utils/fmrisim.py:721:62: E128 continuation line under-indented for visual indent
brainiak/utils/fmrisim.py:727:62: E128 continuation line under-indented for visual indent
brainiak/utils/fmrisim.py:733:62: E128 continuation line under-indented for visual indent
brainiak/utils/fmrisim.py:1320:80: E501 line too long (82 > 79 characters)
brainiak/utils/fmrisim.py:1507:20: E127 continuation line over-indented for visual indent
run-checks failed
The command "./pr-check.sh" exited with 1.
Done. Your build exited with 1.

If you run pr-check.sh on you own computer, you will get the same results.

@mihaic
Copy link
Member

mihaic commented Jan 12, 2017

brainiak/utils/fmrisim.py:1506:20: E127 continuation line over-indented for visual indent
Try this:

    noise_system = (_generate_noise_system(dimensions_tr=dimensions_tr)
                    * noise_dict['system_sigma'])

Also, please merge the latest changes from master. You can also do it on github.com using the "Update branch" button after you push all your changes.

@mihaic
Copy link
Member

mihaic commented Jan 19, 2017

Jenkins, retest this please.

@mihaic
Copy link
Member

mihaic commented Jan 19, 2017

@CameronTEllis, there were other errors unrelated to your code that were fixed. Please merge the latest commits from master (you can press "Update branch" in the PR on github.com and then pull the changes to your local repository).

However, there is also a problem with your code, which you can see when running the tests:

=================================== FAILURES ===================================
_______________________________ test_calc_noise ________________________________

    def test_calc_noise():
    
        # Inputs for functions
        onsets = [10, 30, 50, 70, 90]
        event_durations = [6]
        tr_duration = 2
        duration = 100
        dimensions_tr = np.array([10, 10, 10, duration/tr_duration])
    
        # Preset the noise dict
        nd_orig = {'auto_reg_sigma': 1,
                   'drift_sigma': 0.5,
                   'overall': 0.1,
                   'snr': 30,
                   'spatial_sigma': 0.15,
                   'system_sigma': 1,
                   }
    
        # Create the time course for the signal to be generated
        stimfunction = sim.generate_stimfunction(onsets=onsets,
                                                 event_durations=event_durations,
                                                 total_time=duration,
                                                 )
    
        # Mask the volume to be the same shape as a brain
>       mask = sim.mask_brain(dimensions_tr)

tests/utils/test_fmrisim.py:286: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
brainiak/utils/fmrisim.py:1338: in mask_brain
    volume = np.ones(volume)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

shape = array([ 10.,  10.,  10.,  50.]), dtype = None, order = 'C'

    def ones(shape, dtype=None, order='C'):
        """
        Return a new array of given shape and type, filled with ones.
    
        Parameters
        ----------
        shape : int or sequence of ints
            Shape of the new array, e.g., ``(2, 3)`` or ``2``.
        dtype : data-type, optional
            The desired data-type for the array, e.g., `numpy.int8`.  Default is
            `numpy.float64`.
        order : {'C', 'F'}, optional
            Whether to store multidimensional data in C- or Fortran-contiguous
            (row- or column-wise) order in memory.
    
        Returns
        -------
        out : ndarray
            Array of ones with the given shape, dtype, and order.
    
        See Also
        --------
        zeros, ones_like
    
        Examples
        --------
        >>> np.ones(5)
        array([ 1.,  1.,  1.,  1.,  1.])
    
        >>> np.ones((5,), dtype=np.int)
        array([1, 1, 1, 1, 1])
    
        >>> np.ones((2, 1))
        array([[ 1.],
               [ 1.]])
    
        >>> s = (2,2)
        >>> np.ones(s)
        array([[ 1.,  1.],
               [ 1.,  1.]])
    
        """
>       a = empty(shape, dtype, order)
E       TypeError: 'numpy.float64' object cannot be interpreted as an integer

../../.local/lib/python3.5/site-packages/numpy/core/numeric.py:192: TypeError
====================== 1 failed, 5 passed in 2.51 seconds ======================

Specifically, dimensions_tr = np.array([10, 10, 10, duration/tr_duration]) can contain a non-integer in the last position, thereby causing the error. Please fix this.

@mihaic mihaic merged commit 1c37d96 into brainiak:master Jan 20, 2017
@mihaic
Copy link
Member

mihaic commented Jan 20, 2017

Thank you for the contribution, @CameronTEllis.

I suggest you start a new branch for master for your next contribution. You should delete this branch; you can press the "Delete branch" button at the end of the PR page on github.com (you still need to delete it from your local repository).

danielsuo pushed a commit that referenced this pull request Nov 16, 2017
danielsuo pushed a commit that referenced this pull request Nov 16, 2017
#150)

* Experimental utils for copying directories to other machines in the cluster using Ray.

* Test copying directory functionality.

* Small fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants