Skip to content

Latest commit

 

History

History
67 lines (44 loc) · 4.09 KB

development.md

File metadata and controls

67 lines (44 loc) · 4.09 KB

Development Guide

This is a living document and will be updated as needed.

PUNCH creates its science processing code primarily in Python. We recommend following Python best practices. These can be found in various documents; a good starting point is the SunPy Developer's Guide.

General tips

  • Follow PEP8 when appropriate and always use a linter for style.
  • There are many options for linters, but we recommend ruff. This should be installed as part of a pre-commit step. Your package maintainer should set pre-commit up.
  • Write tests first. Then, write code to pass the tests. Finally, refactor code for clarity and style.
  • Documentation is critical. Do not put it off. Code without documentation is unusable by the community and by future you when you forget how it works.
  • Class names should be nouns
  • Function names should be verbs
  • Variable names should be descriptive but still concise. No variables named by just a few letters. So emission_measure instead of em or emission_measure_cube_for_reprocessing.
  • Avoid loops by leveraging numpy.
  • Functions have clearly defined and restricted purposes. A function does one thing instead of many. For example, a function should generally not do calculations and handle I/O.
  • Don't reinvent the wheel; use existing tools in astropy, sunpy, and the Python ecosystem.

Using virtual environments

It is advised to develop and test in virtual environments. A virtual environment is a non-global Python environment that is dedicated to a specific project. By developing in a virtual environment as opposed to a global environment, you can avoid package dependency conflicts being a source of your errors. You can also experiment with updating to newer versions of packages and see if they are compatible with your code.

To create and activate a virtual environment run:

python -m venv my_venv_name
source my_venv_name/bin/activate

When you're finished working in this virtual environment, run deactivate.

Note that most Python IDEs will manage virtual environments for you, preventing you from having to manually execute these commands.

Testing code

We expect nearly all lines of code to have an associated test. Comprehensive testing allows peace of mind when developing new features or modifying existing ones. You are alerted by a failed test if something you did breaks the code. We recommend using pytest as your testing framework. Read more about testing here.

Documentation

Code without documentation can be as useless as code that doesn't exist and even more frustrating. It is critical to document all code. When you write a function, include a docstring in the numpydoc format.

In addition to documenting directly in code, we recommend developing documentation websites with introductory material and examples as a Sphinx website.

GitHub practices

We use GitHub to manage our development. This involves sharing code, continuous integration, issue tracking, and more.

Creating an issue

When you create a GitHub issue be as specific as possible. More specificity enables a more productive development cycle fixing the issue.

If you're a package maintainer, it is recommended to set up issue templates to encourage this kind of specificity.

NDCube

"ndcube is a SunPy Project affiliated package designed for handling N-dimensional data cubes described by WCS (World Coordinate System) transformations." NDCubes couple together the data, WCS, uncertainty, and metadata. For PUNCH, we have implemented our own metadata class called NormalizedMetadata. Learn more about this in the punchbowl documentation.