Coverage for wrainfo/precipitation.py: 100%
14 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-18 12:40 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-18 12:40 +0000
1"""Precipitation estimation module."""
3# WRaINfo, Is a software to process FURUNO weather radar data.
4#
5# Copyright (c) 2022, FernLab (GFZ Potsdam, fernlab@gfz-potsdam.de)
6#
7# This software was developed within the context of the RaINfo ("Potential use of
8# high resolution weather data in agriculture") project of FernLab funded by
9# the Impulse and Networking Fund of the Helmholtz Association.
10#
11# Licensed under the Apache License, Version 2.0 (the "License");
12# you may not use this file except in compliance with the License.
13#
14# You may obtain a copy of the License at
15# http://www.apache.org/licenses/LICENSE-2.0
16#
17# Unless required by applicable law or agreed to in writing, software
18# distributed under the License is distributed on an "AS IS" BASIS,
19# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20# See the License for the specific language governing permissions and
21# limitations under the License.
23# imports
24# -------
26import wradlib as wrl
27import xarray as xr
28from wrainfo.reader import read_config_file
31# quantitative precipitation estimation (QPE): R(Z)
32# -------------------------------------------------
34def qpe_zr(ds,
35 moment,
36 path,
37 a=200,
38 b=1.6):
39 """Qualitative precipitation estimation with z-R conversion.
41 Parameters
42 ----------
43 ds : xarray.Dataset
44 moment : str
45 name of the clutter and attenuation corrected data array in the dataset.
46 path : str
47 path to configuration file
48 a : integer
49 parameter for the z-R-conversion
50 (Marschall Palmer default value: a = 200, German Weather Service = 256)
51 b : float
52 parameter for the z-R-conversion
53 (Marschall Palmer default value: b = 1.6, German Weather Service = 1.42)
55 Returns
56 -------
57 : xarray.Dataset
58 xarray.Dataset with a data array of derived precipitation amounts.
59 """
60 # read setting from configuration file
61 dims = read_config_file(path=path, selection="dimensions")
62 interval = read_config_file(path=path, selection="scan_interval")
64 # precipitation attributes
65 prec_attrs = {"standard_name": "precipitation_amount_z_r_relationship",
66 "long_name": "precipitation_amount_z_r_relationship",
67 "unit": "mm", }
69 # QPE Z(R)
70 rr = ds[moment].pipe(wrl.trafo.idecibel).pipe(wrl.zr.z_to_r, a=a, b=b)
71 depth = wrl.trafo.r_to_depth(rr, interval)
73 # add to dataset
74 ds["PREC_ZR"] = xr.DataArray(depth, dims=dims, attrs=prec_attrs)
76 # fix encoding
77 chunk = read_config_file(path=path, selection="chunksize")
79 comp = dict(zlib=True, complevel=7, chunksizes=(chunk[0], chunk[1], chunk[2]))
80 ds.PREC_ZR.encoding = comp
82 return ds