|
1 | 1 | README
|
2 | 2 | ------
|
3 | 3 |
|
4 |
| -NREL provides a C implementation of the solar position algorithm |
5 |
| -described in |
6 |
| -[Reda, I.; Andreas, A. (2003). Solar Position Algorithm for Solar Radiation Applications. 55 pp.; NREL Report No. TP-560-34302]( |
7 |
| -http://www.nrel.gov/docs/fy08osti/34302.pdf). |
| 4 | +NREL provides a C implementation of the solar position algorithm described in |
| 5 | +[Reda, I.; Andreas, A. (2003). Solar Position Algorithm for Solar Radiation Applications. 55 pp.; NREL Report No. TP-560-34302](http://www.nrel.gov/docs/fy08osti/34302.pdf). |
8 | 6 |
|
9 |
| -This folder contains the files required to make NREL's C code accessible |
10 |
| -to the ``pvlib-python`` package. We use the Cython package to wrap NREL's SPA |
| 7 | +This folder contains the files required to make SPA C code accessible |
| 8 | +to the `pvlib-python` package. We use the Cython package to wrap the NREL SPA |
11 | 9 | implementation.
|
12 | 10 |
|
13 |
| -** Due to licensing issues, you must download the NREL C files from their |
14 |
| -[website](http://www.nrel.gov/midc/spa) ** |
| 11 | +** Due to licensing issues, the SPA C files can _not_ be distributed with |
| 12 | +`pvlib-python`. You must download the SPA C files from the |
| 13 | +[NREL website](https://midcdmz.nrel.gov/spa/). ** |
15 | 14 |
|
16 |
| -Download the ``spa.c`` and ``spa.h`` files from NREL, |
17 |
| -and copy them into the ``pvlib/spa_c_files`` directory. |
| 15 | +Download the `spa.c` and `spa.h` files from NREL, and copy them into the |
| 16 | +`pvlib/spa_c_files` directory. When the extension is built, the ``timezone`` |
| 17 | +field in the SPA C files is replaced with `time_zone` to avoid a nameclash |
| 18 | +with the function `__timezone` that is redefined by Python>=3.5. This issue |
| 19 | +is [Python bug 24643](https://bugs.python.org/issue24643). |
18 | 20 |
|
19 | 21 | There are a total of 5 files needed to compile the C code, described below:
|
20 | 22 |
|
21 |
| -* ``spa.c``: original C code from NREL |
22 |
| -* ``spa.h``: header file for spa.c |
23 |
| -* ``cspa_py.pxd``: a cython header file which essentially tells cython which parts of the main header file to pay attention to |
24 |
| -* ``spa_py.pyx``: the cython code used to define both functions in the python namespace. NOTE: It is possible to provide user access to other paramters of the SPA algorithm through modifying this file |
25 |
| -* ``setup.py``: a distutils file which performs the compiling of the cython code |
| 23 | +* `spa.c`: original C code from NREL |
| 24 | +* `spa.h`: header file for spa.c |
| 25 | +* `cspa_py.pxd`: a cython header file which essentially tells cython which |
| 26 | + parts of the main header file to pay attention to |
| 27 | +* `spa_py.pyx`: the cython code used to define both functions in the python |
| 28 | + namespace. NOTE: It is possible to provide user access to other paramters of |
| 29 | + the SPA algorithm through modifying this file |
| 30 | +* `setup.py`: a distutils file which performs the compiling of the cython code |
26 | 31 |
|
27 | 32 | The cython compilation process produces two files:
|
28 |
| -* ``spa_py.c``: an intermediate cython c file |
29 |
| -* ``spa_py.so``: the python module which can be imported into a namespace |
| 33 | +* `spa_py.c`: an intermediate cython c file |
| 34 | +* `spa_py.so` or `spa_py.<cpyver-plat>.pyd`: the python module which |
| 35 | + can be imported into a namespace |
30 | 36 |
|
31 |
| -To process the original 5 files, |
32 |
| -use the following shell command inside this folder |
33 |
| - |
34 |
| - $ python setup.py build_ext --inplace |
| 37 | +To create the SPA Python extension, use the following shell command inside this |
| 38 | +folder: |
| 39 | + |
| 40 | + $ python setup.py build_ext --inplace |
| 41 | + |
| 42 | +There are four optional keyword arguments `delta_ut1=0`, `slope=30.0`, |
| 43 | +`azm_rotation=-10`, `atmos_refract` that effect four optional return values |
| 44 | +`incidence`, `suntransit`, `sunrise`, and `sunset`. If not given, the defaults |
| 45 | +shown are used. |
| 46 | + |
| 47 | +There is an example in `spa_py_example.py` that contains a test function called |
| 48 | +`spa_calc_example` that users can use to check that the result is consistent |
| 49 | +with expected values: |
| 50 | + |
| 51 | + >>> from spa_py_example import spa_calc_example |
| 52 | + >>> r = spa_calc_example() |
| 53 | + { |
| 54 | + 'year': 2004, |
| 55 | + 'month': 10, |
| 56 | + 'day': 17, |
| 57 | + 'hour': 12, |
| 58 | + 'minute': 30, |
| 59 | + 'second': 30.0, |
| 60 | + 'delta_ut1': 0.0, |
| 61 | + 'delta_t': 67.0, |
| 62 | + 'time_zone': -7.0, |
| 63 | + 'longitude': -105.1786, |
| 64 | + 'latitude': 39.742476, |
| 65 | + 'elevation': 1830.14, |
| 66 | + 'pressure': 820.0, |
| 67 | + 'temperature': 11.0, |
| 68 | + 'slope': 30.0, |
| 69 | + 'azm_rotation': -10.0, |
| 70 | + 'atmos_refract': 0.5667, |
| 71 | + 'function': 3, |
| 72 | + 'e0': 39.59209464796398, |
| 73 | + 'e': 39.60858878898177, |
| 74 | + 'zenith': 50.39141121101823, |
| 75 | + 'azimuth_astro': 14.311961805946808, |
| 76 | + 'azimuth': 194.3119618059468, |
| 77 | + 'incidence': 25.42168493680471, |
| 78 | + 'suntransit': 11.765833793714224, |
| 79 | + 'sunrise': 6.22578372122376, |
| 80 | + 'sunset': 17.320379610556166 |
| 81 | + } |
0 commit comments