Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • fsl/pytreat-practicals-2020
  • mchiew/pytreat-practicals-2020
  • ndcn0236/pytreat-practicals-2020
  • nichols/pytreat-practicals-2020
4 results
Show changes
Showing
with 3055 additions and 556 deletions
The example_project library
Copyright 2016-2020 University of Oxford, Oxford, UK.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Example project
===============
This is an example project, used to demonstrate the basics of how to structure
a Python project.
#!/usr/bin/env python
__version__ = '0.1.0'
# make myfunction available
# at the package-level
from .mymodule import myfunction
#!/usr/bin/env python
def myfunction(a, b):
return a * b
numpy==1.*
#!/usr/bin/env python
from setuptools import setup
from setuptools import find_packages
# Import version number from
# the project package (see
# the section on versioning).
from mypackage import __version__
# Read in requirements from
# the requirements.txt file.
with open('requirements.txt', 'rt') as f:
requirements = [l.strip() for l in f.readlines()]
# Generate a list of all of the
# packages that are in your project.
packages = find_packages()
setup(
name='Example project',
description='Example Python project for PyTreat',
url='https://git.fmrib.ox.ac.uk/fsl/pytreat-practicals-2020/',
author='Paul McCarthy',
author_email='pauldmccarthy@gmail.com',
license='Apache License Version 2.0',
packages=packages,
version=__version__,
install_requires=requirements,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries :: Python Modules'],
)
......@@ -2,15 +2,17 @@ Advanced Python
===============
This directory contains a collection of practicals, each of which covers a
particular feature of the Python Programming language. They are intended for
particular feature of the Python programming language. They are intended for
people who are familiar with the basics of Python, and want to learn about
some of the more advanced features of the language.
Practicals on the following topics are available:
Practicals on the following topics are available. They can be viewed in any
order, but we recommend going through them in this order:
* Function inputs and outputs
* Modules and packages
* Object-oriented programming
* Operator overloading
* Decorators
* Context managers
1. Function inputs and outputs
2. Modules and packages
3. Object-oriented programming
4. Operator overloading
5. Context managers
6. Decorators
7. Threading and parallel processing
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
### Re-name subject files
Write a function which, given a subject directory, renames all of the image
files for this subject so that they are prefixed with `[group]_subj_[id]`,
where `[group]` is either `CON` or `PAT`, and `[id]` is the (zero-padded)
subject ID.
This function should accept the following parameters:
- The subject directory
- The subject group
**Bonus 1** Make your function work with both `.nii` and `.nii.gz` files.
**Bonus 2** If you completed [the previous exercise](#re-organise-a-data-set),
write a second function which accepts the data set directory as a sole
parameter, and then calls the first function for every subject.
### Compress all uncompressed images
Write a function which recursively scans a directory, and replaces all `.nii`
files with `.nii.gz` files, using the built-in
[`gzip`](https://docs.python.org/3.5/library/gzip.html) library to perform
the compression.
### Write your own `os.path.splitext`
Write an implementation of `os.path.splitext` which works with compressed or
uncompressed NIFTI images.
> Hint: you know what suffixes to expect!
### Write a function to return a specific image file
Assuming that you have completed the previous exercises, and re-organised
`raw_mri_data` so that it has the structure:
`raw_mri_data/[group]/subj_[id]/[group]_subj_[id]_[modality].nii.gz`
write a function which is given:
- the data set directory
- a group label
- integer ubject ID
- modality (`'t1'`, `'t2'`, `'task'`, `'rest'`)
and which returns the fully resolved path to the relevant image file.
> Hint: Python has [regular
expressions](https://docs.python.org/3.5/library/re.html) - you might want
to use one to cope with zero-padding.
**Bonus** Modify the function so the group label does not need to be passed in.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.