1 | #!/usr/bin/python3 |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | #------------------------------------------------------------------------------# |
---|
5 | # |
---|
6 | # Scripts for processing of WRF and CAMx files to PALM dynamic driver |
---|
7 | # |
---|
8 | # This program is free software: you can redistribute it and/or modify |
---|
9 | # it under the terms of the GNU General Public License as published by |
---|
10 | # the Free Software Foundation, either version 3 of the License, or |
---|
11 | # (at your option) any later version. |
---|
12 | # |
---|
13 | # This program is distributed in the hope that it will be useful, |
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | # GNU General Public License for more details. |
---|
17 | # |
---|
18 | # You should have received a copy of the GNU General Public License |
---|
19 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
---|
20 | # |
---|
21 | # Copyright 2018-2021 Institute of Computer Science |
---|
22 | # of the Czech Academy of Sciences, Prague |
---|
23 | # Authors: Krystof Eben, Jaroslav Resler, Pavel Krc |
---|
24 | # |
---|
25 | #------------------------------------------------------------------------------# |
---|
26 | ''' |
---|
27 | This file provides initialization of the basic variables and structures base on |
---|
28 | the default and user config values. It can be adjusted to the needs of particular |
---|
29 | user system or structure of the data storage. |
---|
30 | ''' |
---|
31 | |
---|
32 | import os |
---|
33 | from pathlib import Path |
---|
34 | import numpy as np |
---|
35 | |
---|
36 | # paths of directories |
---|
37 | dir_base = os.path.abspath(Path(dir_scripts).parent.parent) |
---|
38 | print('Base dir:', dir_base) |
---|
39 | dir_in = os.path.join(dir_base, domain) |
---|
40 | print('Input dir:', dir_in) |
---|
41 | if scenario == '': |
---|
42 | dir_in_scen = dir_in |
---|
43 | else: |
---|
44 | dir_in_scen = os.path.join(dir_in,scenario) |
---|
45 | print('Scenario input dir:', dir_in_scen) |
---|
46 | dir_out = os.path.join(dir_base, domain) |
---|
47 | print('Output dir:', dir_out) |
---|
48 | |
---|
49 | # file names of PALM PIDS drivers |
---|
50 | # extension of file name for scenario |
---|
51 | scenario_ext = ("_"+scenario if scenario != "" else "") |
---|
52 | # static driver netcdf file name |
---|
53 | if static_driver_file == "": |
---|
54 | static_driver_file = os.path.join(dir_out, domain+"_static_driver"+"_d"+resolution+scenario_ext+".nc") |
---|
55 | # dynamic driver netcdf file name |
---|
56 | if dynamic_driver_file == "": |
---|
57 | dynamic_driver_file = os.path.join(dir_out, domain+"_dynamic_driver"+"_d"+resolution+scenario_ext+".nc") |
---|
58 | |
---|
59 | # parameters of dynamic driver |
---|
60 | # minimal number of free surface canopy layers above top of terrain with building and plant canopy |
---|
61 | nscl_free = 3 |
---|
62 | # default path of wrf files in case it is not set in user config |
---|
63 | if wrf_dir_name == '': |
---|
64 | wrf_dir_name = os.path.join(dir_in, 'wrf') |
---|
65 | |
---|
66 | # Settings for geostrophic wind |
---|
67 | gw_gfs_margin_deg = 5. #smoothing area in degrees lat/lon |
---|
68 | gw_wrf_margin_km = 10. #smoothing area in km |
---|
69 | #gw_alpha = .143 #GW vertical interpolation by power law |
---|
70 | gw_alpha = 1. #ignore wind power law, interpolate linearly |
---|
71 | |
---|
72 | |
---|
73 | # chemical initial and boundary coords - CAMx nesting |
---|
74 | # CAMx variable conversions |
---|
75 | camx_conversions = { |
---|
76 | 'NO': dict( |
---|
77 | camx_vars = ['NO'], |
---|
78 | camx_units = ['ppmv'], |
---|
79 | output_unit = 'ppm', |
---|
80 | formula = lambda no, hlp: no, |
---|
81 | ), |
---|
82 | 'NO2': dict( |
---|
83 | camx_vars = ['NO2'], |
---|
84 | camx_units = ['ppmv'], |
---|
85 | output_unit = 'ppm', |
---|
86 | formula = lambda no2, hlp: no2, |
---|
87 | ), |
---|
88 | 'NOX': dict( |
---|
89 | camx_vars=['NO', 'NO2'], |
---|
90 | camx_units=['ppmv', 'ppmv'], |
---|
91 | output_unit='ppm', |
---|
92 | formula=lambda no, no2, hlp: no + no2, |
---|
93 | ), |
---|
94 | 'O3': dict( |
---|
95 | camx_vars = ['O3'], |
---|
96 | camx_units = ['ppmv'], |
---|
97 | output_unit = 'ppm', |
---|
98 | formula = lambda o3, hlp: o3, |
---|
99 | ), |
---|
100 | 'PM10': dict( |
---|
101 | camx_vars = ['CPRM'], |
---|
102 | camx_units = ['micrograms m-3'], |
---|
103 | output_unit = 'kg/m3', |
---|
104 | formula = lambda cprm, hlp: (cprm+hlp.pm25) * 1e-9, |
---|
105 | ), |
---|
106 | 'PM25': dict( |
---|
107 | camx_vars = [], |
---|
108 | camx_units = [], |
---|
109 | output_unit = 'kg/m3', |
---|
110 | formula = lambda hlp: hlp.pm25 * 1e-9, |
---|
111 | ), |
---|
112 | } |
---|
113 | |
---|
114 | camx_helpers = [ |
---|
115 | ('pm25', dict( |
---|
116 | camx_vars = 'PSO4 PNO3 PNH4 POA PEC FPRM SOA1 SOA2 SOA3 SOA4 SOPA SOPB'.split(), |
---|
117 | camx_units = ['micrograms m-3']*12, |
---|
118 | formula = lambda *args: np.sum(args[:-1], axis=0), #last arg is hlp |
---|
119 | )), |
---|
120 | ] |
---|
121 | |
---|
122 | |
---|