source: flex_extract.git/python/disaggregation.py @ ff99eae

ctbtodev
Last change on this file since ff99eae was ff99eae, checked in by Anne Philipp <anne.philipp@…>, 6 years ago

completed application of pep8 style guide and pylint investigations. added documentation almost everywhere

  • Property mode set to 100644
File size: 4.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#************************************************************************
4# ToDo AP
5# - check alist of size 4 ?
6# - write a test, IMPORTANT
7#************************************************************************
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
22#          to a new module named disaggregation
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:
31#    disaggregationregation of deaccumulated flux data from an ECMWF model FG field.
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#*******************************************************************************
48
49# ------------------------------------------------------------------------------
50# MODULES
51# ------------------------------------------------------------------------------
52
53# ------------------------------------------------------------------------------
54# FUNCTIONS
55# ------------------------------------------------------------------------------
56def 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.
72        disaggregationregation is done for 4 accumluated timespans which generates
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
97def 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.
113        disaggregationregation is done for 4 accumluated timespans which generates
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
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG