33Contributor Guide
44=================================
55
6- .. note ::
7-
8- This contributor guide is written for wrf-python v1.3.x. In the
9- not-too-distant future, wrf-python will undergo a significant refactoring
10- to remove the wrapt decorators (which don't serialize for dask), but the
11- concepts will remain similar to what is described in :ref: `internals `.
12-
13-
146Introduction
157-----------------------------
168
@@ -30,10 +22,6 @@ The source code is available on GitHub:
3022
3123 https://github.com/NCAR/wrf-python
3224
33- To checkout the code::
34-
35- git clone https://github.com/NCAR/wrf-python
36-
3725
3826Git Flow
3927^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,11 +54,14 @@ Users are encouraged to contribute various ways. This includes:
6654- Creating new examples in the documentation (e.g. plotting examples)
6755
6856
57+
6958Ground Rules
7059------------------------------
7160
72- Please follow the code of conduct .
61+ Please follow the ` Code of Conduct < https://github.com/ncar/wrf-python >`_ .
7362
63+ - Please create an issue on GitHub for any pull request you wish to submit,
64+ except for documentation issues.
7465- Each pull request should be for a logical collection of changes. You can
7566 submit multiple bug fixes in a single pull request if the bugs are related.
7667 Otherwise, please submit seperate pull requests.
@@ -107,7 +98,165 @@ create an account on GitHub to submit a report.
107986. If you are getting a crash (e.g. segmentation fault), we will most likely
10899 need to see your data file if we cannot reproduce the problem here.
109100 See :ref: `submitting_files `.
101+
102+
103+ Submitting Fortran Computational Routines
104+ --------------------------------------------
105+
106+ If you have Fortran computational routines that you'd like to contribute,
107+ but don't know how to wrap them in to Python, please follow the instructions
108+ below.
109+
110+ 1. Only Fortran 90 code will be accepted, so please port your F77 code to
111+ F90.
112+
113+ 2. Follow the :ref: `fortranstyle `.
114+
115+ 3. Please only submit routines relevant to WRF-Python (e.g. diagnostics,
116+ interpolation). General purpose climate/meteorology should go in the
117+ SkyLab project (a project providing similar functionality as
118+ NCL).
119+
120+ 4. If you are unsure if you should contribute your Fortran code, make an
121+ issue on GitHub and we can begin a discussion there.
122+
123+ 5. Place your code in the fortran/contrib directory in the WRF-Python
124+ source tree.
125+
126+ 6. Document your code with a text file that has same name as your Fortran
127+ file, but ending in .rst. This file should placed with your F90 code
128+ in the fortran/contrib directory. Your documentation can use
129+ restructured text formatting, or just plain text. This documentation
130+ will be used in the docstring when Python wrappers are made.
131+
132+ 7. If you are unable to provide any type of test for your routine, please
133+ ensure that your documentation describes what your computation
134+ should produce. You can submit auxiallary documentation and/or images for
135+ this purpose if needed.
136+
137+
138+ Submitting Python Computational Routines
139+ ---------------------------------------------
140+
141+ If you would like to submit a computational routine in Python, but don't know
142+ how to integrate it with the rest of WRF-Python's internals
143+ (e.g. left indexing, arg checking, etc), feel free to
144+ submit the pure Python routine. Below is the guide for submitting pure
145+ Python routines.
146+
147+ 1. These routines should be placed in src/wrf/contrib.py. These algorithms
148+ will not be imported in to WRF-Python's default namespace.
149+
150+ 2. Follow the :ref: `pythonstyle `.
151+
152+ 2. Write your computation as dimension unaware as possible. For example,
153+ adding pressure and perturbation pressure is simply P + PB.
154+
155+ 3. If dimensionality is needed, then write for the minimum dimensionality
156+ required to make the computation for one time step (if applicable). For
157+ example, if you're computing CAPE, then you should use three dimensions for
158+ your algorithm, and we will handle the looping over all times.
159+
160+ 4. Document your routine by creating a docstring that follows Google docstring
161+ format (see `Sphinx Napoleon <https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#google-vs-numpy >`_).
162+
163+ 5. If you are unable to provide a test for this function, please provide
164+ additional documentation (or images) to show what this function should
165+ produce.
166+
167+
168+ Submitting Fully Wrapped Computational Routines
169+ ---------------------------------------------------
170+
171+ Submitting a fully wrapped computational routines is the fastest way to get
172+ your contributation released. However, it requires the most effort on your
173+ part. (This process will be simplified in the future, but it's a little
174+ tedious at this time).
175+
176+ 1. Read the :ref: `internals ` guide. This will show you how to wrap your
177+ routine.
178+
179+ 2. Follow the :ref: `fortranstyle ` and :ref: `pythonstyle `.
180+
181+ 3. You should create your contribution in the WRF-Pyhon source tree as if
182+ you were one of the core developers of it. This means:
183+
184+ - Your Fortran code (if applicable) should be placed in the fortran folder.
185+
186+ - Update the "ext1 = numpy.distutils.core.Extension" section of setup.py
187+ to include your new Fortran source (if applicable).
188+
189+ - Update extension.py to create the Python wrapper that calls your
190+ Fortran function. This must include the appropriate function decorators
191+ for handling argument checking, leftmost dimension indexing, etc. as
192+ described in :ref: `internals `.
193+
194+ - If the current function decorators do not cover your specific needs,
195+ place your custom decorator in specialdec.py. Most of the decorators
196+ in this module are used for products that contain multiple outputs like
197+ cape_2d, but this
198+
199+ - If your function is pure python, you can create a new module for it,
200+ or place it in another module with similar functionality. For example,
201+ if your routine is a new interpolation routine, then it should go
202+ in interp.py. Remember to apply the same type of decorators as
203+ done with Fortran extensions (checking args, leftmost indexings, etc).
204+
205+ - Create a 'getter' routine which is responsible for extracting the
206+ required variables from a WRF file and calling your computational
207+ routine. This is what will be called by :meth: `wrf.getvar `.
208+ This function should be placed in a new python module with the prefix
209+ 'g _' (i.e. g_yourdiagnostic.py)
210+
211+ - Decorate your getter routine with an appropriate metadata handling
212+ decorator. If you need to make a custom decorator for the metadata,
213+ place it in metadecorators.py.
214+
215+ - Update the mappings in routines.py to map your diagnostic name to your
216+ function, and to declare any keyword arguments that your function
217+ needs aside from the usual wrfin, varname, timeidx, method,
218+ squeeze, cache, and meta.
219+
220+ - If you would like to make your routine available as a raw computation,
221+ you will need to place an additional thin wrapper in computation.py. This
222+ thin wrapper must be decorated with an appropriate metadata decorator
223+ found in metadecorators.py (usually set_alg_metadata). If you need to
224+ write your own custom metadata decorator, write it in metadecorators.py.
225+
226+ - You must provide a docstring for every function you create using
227+ Google docstring format (see `Sphinx Napoleon <https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#google-vs-numpy >`_).
228+
229+ - You must provide a test for your function. See :ref: `testing `.
230+
231+
232+ Fixing Documentation Errors
233+ --------------------------------------
110234
235+ 1. Documenation is made with Sphinx using restructured text.
236+
237+ 2. Python docstrings follow `Google docstring <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html >`_ format.
238+
239+ 2. Documentation can be found in the *doc * directory, along with the
240+ docstrings contained within the Python code.
241+
242+ 3. For documentation fixes, you can just submit a pull request with the
243+ appropriate corrections already made.
244+
245+
246+ Creating New Examples
247+ --------------------------------------
248+
249+ 1. Examples are made with Sphinx using restructured text.
250+
251+ 2. Examples are currently found in the *doc * directory, mostly within the
252+ basic_usage.rst and plot.rst files. Feel free to contribute more examples
253+ to these files.
254+
255+ 3. Unless you are drastically changing the documentation structure, you can
256+ submit a pull request with your examples without creating a GitHub
257+ issue. If you are making a large change, or are unsure about it, then
258+ go ahead and create a GitHub issue to discuss with the developers.
259+
111260
112261Setting Up Your Development Environment
113262---------------------------------------------
@@ -200,18 +349,13 @@ contributing is:
200349 Now follow the previous step to rebuild.
201350
202351
203- Pull Requests
204- --------------------------
205-
206- In order to submit changes, you must use GitHub to issue a pull request. Your
207- pull requests should be made against the **develop ** branch, since we are
208- following GitFlow for this project.
209-
210352
211353Code Style
212354--------------------------
213355
214- Python Contributions
356+ .. _pythonstyle :
357+
358+ Python Style Guide
215359^^^^^^^^^^^^^^^^^^^^^^^^^^
216360
217361The Python code in WRF-Python follows the
@@ -224,7 +368,9 @@ whitespace characters in blank lines, etc.), try the
224368`autopep8 <https://pypi.org/project/autopep8/0.8/ >`_ utility.
225369
226370
227- Fortran Contributions
371+ .. _fortranstyle :
372+
373+ Fortran Style Guide
228374^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229375
230376WRF-Python is a Fortran friendly project and we appreciate your contributions.
@@ -271,7 +417,80 @@ A summary of style notes is below:
271417 unfamiliar OpenMP, but feel free to do so if you are already familiar.
272418
273419
420+ Pull Requests
421+ --------------------------
274422
423+ In order to submit changes, you must use GitHub to issue a pull request. Your
424+ pull requests should be made against the **develop ** branch, since we are
425+ following GitFlow for this project.
426+
427+ Following a pull request, automated continuous integration tools will be
428+ run to ensure that your code follows the PEP 8 style guide, and verifies that
429+ a basic suite of unit tests run.
430+
431+
432+ .. testing_ ::
433+
434+ Tests
435+ ---------------------------
436+
437+ Once you have submitted your contribution, we need a way to test your
438+ code. Currently, most of WRF-Python's tests are written to ensure that
439+ WRF-Python produces the same result as the NCAR Command Language (NCL), which
440+ is where the code was originally derived. However, this isn't applicable for
441+ new contributions and bug fixes, since there is nothing to test against for
442+ new contributions and bug fixes might change the numerical result. So, we have
443+ some recommendations below for how you can create your own tests.
444+
445+ Sample Data
446+ ^^^^^^^^^^^^^^^^^^^
447+
448+ You can download sample data for Hurricane Katrina here: <insert link>
449+ This data has both moving nest and static nest version. You should test
450+ against this data set, unless you are unable to demonstrate the problem
451+ with it.
452+
453+ Supplying Data
454+ ^^^^^^^^^^^^^^^^^^^^^^
455+
456+ If you need to supply us data for your test, please provide us a link to
457+ either a cloud storage service, by :ref: `submitting-files `, or some other
458+ means. Unless the data is very small, do not add it to the GitHub repository.
459+
460+ If you can demonstrate the problem/solution with a minimal set of hand created
461+ values, you can just put that in your test itself.
462+
463+
464+ Guidelines
465+ ^^^^^^^^^^^^^^^^^^^
466+
467+ The following are guidelines for testing you contributions. Obviously,
468+ different issues have different needs, so you can use the GitHub
469+ issue related to your contribution to discuss with developers.
470+
471+ 1. New computations must work for both moving nests and static nests.
472+ Generally this is not an issue unless your data makes use of lat/lon
473+ information (e.g. cross sections with lat/lon line definitions).
474+
475+ 2. WRF-Python's tests can be found in the *test * directory.
476+
477+ 3. WRF-Python's tests were written using the standard *unittest * package,
478+ along with numpy's test package for the assert fuctions. One
479+ reason for this is that many of the tests are dynamically generated, and
480+ some other testing frameworks can't find the tests when generated this way.
481+ If you need to use another test framework, that's fine, just let us know
482+ in your GitHub issue.
483+
484+ 4. Place your test in the test/contrib directory.
485+
486+ 5. For new contributions, images may be sufficient to show that your
487+ code is working. Discuss with the developers in you GitHub issue.
488+
489+ 6. For bug related issues, try to create a case that demonstrates the problem,
490+ and demonstrates the fix. If your problem is a crash, then proving that
491+ your code runs without crashing should be sufficient.
492+
493+ 7. You might need some creativity here.
275494
276495
277496
0 commit comments