source: flex_extract.git/python/Disagg.py @ efdb01a

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

whole bunch of modifications due to new structure of ECMWFDATA, added basics of documentation, minor programming corrections

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