Skip to content

Commit d4e66c7

Browse files
committed
Merge branch 'dev'
2 parents 8897d51 + 514065b commit d4e66c7

18 files changed

+781
-363
lines changed

src/pyrad_proc/pyrad/io/read_data_sensor.py

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,12 +2218,26 @@ def get_sensor_data(date, datatype, cfg):
22182218
22192219
"""
22202220
if cfg["sensor"] == "rgage":
2221-
datapath = cfg["smnpath"] + date.strftime("%Y%m") + "/"
2222-
datafile = date.strftime("%Y%m%d") + "_" + cfg["sensorid"] + ".csv"
2221+
# Try several file formats
2222+
datapath1 = os.path.join(cfg["smnpath"], date.strftime("%Y%m"))
2223+
datapath2 = os.path.join(cfg["smnpath"], date.strftime("%Y-%m-%d"),
2224+
cfg["sensorid"])
2225+
datafile1 = os.path.join(datapath1, date.strftime("%Y%m%d")
2226+
+ "_" + cfg["sensorid"] + ".csv*")
2227+
datafile2 = os.path.join(datapath2, date.strftime("%Y%m%d")
2228+
+ "_" + cfg["sensorid"] + ".csv*")
2229+
2230+
files1 = glob.glob(datafile1)
2231+
files2 = glob.glob(datafile2)
2232+
if len(files1):
2233+
datafile = files1[0]
2234+
if len(files2):
2235+
datafile = files2[0]
2236+
22232237
try:
2224-
_, sensordate, _, _, _, sensorvalue, _, _ = read_smn(datapath + datafile)
2238+
_, sensordate, _, _, _, sensorvalue, _, _ = read_smn(datafile)
22252239
except Exception:
2226-
_, sensordate, sensorvalue = read_smn2(datapath + datafile)
2240+
_, sensordate, sensorvalue = read_smn2(datafile)
22272241
if sensordate is None:
22282242
return None, None, None, None
22292243
label = "RG"
@@ -2317,10 +2331,9 @@ def get_sensor_data(date, datatype, cfg):
23172331

23182332
return sensordate, sensorvalue, label, period
23192333

2320-
23212334
def read_smn(fname):
23222335
"""
2323-
Reads SwissMetNet data contained in a csv file
2336+
Reads SwissMetNet data contained in a csv or gzipped csv file.
23242337
23252338
Parameters
23262339
----------
@@ -2329,54 +2342,45 @@ def read_smn(fname):
23292342
23302343
Returns
23312344
-------
2332-
smn_id, date , pressure, temp, rh, precip, wspeed, wdir : tupple
2345+
smn_id, date, pressure, temp, rh, precip, wspeed, wdir : tuple
23332346
The read values
2334-
23352347
"""
23362348
fill_value = 10000000.0
2337-
try:
2338-
with open(fname, "r", newline="") as csvfile:
2339-
# first count the lines
2340-
reader = csv.DictReader(csvfile)
2341-
nrows = sum(1 for row in reader)
2342-
smn_id = np.ma.empty(nrows, dtype="float32")
2343-
pressure = np.ma.empty(nrows, dtype="float32")
2344-
temp = np.ma.empty(nrows, dtype="float32")
2345-
rh = np.ma.empty(nrows, dtype="float32")
2346-
precip = np.ma.empty(nrows, dtype="float32")
2347-
wspeed = np.ma.empty(nrows, dtype="float32")
2348-
wdir = np.ma.empty(nrows, dtype="float32")
23492349

2350-
# now read the data
2351-
csvfile.seek(0)
2352-
reader = csv.DictReader(csvfile)
2353-
date = []
2354-
for i, row in enumerate(reader):
2355-
smn_id[i] = float(row["StationID"])
2356-
date.append(datetime.datetime.strptime(row["DateTime"], "%Y%m%d%H%M%S"))
2357-
pressure[i] = float(row["AirPressure"])
2358-
temp[i] = float(row["2mTemperature"])
2359-
rh[i] = float(row["RH"])
2360-
precip[i] = float(row["Precipitation"])
2361-
wspeed[i] = float(row["Windspeed"])
2362-
wdir[i] = float(row["Winddirection"])
2363-
2364-
pressure = np.ma.masked_values(pressure, fill_value)
2365-
temp = np.ma.masked_values(temp, fill_value)
2366-
rh = np.ma.masked_values(rh, fill_value)
2367-
precip = np.ma.masked_values(precip, fill_value)
2368-
wspeed = np.ma.masked_values(wspeed, fill_value)
2369-
wdir = np.ma.masked_values(wdir, fill_value)
2370-
2371-
# convert precip from mm/10min to mm/h
2372-
precip *= 6.0
2373-
2374-
csvfile.close()
2375-
2376-
return smn_id, date, pressure, temp, rh, precip, wspeed, wdir
2377-
except EnvironmentError as ee:
2378-
warn(str(ee))
2379-
warn("Unable to read file " + fname)
2350+
try:
2351+
# Use pandas to read the file (supports .gz files directly)
2352+
df = pd.read_csv(fname, compression='gzip' if fname.endswith('.gz') else None)
2353+
2354+
# Convert date strings to datetime objects
2355+
df['DateTime'] = pd.to_datetime(df['DateTime'], format='%Y%m%d%H%M%S')
2356+
2357+
# Identify columns by searching for keywords (handles cases like AirPressure:degC)
2358+
air_pressure_col = [col for col in df.columns if 'AirPressure' in col][0]
2359+
temp_col = [col for col in df.columns if '2mTemperature' in col][0]
2360+
rh_col = [col for col in df.columns if 'RH' in col][0]
2361+
precip_col = [col for col in df.columns if 'Precipitation' in col][0]
2362+
wspeed_col = [col for col in df.columns if 'Windspeed' in col][0]
2363+
wdir_col = [col for col in df.columns if 'Winddirection' in col][0]
2364+
2365+
# Mask invalid data (fill_value)
2366+
pressure = np.ma.masked_values(df[air_pressure_col].astype('float32'), fill_value)
2367+
temp = np.ma.masked_values(df[temp_col].astype('float32'), fill_value)
2368+
rh = np.ma.masked_values(df[rh_col].astype('float32'), fill_value)
2369+
precip = np.ma.masked_values(df[precip_col].astype('float32'), fill_value)
2370+
wspeed = np.ma.masked_values(df[wspeed_col].astype('float32'), fill_value)
2371+
wdir = np.ma.masked_values(df[wdir_col].astype('float32'), fill_value)
2372+
2373+
# Convert precip from mm/10min to mm/h
2374+
precip *= 6.0
2375+
2376+
# Extract smn_id and date
2377+
smn_id = df['StationID'].astype('float32').values
2378+
date = df['DateTime'].tolist()
2379+
2380+
return smn_id, date, pressure, temp, rh, precip, wspeed, wdir
2381+
2382+
except Exception as e:
2383+
warn(f"Unable to read file {fname}: {e}")
23802384
return None, None, None, None, None, None, None, None
23812385

23822386

src/pyrad_proc/pyrad/proc/process_Doppler.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def process_turbulence(procstatus, dscfg, radar_list=None):
6565
data set configuration. Accepted Configuration Keywords::
6666
6767
datatype : string. Dataset keyword
68-
The input data type
68+
The input data type, must contain,
69+
"dBuZ" or "dBZ" or "dBZc" or "dBuZv" or "dBZv" or "dBZvc" or "CNRc", and,
70+
"W" or "Wv" or "Wu" or "Wvu" or "WD" or "WDc"
6971
radius : float. Dataset keyword
7072
Search radius for calculating Eddy Dissipation Rate (EDR).
7173
Default 2
@@ -97,7 +99,7 @@ def process_turbulence(procstatus, dscfg, radar_list=None):
9799
Returns
98100
-------
99101
new_dataset : dict
100-
dictionary containing the output
102+
dictionary containing the output field "EDR"
101103
ind_rad : int
102104
radar index
103105
@@ -235,7 +237,8 @@ def process_dealias_fourdd(procstatus, dscfg, radar_list=None):
235237
data set configuration. Accepted Configuration Keywords::
236238
237239
datatype : string. Dataset keyword
238-
The input data type
240+
The input data type, must contain
241+
"V" or "Vc"
239242
filt : int. Dataset keyword
240243
Flag controlling Bergen and Albers filter, 1 = yes, 0 = no.
241244
sign : int. Dataset keyword
@@ -252,7 +255,7 @@ def process_dealias_fourdd(procstatus, dscfg, radar_list=None):
252255
Returns
253256
-------
254257
new_dataset : dict
255-
dictionary containing the output
258+
dictionary containing the output field "dealV" or "dealVc" (if Vc was provided)
256259
ind_rad : int
257260
radar index
258261
@@ -357,7 +360,8 @@ def process_dealias_region_based(procstatus, dscfg, radar_list=None):
357360
data set configuration. Accepted Configuration Keywords::
358361
359362
datatype : string. Dataset keyword
360-
The input data type
363+
The input data type, must contain,
364+
"V" or "Vc"
361365
interval_splits : int, optional
362366
Number of segments to split the nyquist interval into when finding
363367
regions of similar velocity. More splits creates a larger number
@@ -387,7 +391,7 @@ def process_dealias_region_based(procstatus, dscfg, radar_list=None):
387391
Returns
388392
-------
389393
new_dataset : dict
390-
dictionary containing the output
394+
dictionary containing the output field "dealV" or "dealVc" (if Vc was provided)
391395
ind_rad : int
392396
radar index
393397
@@ -458,7 +462,8 @@ def process_dealias_unwrap_phase(procstatus, dscfg, radar_list=None):
458462
data set configuration. Accepted Configuration Keywords::
459463
460464
datatype : string. Dataset keyword
461-
The input data type
465+
The input data type, must contain,
466+
"V" or "Vc"
462467
unwrap_unit : {'ray', 'sweep', 'volume'}, optional
463468
Unit to unwrap independently. 'ray' will unwrap each ray
464469
individually, 'sweep' each sweep, and 'volume' will unwrap the
@@ -473,7 +478,7 @@ def process_dealias_unwrap_phase(procstatus, dscfg, radar_list=None):
473478
Returns
474479
-------
475480
new_dataset : dict
476-
dictionary containing the output
481+
dictionary containing the output field "dealV" or "dealVc" (if Vc was provided)
477482
ind_rad : int
478483
radar index
479484
@@ -534,7 +539,10 @@ def process_radial_velocity(procstatus, dscfg, radar_list=None):
534539
data set configuration. Accepted Configuration Keywords::
535540
536541
datatype : string. Dataset keyword
537-
The input data type
542+
The input data type, must contain
543+
WIND_SPEED, and,
544+
WIND_DIRECTION, and,
545+
wind_vel_v
538546
latitude, longitude : float
539547
arbitrary coordinates [deg] from where to compute the radial
540548
velocity. If any of them is None it will be the radar position
@@ -547,7 +555,7 @@ def process_radial_velocity(procstatus, dscfg, radar_list=None):
547555
Returns
548556
-------
549557
new_dataset : dict
550-
dictionary containing the output
558+
dictionary containing the output field "V"
551559
ind_rad : int
552560
radar index
553561
@@ -665,7 +673,8 @@ def process_wind_vel(procstatus, dscfg, radar_list=None):
665673
data set configuration. Accepted Configuration Keywords::
666674
667675
datatype : string. Dataset keyword
668-
The input data type
676+
The input data type, must contain
677+
"V" or "Vc"
669678
vert_proj : Boolean
670679
If true the vertical projection is computed. Otherwise the
671680
horizontal projection is computed
@@ -675,7 +684,9 @@ def process_wind_vel(procstatus, dscfg, radar_list=None):
675684
Returns
676685
-------
677686
new_dataset : dict
678-
dictionary containing the output
687+
dictionary containing the output field
688+
"wind_vel_h_az", (if vert_proj is False), or,
689+
"wind_vel_v" (if vert_proj is True)
679690
ind_rad : int
680691
radar index
681692
@@ -737,7 +748,7 @@ def process_windshear(procstatus, dscfg, radar_list=None):
737748
Returns
738749
-------
739750
new_dataset : dict
740-
dictionary containing the output
751+
dictionary containing the output field "windshear_v"
741752
ind_rad : int
742753
radar index
743754
@@ -786,7 +797,8 @@ def process_windshear_lidar(procstatus, dscfg, radar_list=None):
786797
data set configuration. Accepted Configuration Keywords::
787798
788799
datatype : string. Dataset keyword
789-
The input data type
800+
The input data type, must contain
801+
"V" or "Vc"
790802
az_tol : float
791803
The tolerance in azimuth when looking for gates on top
792804
of the gate when computation is performed
@@ -797,7 +809,7 @@ def process_windshear_lidar(procstatus, dscfg, radar_list=None):
797809
Returns
798810
-------
799811
new_dataset : dict
800-
dictionary containing the output
812+
dictionary containing the output field "windshear_v"
801813
ind_rad : int
802814
radar index
803815
@@ -847,14 +859,17 @@ def process_vad(procstatus, dscfg, radar_list=None):
847859
data set configuration. Accepted Configuration Keywords::
848860
849861
datatype : string. Dataset keyword
850-
The input data type
862+
The input data type, must contain
863+
"V" or "Vc"
851864
radar_list : list of Radar objects
852865
Optional. list of radar objects
853866
854867
Returns
855868
-------
856869
new_dataset : dict
857-
dictionary containing the output
870+
dictionary containing the output fields
871+
"wind_vel_h_u", "wind_vel_h_v", "wind_vel_v",
872+
"estV", "stdV", and "diffV"
858873
ind_rad : int
859874
radar index
860875
@@ -923,7 +938,9 @@ def process_dda(procstatus, dscfg, radar_list=None):
923938
data set configuration. Accepted Configuration Keywords::
924939
925940
datatype : string. Dataset keyword
926-
The input data type
941+
The input data type, must contain
942+
"V" or "Vc", and,
943+
"dBuZ", "dBZ", or "dBZc"
927944
928945
gridconfig : dictionary. Dataset keyword
929946
Dictionary containing some or all of this keywords:
@@ -997,7 +1014,8 @@ def process_dda(procstatus, dscfg, radar_list=None):
9971014
Returns
9981015
-------
9991016
new_dataset : dict
1000-
dictionary containing the output
1017+
dictionary containing the output fields
1018+
"wind_vel_h_u", "wind_vel_h_v" and "wind_vel_v"
10011019
ind_rad : int
10021020
radar index
10031021

0 commit comments

Comments
 (0)