Skip to content

Commit

Permalink
added docstring convention to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
emiddell committed Mar 12, 2024
1 parent 82d19f9 commit faa9493
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions docs/getting_started/contributing_code/contributing_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ Some relevant conventions in a nutshell:
- **Variable Naming Rule: Variable names follow the same convention as function names. Example: `my_variable = 1`. Avoid `MyVariable` and `myVariable`
- **Constants Naming Rule*: Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples: `include MAX_OVERFLOW`

### Style Guide for docstrings

Please use [documentation strings](https://docs.python.org/3/tutorial/controlflow.html#documentation-strings) to document modules, classes and functions. There exist several different conventions on how to
format these docstrings. We will follow the Google style as described in the
[Google Python Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings).


Please add references to the literature if you are implementing a published algorithm.

**Example:**
```
def func(arg1 : int, arg2 : str) -> bool:
"""One sentence description of function.
Some more details on what the function does.
Reference to related work or source material [1]
[1] Authors et al., Title, Journal, Year
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Description of return value
"""
return True
```

### Where to add my code?

When contributing code to Cedalion (=package), try to incorporate it into the existing file and folder structure, which also defines cedalions package and subpackages. Python files (=modules) contain functions of the same category; folders (subpackages) contain python files of the same family. Examples:
Expand Down Expand Up @@ -259,36 +289,5 @@ def prune(data: cdt.NDTimeSeries, geo3D: Quantity, snr_thresh: Quantity,
return data, drop_list
```

## Concluding Remarks and Documentation
## Concluding Remarks
The example above uses Cedalion's most basic data structures. While the toolbox continues to grow, we will add containers and abstraction layers to simplify and unify usage and code contribution. Whenever possible and especially when you find that the existing environment does not (yet) provide a level of abstraction or a data structure bundling all the data that you need in one container, please develop **bottom up** and write simple functions with (multiple) simple input and output arguments. In the example, once a general container is specified that ties together timeseries data, optode information (such as the `geo3D`) or measurement lists, it is straightforward to refactor the code accordingly. The same is true for more complex processing pipelines tied together in jupyter notebooks. We are working on a mechanism to build pipelines that enables easier and more abstract use by incorporating the lower level functions. Translating a notebook to such a pipeline is then straightforward.

### Code Documentation
Please document your code well by commenting relevant steps throughout. At the beginning of each function, please add relevant information according to the following template (for examples see the functions in the previous section). This will make the documentation also available in our Read the Docs page that allows users to browse available functions and their usage.

```
def your_function(Arg1, Arg2):
"""One sentence description of function.
Some more details on what the function does.
Reference to related work or source material [1]
[1] Authors et al., Title, Journal, Year
INPUTS:
Arg1: Input type and units, explanation.
Arg2: Input type and units, explanation.
OUTPUTS:
Out1:: Output type and units, explanation.
DEFAULT PARAMETERS:
Arg1: Suggested default value for Arg1
Arg2: uggested default value for Arg1
"""
Out1 = true
print(f"i am an example function that returns a boolean {Out1}")
return Out1
```

0 comments on commit faa9493

Please sign in to comment.