[efdb01a] | 1 | #!/usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | #************************************************************************ |
---|
[ff99eae] | 4 | # ToDo AP |
---|
[991df6a] | 5 | # - check alist of size 4 ? |
---|
| 6 | # - write a test, IMPORTANT |
---|
[efdb01a] | 7 | #************************************************************************ |
---|
[991df6a] | 8 | #******************************************************************************* |
---|
| 9 | # @Author: Anne Philipp (University of Vienna) |
---|
| 10 | # |
---|
| 11 | # @Date: March 2018 |
---|
| 12 | # |
---|
| 13 | # @Change History: |
---|
| 14 | # November 2015 - Leopold Haimberger (University of Vienna): |
---|
| 15 | # - migration of the methods dapoly and darain from Fortran |
---|
| 16 | # (flex_extract_v6 and earlier) to Python |
---|
| 17 | # |
---|
| 18 | # April 2018 - Anne Philipp (University of Vienna): |
---|
| 19 | # - applied PEP8 style guide |
---|
| 20 | # - added structured documentation |
---|
| 21 | # - outsourced the disaggregation functions dapoly and darain |
---|
[ff99eae] | 22 | # to a new module named disaggregation |
---|
[991df6a] | 23 | # |
---|
| 24 | # @License: |
---|
| 25 | # (C) Copyright 2015-2018. |
---|
| 26 | # |
---|
| 27 | # This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
| 28 | # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
| 29 | # |
---|
| 30 | # @Module Description: |
---|
[ff99eae] | 31 | # disaggregationregation of deaccumulated flux data from an ECMWF model FG field. |
---|
[991df6a] | 32 | # Initially the flux data to be concerned are: |
---|
| 33 | # - large-scale precipitation |
---|
| 34 | # - convective precipitation |
---|
| 35 | # - surface sensible heat flux |
---|
| 36 | # - surface solar radiation |
---|
| 37 | # - u stress |
---|
| 38 | # - v stress |
---|
| 39 | # Different versions of disaggregation is provided for rainfall |
---|
| 40 | # data (darain, modified linear) and the surface fluxes and |
---|
| 41 | # stress data (dapoly, cubic polynomial). |
---|
| 42 | # |
---|
| 43 | # @Module Content: |
---|
| 44 | # - dapoly |
---|
| 45 | # - darain |
---|
| 46 | # |
---|
| 47 | #******************************************************************************* |
---|
[efdb01a] | 48 | |
---|
| 49 | # ------------------------------------------------------------------------------ |
---|
| 50 | # MODULES |
---|
| 51 | # ------------------------------------------------------------------------------ |
---|
| 52 | |
---|
| 53 | # ------------------------------------------------------------------------------ |
---|
| 54 | # FUNCTIONS |
---|
| 55 | # ------------------------------------------------------------------------------ |
---|
| 56 | def dapoly(alist): |
---|
| 57 | ''' |
---|
| 58 | @Author: P. JAMES |
---|
| 59 | |
---|
| 60 | @Date: 2000-03-29 |
---|
| 61 | |
---|
| 62 | @ChangeHistory: |
---|
| 63 | June 2003 - A. BECK (2003-06-01) |
---|
| 64 | adaptaions |
---|
| 65 | November 2015 - Leopold Haimberger (University of Vienna) |
---|
| 66 | migration from Fortran to Python |
---|
| 67 | |
---|
| 68 | @Description: |
---|
| 69 | Interpolation of deaccumulated fluxes of an ECMWF model FG field |
---|
| 70 | using a cubic polynomial solution which conserves the integrals |
---|
| 71 | of the fluxes within each timespan. |
---|
[ff99eae] | 72 | disaggregationregation is done for 4 accumluated timespans which generates |
---|
[efdb01a] | 73 | a new, disaggregated value which is output at the central point |
---|
| 74 | of the 4 accumulation timespans. This new point is used for linear |
---|
| 75 | interpolation of the complete timeseries afterwards. |
---|
| 76 | |
---|
| 77 | @Input: |
---|
| 78 | alist: list of size 4, array(2D), type=float |
---|
| 79 | List of 4 timespans as 2-dimensional, horizontal fields. |
---|
| 80 | E.g. [[array_t1], [array_t2], [array_t3], [array_t4]] |
---|
| 81 | |
---|
| 82 | @Return: |
---|
| 83 | nfield: array(2D), type=float |
---|
| 84 | New field which replaces the field at the second position |
---|
| 85 | of the accumulation timespans. |
---|
| 86 | |
---|
| 87 | ''' |
---|
| 88 | pya = (alist[3] - alist[0] + 3. * (alist[1] - alist[2])) / 6. |
---|
| 89 | pyb = (alist[2] + alist[0]) / 2. - alist[1] - 9. * pya / 2. |
---|
| 90 | pyc = alist[1] - alist[0] - 7. * pya / 2. - 2. * pyb |
---|
| 91 | pyd = alist[0] - pya / 4. - pyb / 3. - pyc / 2. |
---|
| 92 | nfield = 8. * pya + 4. * pyb + 2. * pyc + pyd |
---|
| 93 | |
---|
| 94 | return nfield |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | def darain(alist): |
---|
| 98 | ''' |
---|
| 99 | @Author: P. JAMES |
---|
| 100 | |
---|
| 101 | @Date: 2000-03-29 |
---|
| 102 | |
---|
| 103 | @ChangeHistory: |
---|
| 104 | June 2003 - A. BECK (2003-06-01) |
---|
| 105 | adaptaions |
---|
| 106 | November 2015 - Leopold Haimberger (University of Vienna) |
---|
| 107 | migration from Fortran to Python |
---|
| 108 | |
---|
| 109 | @Description: |
---|
| 110 | Interpolation of deaccumulated fluxes of an ECMWF model FG rainfall |
---|
| 111 | field using a modified linear solution which conserves the integrals |
---|
| 112 | of the fluxes within each timespan. |
---|
[ff99eae] | 113 | disaggregationregation is done for 4 accumluated timespans which generates |
---|
[efdb01a] | 114 | a new, disaggregated value which is output at the central point |
---|
| 115 | of the 4 accumulation timespans. This new point is used for linear |
---|
| 116 | interpolation of the complete timeseries afterwards. |
---|
| 117 | |
---|
| 118 | @Input: |
---|
| 119 | alist: list of size 4, array(2D), type=float |
---|
| 120 | List of 4 timespans as 2-dimensional, horizontal fields. |
---|
| 121 | E.g. [[array_t1], [array_t2], [array_t3], [array_t4]] |
---|
| 122 | |
---|
| 123 | @Return: |
---|
| 124 | nfield: array(2D), type=float |
---|
| 125 | New field which replaces the field at the second position |
---|
| 126 | of the accumulation timespans. |
---|
| 127 | ''' |
---|
| 128 | xa = alist[0] |
---|
| 129 | xb = alist[1] |
---|
| 130 | xc = alist[2] |
---|
| 131 | xd = alist[3] |
---|
| 132 | xa[xa < 0.] = 0. |
---|
| 133 | xb[xb < 0.] = 0. |
---|
| 134 | xc[xc < 0.] = 0. |
---|
| 135 | xd[xd < 0.] = 0. |
---|
| 136 | |
---|
| 137 | xac = 0.5 * xb |
---|
| 138 | mask = xa + xc > 0. |
---|
| 139 | xac[mask] = xb[mask] * xc[mask] / (xa[mask] + xc[mask]) |
---|
| 140 | xbd = 0.5 * xc |
---|
| 141 | mask = xb + xd > 0. |
---|
| 142 | xbd[mask] = xb[mask] * xc[mask] / (xb[mask] + xd[mask]) |
---|
| 143 | nfield = xac + xbd |
---|
| 144 | |
---|
| 145 | return nfield |
---|