disdrodb 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. disdrodb/__init__.py +68 -34
  2. disdrodb/_config.py +5 -4
  3. disdrodb/_version.py +16 -3
  4. disdrodb/accessor/__init__.py +20 -0
  5. disdrodb/accessor/methods.py +125 -0
  6. disdrodb/api/checks.py +177 -24
  7. disdrodb/api/configs.py +3 -3
  8. disdrodb/api/info.py +13 -13
  9. disdrodb/api/io.py +281 -22
  10. disdrodb/api/path.py +184 -195
  11. disdrodb/api/search.py +18 -9
  12. disdrodb/cli/disdrodb_create_summary.py +103 -0
  13. disdrodb/cli/disdrodb_create_summary_station.py +91 -0
  14. disdrodb/cli/disdrodb_run_l0.py +1 -1
  15. disdrodb/cli/disdrodb_run_l0_station.py +1 -1
  16. disdrodb/cli/disdrodb_run_l0a_station.py +1 -1
  17. disdrodb/cli/disdrodb_run_l0b.py +1 -1
  18. disdrodb/cli/disdrodb_run_l0b_station.py +3 -3
  19. disdrodb/cli/disdrodb_run_l0c.py +1 -1
  20. disdrodb/cli/disdrodb_run_l0c_station.py +3 -3
  21. disdrodb/cli/disdrodb_run_l1_station.py +2 -2
  22. disdrodb/cli/disdrodb_run_l2e_station.py +2 -2
  23. disdrodb/cli/disdrodb_run_l2m_station.py +2 -2
  24. disdrodb/configs.py +149 -4
  25. disdrodb/constants.py +61 -0
  26. disdrodb/data_transfer/download_data.py +127 -11
  27. disdrodb/etc/configs/attributes.yaml +339 -0
  28. disdrodb/etc/configs/encodings.yaml +473 -0
  29. disdrodb/etc/products/L1/global.yaml +13 -0
  30. disdrodb/etc/products/L2E/10MIN.yaml +12 -0
  31. disdrodb/etc/products/L2E/1MIN.yaml +1 -0
  32. disdrodb/etc/products/L2E/global.yaml +22 -0
  33. disdrodb/etc/products/L2M/10MIN.yaml +12 -0
  34. disdrodb/etc/products/L2M/GAMMA_ML.yaml +8 -0
  35. disdrodb/etc/products/L2M/NGAMMA_GS_LOG_ND_MAE.yaml +6 -0
  36. disdrodb/etc/products/L2M/NGAMMA_GS_ND_MAE.yaml +6 -0
  37. disdrodb/etc/products/L2M/NGAMMA_GS_Z_MAE.yaml +6 -0
  38. disdrodb/etc/products/L2M/global.yaml +26 -0
  39. disdrodb/issue/writer.py +2 -0
  40. disdrodb/l0/__init__.py +13 -0
  41. disdrodb/l0/configs/LPM/l0b_cf_attrs.yml +4 -4
  42. disdrodb/l0/configs/PARSIVEL/l0b_cf_attrs.yml +1 -1
  43. disdrodb/l0/configs/PARSIVEL/l0b_encodings.yml +3 -3
  44. disdrodb/l0/configs/PARSIVEL/raw_data_format.yml +1 -1
  45. disdrodb/l0/configs/PARSIVEL2/l0b_cf_attrs.yml +5 -5
  46. disdrodb/l0/configs/PARSIVEL2/l0b_encodings.yml +3 -3
  47. disdrodb/l0/configs/PARSIVEL2/raw_data_format.yml +1 -1
  48. disdrodb/l0/configs/PWS100/l0b_cf_attrs.yml +4 -4
  49. disdrodb/l0/configs/PWS100/raw_data_format.yml +1 -1
  50. disdrodb/l0/l0a_processing.py +37 -32
  51. disdrodb/l0/l0b_nc_processing.py +118 -8
  52. disdrodb/l0/l0b_processing.py +30 -65
  53. disdrodb/l0/l0c_processing.py +369 -259
  54. disdrodb/l0/readers/LPM/ARM/ARM_LPM.py +7 -0
  55. disdrodb/l0/readers/LPM/NETHERLANDS/DELFT_LPM_NC.py +66 -0
  56. disdrodb/l0/readers/LPM/SLOVENIA/{CRNI_VRH.py → UL.py} +3 -0
  57. disdrodb/l0/readers/LPM/SWITZERLAND/INNERERIZ_LPM.py +195 -0
  58. disdrodb/l0/readers/PARSIVEL/GPM/PIERS.py +0 -2
  59. disdrodb/l0/readers/PARSIVEL/JAPAN/JMA.py +4 -1
  60. disdrodb/l0/readers/PARSIVEL/NCAR/PECAN_MOBILE.py +1 -1
  61. disdrodb/l0/readers/PARSIVEL/NCAR/VORTEX2_2009.py +1 -1
  62. disdrodb/l0/readers/PARSIVEL2/ARM/ARM_PARSIVEL2.py +4 -0
  63. disdrodb/l0/readers/PARSIVEL2/BELGIUM/ILVO.py +168 -0
  64. disdrodb/l0/readers/PARSIVEL2/CANADA/UQAM_NC.py +69 -0
  65. disdrodb/l0/readers/PARSIVEL2/DENMARK/DTU.py +165 -0
  66. disdrodb/l0/readers/PARSIVEL2/FINLAND/FMI_PARSIVEL2.py +69 -0
  67. disdrodb/l0/readers/PARSIVEL2/FRANCE/ENPC_PARSIVEL2.py +255 -134
  68. disdrodb/l0/readers/PARSIVEL2/FRANCE/OSUG.py +525 -0
  69. disdrodb/l0/readers/PARSIVEL2/FRANCE/SIRTA_PARSIVEL2.py +1 -1
  70. disdrodb/l0/readers/PARSIVEL2/GPM/GCPEX.py +9 -7
  71. disdrodb/l0/readers/PARSIVEL2/KIT/BURKINA_FASO.py +1 -1
  72. disdrodb/l0/readers/PARSIVEL2/KIT/TEAMX.py +123 -0
  73. disdrodb/l0/readers/PARSIVEL2/{NETHERLANDS/DELFT.py → MPI/BCO_PARSIVEL2.py} +41 -71
  74. disdrodb/l0/readers/PARSIVEL2/MPI/BOWTIE.py +220 -0
  75. disdrodb/l0/readers/PARSIVEL2/NASA/APU.py +120 -0
  76. disdrodb/l0/readers/PARSIVEL2/NASA/LPVEX.py +109 -0
  77. disdrodb/l0/readers/PARSIVEL2/NCAR/FARM_PARSIVEL2.py +1 -0
  78. disdrodb/l0/readers/PARSIVEL2/NCAR/PECAN_FP3.py +1 -1
  79. disdrodb/l0/readers/PARSIVEL2/NCAR/PERILS_MIPS.py +126 -0
  80. disdrodb/l0/readers/PARSIVEL2/NCAR/PERILS_PIPS.py +165 -0
  81. disdrodb/l0/readers/PARSIVEL2/NCAR/VORTEX_SE_2016_P2.py +1 -1
  82. disdrodb/l0/readers/PARSIVEL2/NCAR/VORTEX_SE_2016_PIPS.py +20 -12
  83. disdrodb/l0/readers/PARSIVEL2/NETHERLANDS/DELFT_NC.py +5 -0
  84. disdrodb/l0/readers/PARSIVEL2/SPAIN/CENER.py +144 -0
  85. disdrodb/l0/readers/PARSIVEL2/SPAIN/CR1000DL.py +201 -0
  86. disdrodb/l0/readers/PARSIVEL2/SPAIN/LIAISE.py +137 -0
  87. disdrodb/l0/readers/PARSIVEL2/USA/C3WE.py +146 -0
  88. disdrodb/l0/readers/PWS100/FRANCE/ENPC_PWS100.py +105 -99
  89. disdrodb/l0/readers/PWS100/FRANCE/ENPC_PWS100_SIRTA.py +151 -0
  90. disdrodb/l1/__init__.py +5 -0
  91. disdrodb/l1/fall_velocity.py +46 -0
  92. disdrodb/l1/filters.py +34 -20
  93. disdrodb/l1/processing.py +46 -45
  94. disdrodb/l1/resampling.py +77 -66
  95. disdrodb/l1_env/routines.py +18 -3
  96. disdrodb/l2/__init__.py +7 -0
  97. disdrodb/l2/empirical_dsd.py +58 -10
  98. disdrodb/l2/processing.py +268 -117
  99. disdrodb/metadata/checks.py +132 -125
  100. disdrodb/metadata/standards.py +3 -1
  101. disdrodb/psd/fitting.py +631 -345
  102. disdrodb/psd/models.py +9 -6
  103. disdrodb/routines/__init__.py +54 -0
  104. disdrodb/{l0/routines.py → routines/l0.py} +316 -355
  105. disdrodb/{l1/routines.py → routines/l1.py} +76 -116
  106. disdrodb/routines/l2.py +1019 -0
  107. disdrodb/{routines.py → routines/wrappers.py} +98 -10
  108. disdrodb/scattering/__init__.py +16 -4
  109. disdrodb/scattering/axis_ratio.py +61 -37
  110. disdrodb/scattering/permittivity.py +504 -0
  111. disdrodb/scattering/routines.py +746 -184
  112. disdrodb/summary/__init__.py +17 -0
  113. disdrodb/summary/routines.py +4196 -0
  114. disdrodb/utils/archiving.py +434 -0
  115. disdrodb/utils/attrs.py +68 -125
  116. disdrodb/utils/cli.py +5 -5
  117. disdrodb/utils/compression.py +30 -1
  118. disdrodb/utils/dask.py +121 -9
  119. disdrodb/utils/dataframe.py +61 -7
  120. disdrodb/utils/decorators.py +31 -0
  121. disdrodb/utils/directories.py +35 -15
  122. disdrodb/utils/encoding.py +37 -19
  123. disdrodb/{l2 → utils}/event.py +15 -173
  124. disdrodb/utils/logger.py +14 -7
  125. disdrodb/utils/manipulations.py +81 -0
  126. disdrodb/utils/routines.py +166 -0
  127. disdrodb/utils/subsetting.py +214 -0
  128. disdrodb/utils/time.py +35 -177
  129. disdrodb/utils/writer.py +20 -7
  130. disdrodb/utils/xarray.py +5 -4
  131. disdrodb/viz/__init__.py +13 -0
  132. disdrodb/viz/plots.py +398 -0
  133. {disdrodb-0.1.2.dist-info → disdrodb-0.1.4.dist-info}/METADATA +4 -3
  134. {disdrodb-0.1.2.dist-info → disdrodb-0.1.4.dist-info}/RECORD +139 -98
  135. {disdrodb-0.1.2.dist-info → disdrodb-0.1.4.dist-info}/entry_points.txt +2 -0
  136. disdrodb/l1/encoding_attrs.py +0 -642
  137. disdrodb/l2/processing_options.py +0 -213
  138. disdrodb/l2/routines.py +0 -868
  139. /disdrodb/l0/readers/PARSIVEL/SLOVENIA/{UL_FGG.py → UL.py} +0 -0
  140. {disdrodb-0.1.2.dist-info → disdrodb-0.1.4.dist-info}/WHEEL +0 -0
  141. {disdrodb-0.1.2.dist-info → disdrodb-0.1.4.dist-info}/licenses/LICENSE +0 -0
  142. {disdrodb-0.1.2.dist-info → disdrodb-0.1.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env python3
2
+ # -----------------------------------------------------------------------------.
3
+ # Copyright (c) 2021-2023 DISDRODB developers
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # -----------------------------------------------------------------------------.
18
+ import pandas as pd
19
+
20
+ from disdrodb.l0.l0_reader import is_documented_by, reader_generic_docstring
21
+ from disdrodb.l0.l0a_processing import read_raw_text_file
22
+
23
+
24
+ def reader_parsivel(filepath, logger):
25
+ """Reader for Parsivel CR1000 Data Logger file."""
26
+ ##------------------------------------------------------------------------.
27
+ #### Define column names
28
+ column_names = [
29
+ "time",
30
+ "RECORD",
31
+ "rainfall_rate_32bit",
32
+ "rainfall_accumulated_32bit",
33
+ "weather_code_synop_4680",
34
+ "weather_code_synop_4677",
35
+ "reflectivity_32bit",
36
+ "mor_visibility",
37
+ "laser_amplitude",
38
+ "number_particles",
39
+ "sensor_temperature",
40
+ "sensor_heating_current",
41
+ "sensor_battery_voltage",
42
+ "sensor_status",
43
+ "rain_kinetic_energy",
44
+ "V_Batt_Min",
45
+ ]
46
+
47
+ ##------------------------------------------------------------------------.
48
+ #### Define reader options
49
+ reader_kwargs = {}
50
+ # - Define delimiter
51
+ reader_kwargs["delimiter"] = ","
52
+ # - Skip first row as columns names
53
+ reader_kwargs["header"] = None
54
+ # - Skip first 3 rows
55
+ reader_kwargs["skiprows"] = 4
56
+ # - Define encoding
57
+ reader_kwargs["encoding"] = "latin" # "ISO-8859-1"
58
+ # - Avoid first column to become df index !!!
59
+ reader_kwargs["index_col"] = False
60
+ # - Define behaviour when encountering bad lines
61
+ reader_kwargs["on_bad_lines"] = "skip"
62
+ # - Define reader engine
63
+ # - C engine is faster
64
+ # - Python engine is more feature-complete
65
+ reader_kwargs["engine"] = "python"
66
+ # - Define on-the-fly decompression of on-disk data
67
+ # - Available: gzip, bz2, zip
68
+ reader_kwargs["compression"] = "infer"
69
+ # - Strings to recognize as NA/NaN and replace with standard NA flags
70
+ # - Already included: '#N/A', '#N/A N/A', '#NA', '-1.#IND', '-1.#QNAN',
71
+ # '-NaN', '-nan', '1.#IND', '1.#QNAN', '<NA>', 'N/A',
72
+ # 'NA', 'NULL', 'NaN', 'n/a', 'nan', 'null'
73
+ reader_kwargs["na_values"] = ["na", "", "error"]
74
+
75
+ ##------------------------------------------------------------------------.
76
+ #### Read the data
77
+ df = read_raw_text_file(
78
+ filepath=filepath,
79
+ column_names=column_names,
80
+ reader_kwargs=reader_kwargs,
81
+ logger=logger,
82
+ )
83
+
84
+ ##------------------------------------------------------------------------.
85
+ #### Adapt the dataframe to adhere to DISDRODB L0 standards
86
+ # Define time
87
+ df["time"] = pd.to_datetime(df["time"], format="%Y-%m-%d %H:%M:%S", errors="coerce")
88
+
89
+ # Drop columns not agreeing with DISDRODB L0 standards
90
+ df = df.drop(columns=["RECORD", "V_Batt_Min"])
91
+ return df
92
+
93
+
94
+ def reader_spectrum(filepath, logger):
95
+ """Reader for Spectrum CR1000 Data Logger file."""
96
+ ##------------------------------------------------------------------------.
97
+ #### Define column names
98
+ column_names = ["TO_PARSE"]
99
+
100
+ ##------------------------------------------------------------------------.
101
+ #### Define reader options
102
+ reader_kwargs = {}
103
+ # - Define delimiter
104
+ reader_kwargs["delimiter"] = "\\n"
105
+ # - Skip first row as columns names
106
+ reader_kwargs["header"] = None
107
+ # - Skip first 3 rows
108
+ reader_kwargs["skiprows"] = 4
109
+ # - Define encoding
110
+ reader_kwargs["encoding"] = "latin" # "ISO-8859-1"
111
+ # - Avoid first column to become df index !!!
112
+ reader_kwargs["index_col"] = False
113
+ # - Define behaviour when encountering bad lines
114
+ reader_kwargs["on_bad_lines"] = "skip"
115
+ # - Define reader engine
116
+ # - C engine is faster
117
+ # - Python engine is more feature-complete
118
+ reader_kwargs["engine"] = "python"
119
+ # - Define on-the-fly decompression of on-disk data
120
+ # - Available: gzip, bz2, zip
121
+ reader_kwargs["compression"] = "infer"
122
+ # - Strings to recognize as NA/NaN and replace with standard NA flags
123
+ # - Already included: '#N/A', '#N/A N/A', '#NA', '-1.#IND', '-1.#QNAN',
124
+ # '-NaN', '-nan', '1.#IND', '1.#QNAN', '<NA>', 'N/A',
125
+ # 'NA', 'NULL', 'NaN', 'n/a', 'nan', 'null'
126
+ reader_kwargs["na_values"] = ["na", "", "error"]
127
+
128
+ ##------------------------------------------------------------------------.
129
+ #### Read the data
130
+ df = read_raw_text_file(
131
+ filepath=filepath,
132
+ column_names=column_names,
133
+ reader_kwargs=reader_kwargs,
134
+ logger=logger,
135
+ )
136
+
137
+ ##------------------------------------------------------------------------.
138
+ #### Adapt the dataframe to adhere to DISDRODB L0 standards
139
+ # Define time
140
+ df = df["TO_PARSE"].str.split(",", n=2, expand=True)
141
+ df.columns = ["time", "RECORD", "TO_PARSE"]
142
+
143
+ df["time"] = pd.to_datetime(df["time"].str.strip('"'), format="%Y-%m-%d %H:%M:%S", errors="coerce")
144
+
145
+ # Derive raw drop arrays
146
+ def split_string(s):
147
+ vals = [v.strip() for v in s.split(",")]
148
+ c1 = ",".join(vals[:32]) # -10
149
+ c1 = c1.replace("-10", "0")
150
+ c2 = "0,0," + ",".join(vals[32:62])
151
+ c3 = ",".join(vals[62:])
152
+ series = pd.Series(
153
+ {
154
+ "raw_drop_concentration": c1,
155
+ "raw_drop_average_velocity": c2,
156
+ "raw_drop_number": c3,
157
+ },
158
+ )
159
+ return series
160
+
161
+ splitted_string = df["TO_PARSE"].apply(split_string)
162
+ df["raw_drop_concentration"] = splitted_string["raw_drop_concentration"]
163
+ df["raw_drop_average_velocity"] = splitted_string["raw_drop_average_velocity"]
164
+ df["raw_drop_number"] = splitted_string["raw_drop_number"]
165
+
166
+ # Drop columns not agreeing with DISDRODB L0 standards
167
+ df = df.drop(columns=["TO_PARSE", "RECORD"])
168
+ return df
169
+
170
+
171
+ @is_documented_by(reader_generic_docstring)
172
+ def reader(
173
+ filepath,
174
+ logger=None,
175
+ ):
176
+ """Reader."""
177
+ # Retrieve Spectrum filepath
178
+ spectrum_filepath = filepath.replace("Parsivel", "Spectre")
179
+
180
+ # Read integral variables
181
+ df = reader_parsivel(filepath, logger=logger)
182
+
183
+ # Initialize empty arrays
184
+ # --> 0 values array produced in L0B
185
+ df["raw_drop_concentration"] = ""
186
+ df["raw_drop_average_velocity"] = ""
187
+ df["raw_drop_number"] = ""
188
+
189
+ # Read raw spectrum for corresponding timesteps
190
+ df_raw_spectrum = reader_spectrum(spectrum_filepath, logger=logger)
191
+
192
+ # Add raw array to df
193
+ df = df.set_index("time")
194
+ df_raw_spectrum = df_raw_spectrum.set_index("time")
195
+ df.update(df_raw_spectrum)
196
+
197
+ # Set back time as column
198
+ df = df.reset_index()
199
+
200
+ # Return the dataframe adhering to DISDRODB L0 standards
201
+ return df
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env python3
2
+ # -----------------------------------------------------------------------------.
3
+ # Copyright (c) 2021-2023 DISDRODB developers
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # -----------------------------------------------------------------------------.
18
+ import pandas as pd
19
+
20
+ from disdrodb.l0.l0_reader import is_documented_by, reader_generic_docstring
21
+ from disdrodb.l0.l0a_processing import read_raw_text_file
22
+
23
+
24
+ @is_documented_by(reader_generic_docstring)
25
+ def reader(
26
+ filepath,
27
+ logger=None,
28
+ ):
29
+ """Reader."""
30
+ ##------------------------------------------------------------------------.
31
+ #### Define column names
32
+ column_names = ["TO_PARSE"]
33
+
34
+ ##------------------------------------------------------------------------.
35
+ #### Define reader options
36
+ reader_kwargs = {}
37
+ # - Define delimiter
38
+ reader_kwargs["delimiter"] = "\\n"
39
+ # - Skip first row as columns names
40
+ # - Define encoding
41
+ reader_kwargs["encoding"] = "latin" # "ISO-8859-1"
42
+ # - Avoid first column to become df index !!!
43
+ reader_kwargs["index_col"] = False
44
+ # - Define behaviour when encountering bad lines
45
+ reader_kwargs["on_bad_lines"] = "skip"
46
+ # - Define reader engine
47
+ # - C engine is faster
48
+ # - Python engine is more feature-complete
49
+ reader_kwargs["engine"] = "python"
50
+ # - Define on-the-fly decompression of on-disk data
51
+ # - Available: gzip, bz2, zip
52
+ reader_kwargs["compression"] = "infer"
53
+ # - Strings to recognize as NA/NaN and replace with standard NA flags
54
+ # - Already included: '#N/A', '#N/A N/A', '#NA', '-1.#IND', '-1.#QNAN',
55
+ # '-NaN', '-nan', '1.#IND', '1.#QNAN', '<NA>', 'N/A',
56
+ # 'NA', 'NULL', 'NaN', 'n/a', 'nan', 'null'
57
+ reader_kwargs["na_values"] = ["na", "", "error"]
58
+
59
+ ##------------------------------------------------------------------------.
60
+ #### Read the data
61
+ df = read_raw_text_file(
62
+ filepath=filepath,
63
+ column_names=column_names,
64
+ reader_kwargs=reader_kwargs,
65
+ logger=logger,
66
+ )
67
+
68
+ ##------------------------------------------------------------------------.
69
+ #### Adapt the dataframe to adhere to DISDRODB L0 standards
70
+ # Define time
71
+ df = df["TO_PARSE"].str.split(",", n=2, expand=True)
72
+ df.columns = ["date", "time", "TO_PARSE"]
73
+ datetime_str = df["date"] + " " + df["time"]
74
+ df["time"] = pd.to_datetime(datetime_str, format="%d.%m.%Y %H:%M:%S", errors="coerce")
75
+
76
+ # Identify rows with integral variables
77
+ df_vars = df[df["TO_PARSE"].str.len() == 61]
78
+
79
+ # Split and assign column names
80
+ df_data = df_vars["TO_PARSE"].str.split(",", expand=True)
81
+ var_names = [
82
+ "rainfall_rate_32bit",
83
+ "rainfall_accumulated_32bit",
84
+ "weather_code_synop_4680",
85
+ "weather_code_synop_4677",
86
+ "reflectivity_32bit",
87
+ "mor_visibility",
88
+ "laser_amplitude",
89
+ "number_particles",
90
+ "sensor_temperature",
91
+ "sensor_heating_current",
92
+ "sensor_battery_voltage",
93
+ ]
94
+ df_data.columns = var_names
95
+ df_data["time"] = df_vars["time"]
96
+
97
+ # Initialize empty arrays
98
+ # --> 0 values array produced in L0B
99
+ df_data["raw_drop_concentration"] = ""
100
+ df_data["raw_drop_average_velocity"] = ""
101
+ df_data["raw_drop_number"] = ""
102
+
103
+ # Identify raw spectrum
104
+ df_raw_spectrum = df[df["TO_PARSE"].str.len() == 4545]
105
+
106
+ # Derive raw drop arrays
107
+ def split_string(s):
108
+ vals = [v.strip() for v in s.split(",")]
109
+ c1 = ",".join(vals[:32])
110
+ c2 = ",".join(vals[32:64])
111
+ c3 = ",".join(vals[64].replace("r", "").split("/"))
112
+ series = pd.Series(
113
+ {
114
+ "raw_drop_concentration": c1,
115
+ "raw_drop_average_velocity": c2,
116
+ "raw_drop_number": c3,
117
+ },
118
+ )
119
+ return series
120
+
121
+ splitted_string = df_raw_spectrum["TO_PARSE"].apply(split_string)
122
+ df_raw_spectrum["raw_drop_concentration"] = splitted_string["raw_drop_concentration"]
123
+ df_raw_spectrum["raw_drop_average_velocity"] = splitted_string["raw_drop_average_velocity"]
124
+ df_raw_spectrum["raw_drop_number"] = splitted_string["raw_drop_number"]
125
+ df_raw_spectrum = df_raw_spectrum.drop(columns=["date", "TO_PARSE"])
126
+
127
+ # Add raw array
128
+ df = df_data.set_index("time")
129
+ df_raw_spectrum = df_raw_spectrum.set_index("time")
130
+
131
+ df.update(df_raw_spectrum)
132
+
133
+ # Set back time as column
134
+ df = df.reset_index()
135
+
136
+ # Return the dataframe adhering to DISDRODB L0 standards
137
+ return df
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env python3
2
+ # -----------------------------------------------------------------------------.
3
+ # Copyright (c) 2021-2023 DISDRODB developers
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # -----------------------------------------------------------------------------.
18
+ import pandas as pd
19
+
20
+ from disdrodb.l0.l0_reader import is_documented_by, reader_generic_docstring
21
+ from disdrodb.l0.l0a_processing import read_raw_text_file
22
+
23
+
24
+ @is_documented_by(reader_generic_docstring)
25
+ def reader(
26
+ filepath,
27
+ logger=None,
28
+ ):
29
+ """Reader."""
30
+ ##------------------------------------------------------------------------.
31
+ #### Define column names
32
+ column_names = ["TO_PARSE"]
33
+
34
+ ##------------------------------------------------------------------------.
35
+ #### Define reader options
36
+ reader_kwargs = {}
37
+ # Skip first row as columns names
38
+ reader_kwargs["header"] = None
39
+ # Skip file with encoding errors
40
+ reader_kwargs["encoding_errors"] = "ignore"
41
+ # - Define delimiter
42
+ reader_kwargs["delimiter"] = "\\n"
43
+ # - Avoid first column to become df index !!!
44
+ reader_kwargs["index_col"] = False
45
+ # - Define behaviour when encountering bad lines
46
+ reader_kwargs["on_bad_lines"] = "skip"
47
+ # - Define reader engine
48
+ # - C engine is faster
49
+ # - Python engine is more feature-complete
50
+ reader_kwargs["engine"] = "python"
51
+ # - Define on-the-fly decompression of on-disk data
52
+ # - Available: gzip, bz2, zip
53
+ reader_kwargs["compression"] = "infer"
54
+ # - Strings to recognize as NA/NaN and replace with standard NA flags
55
+ # - Already included: '#N/A', '#N/A N/A', '#NA', '-1.#IND', '-1.#QNAN',
56
+ # '-NaN', '-nan', '1.#IND', '1.#QNAN', '<NA>', 'N/A',
57
+ # 'NA', 'NULL', 'NaN', 'n/a', 'nan', 'null'
58
+ reader_kwargs["na_values"] = ["na", "", "error", "NA", "-.-"]
59
+
60
+ ##------------------------------------------------------------------------.
61
+ #### Read the data
62
+ df = read_raw_text_file(
63
+ filepath=filepath,
64
+ column_names=column_names,
65
+ reader_kwargs=reader_kwargs,
66
+ logger=logger,
67
+ )
68
+
69
+ ##------------------------------------------------------------------------.
70
+ #### Adapt the dataframe to adhere to DISDRODB L0 standards
71
+ # Define 'time' datetime
72
+
73
+ # Split the columns
74
+ df["TO_PARSE"].iloc[0:5].str.split(";", n=16, expand=True).iloc[0]
75
+
76
+ df = df["TO_PARSE"].str.split(";", n=16, expand=True)
77
+
78
+ # Assign column names
79
+ names = [
80
+ "sensor_serial_number",
81
+ "sensor_status",
82
+ "laser_amplitude",
83
+ "sensor_heating_current",
84
+ "sensor_battery_voltage",
85
+ "dummy_date",
86
+ "sensor_time",
87
+ "sensor_date",
88
+ "sensor_temperature",
89
+ "number_particles",
90
+ "rainfall_rate_32bit",
91
+ "reflectivity_32bit",
92
+ "rainfall_accumulated_16bit",
93
+ "mor_visibility",
94
+ "weather_code_synop_4680",
95
+ "weather_code_synop_4677",
96
+ "TO_SPLIT",
97
+ ]
98
+ df.columns = names
99
+
100
+ # Derive raw drop arrays
101
+ def split_string(s):
102
+ vals = [v.strip() for v in s.split(";")]
103
+ c1 = ";".join(vals[:32])
104
+ c2 = ";".join(vals[32:64])
105
+ c3 = ";".join(vals[64:1088])
106
+ c4 = vals[1088]
107
+ c5 = vals[1089]
108
+ series = pd.Series(
109
+ {
110
+ "raw_drop_concentration": c1,
111
+ "raw_drop_average_velocity": c2,
112
+ "raw_drop_number": c3,
113
+ "rain_kinetic_energy": c4,
114
+ "CHECK_EMPTY": c5,
115
+ },
116
+ )
117
+ return series
118
+
119
+ splitted_string = df["TO_SPLIT"].apply(split_string)
120
+ df["raw_drop_concentration"] = splitted_string["raw_drop_concentration"]
121
+ df["raw_drop_average_velocity"] = splitted_string["raw_drop_average_velocity"]
122
+ df["raw_drop_number"] = splitted_string["raw_drop_number"]
123
+ df["rain_kinetic_energy"] = splitted_string["rain_kinetic_energy"]
124
+ df["CHECK_EMPTY"] = splitted_string["CHECK_EMPTY"]
125
+
126
+ # Ensure valid observation
127
+ df = df[df["CHECK_EMPTY"] == ""]
128
+
129
+ # Add the time column
130
+ time_str = df["sensor_date"] + "-" + df["sensor_time"]
131
+ df["time"] = pd.to_datetime(time_str, format="%d.%m.%Y-%H:%M:%S", errors="coerce")
132
+
133
+ # Drop columns not agreeing with DISDRODB L0 standards
134
+ columns_to_drop = [
135
+ "dummy_date",
136
+ "sensor_date",
137
+ "sensor_time",
138
+ "sensor_serial_number",
139
+ "rainfall_accumulated_16bit", # unexpected format
140
+ "CHECK_EMPTY",
141
+ "TO_SPLIT",
142
+ ]
143
+ df = df.drop(columns=columns_to_drop)
144
+
145
+ # Return the dataframe adhering to DISDRODB L0 standards
146
+ return df