source: flex_extract.git/python/disaggregation.py @ 97e09f4

ctbtodevfeature/makefilesorigin/task/language-editingtask/language-editing
Last change on this file since 97e09f4 was 54a8a01, checked in by Anne Philipp <anne.philipp@…>, 3 years ago

restructuring, documentations and bug fixes

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