Reference
crnpy
is a Python package for processing cosmic ray neutron data.
Created by Joaquin Peraza and Andres Patrignani.
abs_humidity(relative_humidity, temp)
Compute the actual vapor pressure (e) in g m^-3 using RH (%) and current temperature (c) observations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relative_humidity |
float
|
relative humidity (%) |
required |
temp |
float
|
temperature (Celsius) |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
actual vapor pressure (g m^-3) |
Source code in crnpy/crnpy.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
atmospheric_depth(elevation, latitude)
Function to estimate the atmospheric depth for any point on Earth according to McJannet and Desilets, 2023
This function is required in the calculation of the location-dependent reference correction proposed by McJannet and Desilets, 2023.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elevation |
float
|
Elevation in meters above sea level. |
required |
latitude |
float
|
Geographic latitude in decimal degrees. Value in range -90 to 90 |
required |
Returns:
Type | Description |
---|---|
float
|
Atmospheric depth in g/cm2 |
References
Atmosphere, U. S. (1976). US standard atmosphere. National Oceanic and Atmospheric Administration.
McJannet, D. L., & Desilets, D. (2023). Incoming Neutron Flux Corrections for Cosmic‐Ray Soil and Snow Sensors Using the Global Neutron Monitor Network. Water Resources Research, 59(4), e2022WR033889.
Source code in crnpy/crnpy.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 |
|
biomass_to_bwe(biomass_dry, biomass_fresh, fWE=0.494)
Function to convert biomass to biomass water equivalent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
biomass_dry |
array or Series or DataFrame
|
Above ground dry biomass in kg m-2. |
required |
biomass_fresh |
array or Series or DataFrame
|
Above ground fresh biomass in kg m-2. |
required |
fWE |
float
|
Stoichiometric ratio of H2O to organic carbon molecules in the plant (assuming this is mostly cellulose) Default is 0.494 (Wahbi & Avery, 2018). |
0.494
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Biomass water equivalent in kg m-2. |
References
Wahbi, A., Avery, W. (2018). In Situ Destructive Sampling. In: Cosmic Ray Neutron Sensing: Estimation of Agricultural Crop Biomass Water Equivalent. Springer, Cham. https://doi.org/10.1007/978-3-319-69539-6_2
Source code in crnpy/crnpy.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
correction_bwe(counts, bwe, r2_N0=0.05)
Function to correct for biomass effects in neutron counts. following the approach described in Baatz et al., 2015.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
array or Series or DataFrame
|
Array of ephithermal neutron counts. |
required |
bwe |
float
|
Biomass water equivalent kg m-2. |
required |
r2_N0 |
float
|
Ratio of neutron counts with biomass to neutron counts without biomass. Default is 0.05. |
0.05
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Array of corrected neutron counts for biomass effects. |
References
Baatz, R., H. R. Bogena, H.-J. Hendricks Franssen, J. A. Huisman, C. Montzka, and H. Vereecken (2015), An empiricalvegetation correction for soil water content quantification using cosmic ray probes, Water Resour. Res., 51, 2030–2046, doi:10.1002/ 2014WR016443.
Source code in crnpy/crnpy.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
correction_humidity(abs_humidity, Aref)
Correction factor for absolute humidity.
This function corrects neutron counts for absolute humidity using the method described in Rosolem et al. (2013) and Anderson et al. (2017). The correction is performed using the following equation:
$$ C_{corrected} = C_{raw} \cdot f_w $$
where:
- Ccorrected: corrected neutron counts
- Craw: raw neutron counts
- fw: absolute humidity correction factor
$$ f_w = 1 + 0.0054(A - A_{ref}) $$
where:
- A: absolute humidity
- Aref: reference absolute humidity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
abs_humidity |
list or array
|
Relative humidity readings. |
required |
Aref |
float
|
Reference absolute humidity (g/m^3). The day of the instrument calibration is recommended. |
required |
Returns:
Type | Description |
---|---|
list
|
fw correction factor. |
References
Rosolem, R., W. J. Shuttleworth, M. Zreda, T. E. Franz, X. Zeng, and S. A. Kurc, 2013: The Effect of Atmospheric Water Vapor on Neutron Count in the Cosmic-Ray Soil Moisture Observing System. J. Hydrometeor., 14, 1659–1671, https://doi.org/10.1175/JHM-D-12-0120.1.
M. Andreasen, K.H. Jensen, D. Desilets, T.E. Franz, M. Zreda, H.R. Bogena, and M.C. Looms. 2017. Status and perspectives on the cosmic-ray neutron method for soil moisture estimation and other environmental science applications. Vadose Zone J. 16(8). doi:10.2136/vzj2017.04.0086
Source code in crnpy/crnpy.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
correction_incoming_flux(incoming_neutrons, incoming_Ref=None, fill_na=None, Rc_method=None, Rc_site=None, site_atmdepth=None, Rc_ref=None, ref_atmdepth=None)
Correction factor for incoming neutron flux.
This function corrects neutron counts for incoming neutron flux using the method described in Anderson et al. (2017). The correction is performed using the following equation:
$$ C_{corrected} = \frac{C_{raw}}{f_i} $$
where:
- Ccorrected: corrected neutron counts
- Craw: raw neutron counts
- fi: incoming neutron flux correction factor
$$ f_i = \frac{I}{I_{ref}} $$
where:
- I: incoming neutron flux
- Iref: reference incoming neutron flux
Parameters:
Name | Type | Description | Default |
---|---|---|---|
incoming_neutrons |
list or array
|
Incoming neutron flux readings. |
required |
incoming_Ref |
float
|
Reference incoming neutron flux. Baseline incoming neutron flux. |
None
|
fill_na |
float
|
Value to fill missing data. If None, missing data remains as NaN. |
None
|
Rc_method |
str
|
Optional to correct for differences in cutoff rigidity between the site and the reference station. Possible values are 'McJannetandDesilets2023' or 'Hawdonetal2014'. If None, no correction is performed. |
None
|
Rc_site |
float
|
Cutoff rigidity at the monitoring site. |
None
|
site_atmdepth |
float
|
Atmospheric depth at the monitoring site. |
None
|
Rc_ref |
float
|
Cutoff rigidity at the reference station. |
None
|
ref_atmdepth |
float
|
Atmospheric depth at the reference station. |
None
|
Returns:
Type | Description |
---|---|
list
|
fi correction factor. |
References
Hawdon, A., D. McJannet, and J. Wallace (2014), Calibration and correction procedures for cosmic-ray neutron soil moisture probes located across Australia, Water Resour. Res., 50, 5029–5043, doi:10.1002/2013WR015138.
M. Andreasen, K.H. Jensen, D. Desilets, T.E. Franz, M. Zreda, H.R. Bogena, and M.C. Looms. 2017. Status and perspectives on the cosmic-ray neutron method for soil moisture estimation and other environmental science applications. Vadose Zone J. 16(8). doi:10.2136/vzj2017.04.0086
McJannet, D. L., & Desilets, D. (2023). Incoming neutron flux corrections for cosmic-ray soil and snow sensors using the global neutron monitor network. Water Resources Research, 59, e2022WR033889. https://doi.org/10.1029/2022WR033889
Source code in crnpy/crnpy.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
correction_pressure(pressure, Pref, L)
Correction factor for atmospheric pressure.
This function corrects neutron counts for atmospheric pressure using the method described in Andreasen et al. (2017). The correction is performed using the following equation:
$$ C_{corrected} = \frac{C_{raw}}{fp} $$
where:
- Ccorrected: corrected neutron counts
- Craw: raw neutron counts
- fp: pressure correction factor
$$ fp = e^{\frac{P_{ref} - P}{L}} $$
where:
- P: atmospheric pressure
- Pref: reference atmospheric pressure
- L: Atmospheric attenuation coefficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pressure |
list or array
|
Atmospheric pressure readings. Long-term average pressure is recommended. |
required |
Pref |
float
|
Reference atmospheric pressure. |
required |
L |
float
|
Atmospheric attenuation coefficient. |
required |
Returns:
Type | Description |
---|---|
list
|
fp pressure correction factor. |
References
Zreda, M., Shuttleworth, W. J., Zeng, X., Zweck, C., Desilets, D., Franz, T., and Rosolem, R.: COSMOS: the COsmic-ray Soil Moisture Observing System, Hydrol. Earth Syst. Sci., 16, 4079–4099, https://doi.org/10.5194/hess-16-4079-2012, 2012.
M. Andreasen, K.H. Jensen, D. Desilets, T.E. Franz, M. Zreda, H.R. Bogena, and M.C. Looms. 2017. Status and perspectives on the cosmic-ray neutron method for soil moisture estimation and other environmental science applications. Vadose Zone J. 16(8). doi:10.2136/vzj2017.04.0086
Source code in crnpy/crnpy.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
correction_road(counts, theta_N, road_width, road_distance=0.0, theta_road=0.12, p0=0.42, p1=0.5, p2=1.06, p3=4, p4=0.16, p6=0.94, p7=1.1, p8=2.7, p9=0.01)
Function to correct for road effects in neutron counts. following the approach described in Schrön et al., 2018.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
array or Series or DataFrame
|
Array of ephithermal neutron counts. |
required |
theta_N |
float
|
Volumetric water content of the soil estimated from the uncorrected neutron counts. |
required |
road_width |
float
|
Width of the road in m. |
required |
road_distance |
float
|
Distance of the road from the sensor in m. Default is 0.0. |
0.0
|
theta_road |
float
|
Volumetric water content of the road. Default is 0.12. |
0.12
|
p0-p9 |
float
|
Parameters of the correction function. Default values are from Schrön et al., 2018. |
required |
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Array of corrected neutron counts for road effects. |
References
Schrön,M.,Rosolem,R.,Köhli,M., Piussi,L.,Schröter,I.,Iwema,J.,etal. (2018).Cosmic-ray neutron rover surveys of field soil moisture and the influence of roads.WaterResources Research,54,6441–6459. https://doi. org/10.1029/2017WR021719
Source code in crnpy/crnpy.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
counts_to_vwc(counts, N0, Wlat, Wsoc, bulk_density, a0=0.0808, a1=0.372, a2=0.115)
Function to convert corrected and filtered neutron counts into volumetric water content.
This method implements soil moisture estimation using the non-linear relationship between neutron count and soil volumetric water content following the approach described in Desilets et al., 2010.
$\theta(N) =\frac{a_0}{(\frac{N}{N_0}) - a_1} - a_2 $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
array or Series or DataFrame
|
Array of corrected and filtered neutron counts. |
required |
N0 |
float
|
Device-specific neutron calibration constant. |
required |
Wlat |
float
|
Lattice water content. |
required |
Wsoc |
float
|
Soil organic carbon content. |
required |
bulk_density |
float
|
Soil bulk density. |
required |
a0 |
float
|
Parameter given in Zreda et al., 2012. Default is 0.0808. |
0.0808
|
a1 |
float
|
Parameter given in Zreda et al., 2012. Default is 0.372. |
0.372
|
a2 |
float
|
Parameter given in Zreda et al., 2012. Default is 0.115. |
0.115
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Volumetric water content in m3 m-3. |
References
Desilets, D., M. Zreda, and T.P.A. Ferré. 2010. Nature’s neutron probe: Land surface hydrology at an elusive scale with cosmic rays. Water Resour. Res. 46:W11505. doi.org/10.1029/2009WR008726
Source code in crnpy/crnpy.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
cutoff_rigidity(lat, lon)
Function to estimate the approximate cutoff rigidity for any point on Earth according to the tabulated data of Smart and Shea, 2019. The returned value can be used to select the appropriate neutron monitor station to estimate the cosmic-ray neutron intensity at the location of interest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat |
float
|
Geographic latitude in decimal degrees. Value in range -90 to 90 |
required |
lon |
float
|
Geographic longitude in decimal degrees. Values in range from 0 to 360. Typical negative longitudes in the west hemisphere will fall in the range 180 to 360. |
required |
Returns:
Type | Description |
---|---|
float
|
Cutoff rigidity in GV. Error is about +/- 0.3 GV |
Examples:
Estimate the cutoff rigidity for Newark, NJ, US
>>> zq = cutoff_rigidity(39.68, -75.75)
>>> print(zq)
2.52 GV (Value from NMD is 2.40 GV)
References
Hawdon, A., McJannet, D., & Wallace, J. (2014). Calibration and correction procedures for cosmic‐ray neutron soil moisture probes located across Australia. Water Resources Research, 50(6), 5029-5043.
Smart, D. & Shea, Matthew. (2001). Geomagnetic Cutoff Rigidity Computer Program: Theory, Software Description and Example. NASA STI/Recon Technical Report N.
Shea, M. A., & Smart, D. F. (2019, July). Re-examination of the First Five Ground-Level Events. In International Cosmic Ray Conference (ICRC2019) (Vol. 36, p. 1149).
Source code in crnpy/crnpy.py
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
|
euclidean_distance(px, py, x, y)
Function that computes the Euclidean distance between one point in space and one or more points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px |
float
|
x projected coordinate of the point. |
required |
py |
float
|
y projected coordinate of the point. |
required |
x |
(list, ndarray, series)
|
vector of x projected coordinates. |
required |
y |
(list, ndarray, series)
|
vector of y projected coordinates. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Numpy array of distances from the point (px,py) to all the points in x and y vectors. |
Source code in crnpy/crnpy.py
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 |
|
exp_filter(sm, T=1)
Exponential filter to estimate soil moisture in the rootzone from surface observtions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
list or array
|
Soil moisture in mm of water for the top layer of the soil profile. |
required |
T |
float
|
Characteristic time length in the same units as the measurement interval. |
1
|
Returns:
Name | Type | Description |
---|---|---|
sm_subsurface |
list or array
|
Subsurface soil moisture in the same units as the input. |
References
Albergel, C., Rüdiger, C., Pellarin, T., Calvet, J.C., Fritz, N., Froissard, F., Suquia, D., Petitpa, A., Piguet, B. and Martin, E., 2008. From near-surface to root-zone soil moisture using an exponential filter: an assessment of the method based on in-situ observations and model simulations. Hydrology and Earth System Sciences, 12(6), pp.1323-1337.
Franz, T.E., Wahbi, A., Zhang, J., Vreugdenhil, M., Heng, L., Dercon, G., Strauss, P., Brocca, L. and Wagner, W., 2020. Practical data products from cosmic-ray neutron sensing for hydrological applications. Frontiers in Water, 2, p.9.
Rossini, P. and Patrignani, A., 2021. Predicting rootzone soil moisture from surface observations in cropland using an exponential filter. Soil Science Society of America Journal.
Source code in crnpy/crnpy.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 |
|
fill_missing_timestamps(df, timestamp_col='timestamp', freq='H', round_timestamp=True, verbose=False)
Helper function to fill rows with missing timestamps in datetime record. Rows are filled with NaN values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas DataFrame. |
required |
timestamp_col |
str
|
Column with the timestamp. Must be in datetime format. Default column name is 'timestamp'. |
'timestamp'
|
freq |
str
|
Timestamp frequency. 'H' for hourly, 'M' for minute, or None. Can also use '3H' for a 3 hour frequency. Default is 'H'. |
'H'
|
round_timestamp |
bool
|
Whether to round timestamps to the nearest frequency. Default is True. |
True
|
verbose |
bool
|
Prints the missing timestamps added to the DatFrame. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with filled missing timestamps. |
Source code in crnpy/crnpy.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
find_neutron_monitor(Rc, start_date=None, end_date=None, verbose=False)
Search for potential reference neutron monitoring stations based on cutoff rigidity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Rc |
float
|
Cutoff rigidity in GV. Values in range 1.0 to 3.0 GV. |
required |
start_date |
datetime
|
Start date for the period of interest. |
None
|
end_date |
datetime
|
End date for the period of interest. |
None
|
verbose |
bool
|
If True, print a expanded output of the incoming neutron flux data. |
False
|
Returns:
Type | Description |
---|---|
list
|
List of top five stations with closes cutoff rigidity. User needs to select station according to site altitude. |
Examples:
>>> from crnpy import crnpy
>>> Rc = 2.40 # 2.40 Newark, NJ, US
>>> crnpy.find_neutron_monitor(Rc)
Select a station with an altitude similar to that of your location. For more information go to: 'https://www.nmdb.eu/nest/help.php#helpstations
Your cutoff rigidity is 2.4 GV STID NAME R Altitude_m 40 NEWK Newark 2.40 50 33 MOSC Moscow 2.43 200 27 KIEL Kiel 2.36 54 28 KIEL2 KielRT 2.36 54 31 MCRL Mobile Cosmic Ray Laboratory 2.46 200 32 MGDN Magadan 2.10 220 42 NVBK Novosibirsk 2.91 163 26 KGSN Kingston 1.88 65 9 CLMX Climax 3.00 3400 57 YKTK Yakutsk 1.65 105
References
https://www.nmdb.eu/nest/help.php#helpstations
Source code in crnpy/crnpy.py
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
|
get_incoming_neutron_flux(start_date, end_date, station, utc_offset=0, expand_window=0, verbose=False)
Function to retrieve neutron flux from the Neutron Monitor Database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_date |
datetime
|
Start date of the time series. |
required |
end_date |
datetime
|
End date of the time series. |
required |
station |
str
|
Neutron Monitor station to retrieve data from. |
required |
utc_offset |
int
|
UTC offset in hours. Default is 0. |
0
|
expand_window |
int
|
Number of hours to expand the time window to retrieve extra data. Default is 0. |
0
|
verbose |
bool
|
Print information about the request. Default is False. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
Neutron flux in counts per hour and timestamps. |
References
Documentation available:https://www.nmdb.eu/nest/help.php#howto
Source code in crnpy/crnpy.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
|
get_reference_neutron_flux(station, date=pd.to_datetime('2011-05-01'))
Function to retrieve reference neutron flux from the Neutron Monitor Database. Default date is 2011-05-01, following previous studies (Zreda et a., 2012, Hawdon et al., 2014, Bogena et al., 2022).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Neutron Monitor station to retrieve data from. |
required |
date |
datetime
|
Date of the reference neutron flux. Default is 2011-05-01. |
to_datetime('2011-05-01')
|
Returns:
Type | Description |
---|---|
float
|
Reference neutron flux in counts per hour. |
References
Zreda, M., Shuttleworth, W. J., Zeng, X., Zweck, C., Desilets, D., Franz, T., & Rosolem, R. (2012). COSMOS: The cosmic-ray soil moisture observing system. Hydrology and Earth System Sciences, 16(11), 4079-4099.
Hawdon, A., McJannet, D., & Wallace, J. (2014). Calibration and correction procedures for cosmic‐ray neutron soil moisture probes located across Australia. Water Resources Research, 50(6), 5029-5043.
Bogena, H. R., Schrön, M., Jakobi, J., Ney, P., Zacharias, S., Andreasen, M., ... & Vereecken, H. (2022). COSMOS-Europe: a European network of cosmic-ray neutron soil moisture sensors. Earth System Science Data, 14(3), 1125-1151.
Source code in crnpy/crnpy.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
idw(x, y, z, X_pred, Y_pred, neighborhood=1000, p=1)
Function to interpolate data using inverse distance weight.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
list or array
|
UTM x coordinates in meters. |
required |
y |
list or array
|
UTM y coordinates in meters. |
required |
z |
list or array
|
Values to be interpolated. |
required |
X_pred |
list or array
|
UTM x coordinates where z values need to be predicted. |
required |
Y_pred |
list or array
|
UTM y coordinates where z values need to be predicted. |
required |
neighborhood |
float
|
Only points within this radius in meters are considered for the interpolation. |
1000
|
p |
int
|
Exponent of the inverse distance weight formula. Typically, p=1 or p=2. |
1
|
Returns:
Type | Description |
---|---|
array
|
Interpolated values. |
Source code in crnpy/crnpy.py
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 |
|
interpolate_2d(x, y, z, dx=100, dy=100, method='cubic', neighborhood=1000)
Function for interpolating irregular spatial data into a regular grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
list or array
|
UTM x coordinates in meters. |
required |
y |
list or array
|
UTM y coordinates in meters. |
required |
z |
list or array
|
Values to be interpolated. |
required |
dx |
float
|
Pixel width in meters. |
100
|
dy |
float
|
Pixel height in meters. |
100
|
method |
str
|
Interpolation method. One of 'cubic', 'linear', 'nearest', or 'idw'. |
'cubic'
|
neighborhood |
float
|
Only points within this radius in meters are considered for the interpolation. |
1000
|
Returns:
Name | Type | Description |
---|---|---|
x_pred |
array
|
2D array with x coordinates. |
y_pred |
array
|
2D array with y coordinates. |
z_pred |
array
|
2D array with interpolated values. |
Source code in crnpy/crnpy.py
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
|
interpolate_incoming_flux(nmdb_timestamps, nmdb_counts, crnp_timestamps)
Function to interpolate incoming neutron flux to match the timestamps of the observations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nmdb_timestamps |
Series or array
|
Series or array of timestamps in datetime format from the NMDB |
required |
nmdb_counts |
Series or array
|
Series or array of incoming neutron flux counts from the NMDB |
required |
crnp_timestamps |
Series or array
|
Series or array of timestamps in datetime format from the CRNP device |
required |
Returns:
Type | Description |
---|---|
Series
|
Series containing interpolated incoming neutron flux. Length of Series is the same as crnp_timestamps |
Source code in crnpy/crnpy.py
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
|
is_outlier(x, method, window=11, min_val=None, max_val=None)
Function that tests whether values are outliers using a modified moving z-score based on the median absolute difference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
DataFrame or Series
|
Variable containing only the columns with neutron counts. |
required |
method |
str
|
Outlier detection method. One of: range, iqr, moviqr, zscore, movzscore, modified_zscore, and scaled_mad |
required |
window |
int
|
Window size for the moving central tendency. Default is 11. |
11
|
min_val |
int or float
|
Minimum value for a reading to be considered valid. Default is None. |
None
|
max_val(int |
or float
|
Maximum value for a reading to be considered valid. Default is None. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Boolean indicating outliers. |
References
Iglewicz, B. and Hoaglin, D.C., 1993. How to detect and handle outliers (Vol. 16). Asq Press.
Source code in crnpy/crnpy.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
latlon_to_utm(lat, lon, utm_zone_number=None, utm_zone_letter=None)
Convert geographic coordinates (lat, lon) to projected coordinates (utm) using the Military Grid Reference System.
Function only applies to non-polar coordinates. If further functionality is required, consider using the utm module. See references for more information.
UTM zones on an equirectangular world map with irregular zones in red and New York City's zone highlighted. See UTM zones for a full description.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat |
(float, array)
|
Latitude in decimal degrees. |
required |
lon |
(float, array)
|
Longitude in decimal degrees. |
required |
utm_zone_number |
int
|
UTM zone number. If None, the zone number is automatically calculated. |
None
|
utm_zone_letter |
str
|
UTM zone letter. If None, the zone letter is automatically calculated. |
None
|
Returns:
Type | Description |
---|---|
(float, float, int, str)
|
Tuple of easting, northing, zone number and zone letter. First element is easting, second is northing, third is zone number and fourth is zone letter. |
References
Code adapted from utm module created by Tobias Bieniek (Github username: Turbo87) https://github.com/Turbo87/utm
Source code in crnpy/crnpy.py
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 |
|
lattice_water(clay_content, total_carbon=None)
Estimate the amount of water in the lattice of clay minerals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clay_content |
float
|
Clay content in the soil in percent. |
required |
total_carbon |
float
|
Total carbon content in the soil in percent. If None, the amount of water is estimated based on clay content only. |
None
|
Returns:
Type | Description |
---|---|
float
|
Amount of water in the lattice of clay minerals in percent |
Source code in crnpy/crnpy.py
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
|
location_factor(site_atmospheric_depth, site_Rc, reference_atmospheric_depth, reference_Rc)
Function to estimate the location factor between two sites according to McJannet and Desilets, 2023.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_atmospheric_depth |
float
|
Atmospheric depth at the site in g/cm2. Can be estimated using the function |
required |
site_Rc |
float
|
Cutoff rigidity at the site in GV. Can be estimated using the function |
required |
reference_atmospheric_depth |
float
|
Atmospheric depth at the reference location in g/cm2. |
required |
reference_Rc |
float
|
Cutoff rigidity at the reference location in GV. |
required |
Returns:
Type | Description |
---|---|
float
|
Location-dependent correction factor. |
References
McJannet, D. L., & Desilets, D. (2023). Incoming Neutron Flux Corrections for Cosmic‐Ray Soil and Snow Sensors Using the Global Neutron Monitor Network. Water Resources Research, 59(4), e2022WR033889.
Source code in crnpy/crnpy.py
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
|
nrad_weight(h, theta, distances, depth, profiles=None, rhob=1.4, method='Kohli_2015', p=None, Hveg=0, tol=0.01)
Function to compute distance weights corresponding to each soil sample.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h |
array or Series
|
Air Humidity from 0.1 to 50 in g/m^3. When h=0, the function will skip the distance weighting. |
required |
theta |
array or Series
|
Soil Moisture for each sample (0.02 - 0.50 m^3/m^3) |
required |
distances |
array or Series
|
Distances from the location of each sample to the origin (0.5 - 600 m) |
required |
depth |
array or Series
|
Depths for each sample (m) |
required |
profiles |
array or Series
|
Soil profiles id for each sample. Required for the 'Schron_2017' method. |
None
|
rhob |
array or Series
|
Bulk density in g/cm^3 |
1.4
|
p |
array or Series
|
Atmospheric pressure in hPa. Required for the 'Schron_2017' method. |
None
|
Hveg |
array or Series
|
Vegetation height in m. Required for the 'Schron_2017' method. |
0
|
method |
str
|
Method to compute the distance weights. Options are 'Kohli_2015' or 'Schron_2017'. |
'Kohli_2015'
|
tol |
float
|
Tolerance for the iterative solution. Default is 0.01. Required for the 'Schron_2017' method. |
0.01
|
Returns:
Name | Type | Description |
---|---|---|
theta_new |
array or Series
|
Weighted soil moisture values. |
weights |
array or Series
|
Distance weights for each sample. For the 'Schron_2017' method, the weights are computed for each distance. |
References
Köhli, M., Schrön, M., Zreda, M., Schmidt, U., Dietrich, P., and Zacharias, S. (2015). Footprint characteristics revised for field-scale soil moisture monitoring with cosmic-ray neutrons. Water Resour. Res. 51, 5772–5790. doi:10.1002/2015WR017169
Schrön, M., Köhli, M., Scheiffele, L., Iwema, J., Bogena, H. R., Lv, L., Martini, E., Baroni, G., Rosolem, R., Weimar, J., Mai, J., Cuntz, M., Rebmann, C., Oswald, S. E., Dietrich, P., Schmidt, U., and Zacharias, S.: Improving calibration and validation of cosmic-ray neutron sensors in the light of spatial sensitivity, Hydrol. Earth Syst. Sci., 21, 5009–5030, https://doi.org/10.5194/hess-21-5009-2017, 2017.
Source code in crnpy/crnpy.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
|
remove_incomplete_intervals(df, timestamp_col, integration_time, remove_first=False)
Function that removes rows with incomplete integration intervals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas Dataframe with data from stationary or roving CRNP devices. |
required |
timestamp_col |
str
|
Name of the column with timestamps in datetime format. |
required |
integration_time |
int
|
Duration of the neutron counting interval in seconds. Typical values are 60 seconds and 3600 seconds. |
required |
remove_first |
bool
|
Remove first row. Default is False. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
|
Source code in crnpy/crnpy.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
rover_centered_coordinates(x, y)
Function to estimate the intermediate locations between two points, assuming the measurements were taken at a constant speed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
array
|
x coordinates. |
required |
y |
array
|
y coordinates. |
required |
Returns:
Name | Type | Description |
---|---|---|
x_est |
array
|
Estimated x coordinates. |
y_est |
array
|
Estimated y coordinates. |
Source code in crnpy/crnpy.py
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 |
|
sensing_depth(vwc, pressure, p_ref, bulk_density, Wlat, dist=None, method='Schron_2017')
Function that computes the estimated sensing depth of the cosmic-ray neutron probe. The function offers several methods to compute the depth at which 86 % of the neutrons probe the soil profile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vwc |
array or Series or DataFrame
|
Estimated volumetric water content for each timestamp. |
required |
pressure |
array or Series or DataFrame
|
Atmospheric pressure in hPa for each timestamp. |
required |
p_ref |
float
|
Reference pressure in hPa. |
required |
bulk_density |
float
|
Soil bulk density. |
required |
Wlat |
float
|
Lattice water content. |
required |
method |
str
|
Method to compute the sensing depth. Options are 'Schron_2017' or 'Franz_2012'. |
'Schron_2017'
|
dist |
list or array
|
List of radial distances at which to estimate the sensing depth. Only used for the 'Schron_2017' method. |
None
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Estimated sensing depth in m. |
References
Franz, T.E., Zreda, M., Ferre, T.P.A., Rosolem, R., Zweck, C., Stillman, S., Zeng, X. and Shuttleworth, W.J., 2012. Measurement depth of the cosmic ray soil moisture probe affected by hydrogen from various sources. Water Resources Research, 48(8). doi.org/10.1029/2012WR011871
Schrön, M., Köhli, M., Scheiffele, L., Iwema, J., Bogena, H. R., Lv, L., et al. (2017). Improving calibration and validation of cosmic-ray neutron sensors in the light of spatial sensitivity. Hydrol. Earth Syst. Sci. 21, 5009–5030. doi.org/10.5194/hess-21-5009-2017
Source code in crnpy/crnpy.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
smooth_1d(values, window=5, order=3, method='moving_median')
Use a Savitzky-Golay filter to smooth the signal of corrected neutron counts or another one-dimensional array (e.g. computed volumetric water content).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
DataFrame or Serie
|
Dataframe containing the values to smooth. |
required |
window |
int
|
Window size for the Savitzky-Golay filter. Default is 5. |
5
|
method |
str
|
Method to use for smoothing the data. Default is 'moving_median'. Options are 'moving_average', 'moving_median' and 'savitzky_golay'. |
'moving_median'
|
order |
int
|
Order of the Savitzky-Golay filter. Default is 3. |
3
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with smoothed values. |
References
Franz, T.E., Wahbi, A., Zhang, J., Vreugdenhil, M., Heng, L., Dercon, G., Strauss, P., Brocca, L. and Wagner, W., 2020. Practical data products from cosmic-ray neutron sensing for hydrological applications. Frontiers in Water, 2, p.9. doi.org/10.3389/frwa.2020.00009
Savitzky, A., & Golay, M. J. (1964). Smoothing and differentiation of data by simplified least squares procedures. Analytical chemistry, 36(8), 1627-1639.
Source code in crnpy/crnpy.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
|
spatial_average(x, y, z, buffer=100, min_neighbours=3, method='mean', rnd=False)
Moving buffer filter to smooth georeferenced two-dimensional data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
list or array
|
UTM x coordinates in meters. |
required |
y |
list or array
|
UTM y coordinates in meters. |
required |
z |
list or array
|
Values to be smoothed. |
required |
buffer |
float
|
Radial buffer distance in meters. |
100
|
min_neighbours |
int
|
Minimum number of neighbours to consider for the smoothing. |
3
|
method |
str
|
One of 'mean' or 'median'. |
'mean'
|
rnd |
bool
|
Boolean to round the final result. Useful in case of z representing neutron counts. |
False
|
Returns:
Type | Description |
---|---|
array
|
Smoothed version of z with the same dimension as z. |
Source code in crnpy/crnpy.py
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 |
|
total_raw_counts(counts)
Compute the sum of uncorrected neutron counts for all detectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
DataFrame
|
Dataframe containing only the columns with neutron counts. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe with the sum of uncorrected neutron counts for all detectors. |
Source code in crnpy/crnpy.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
uncertainty_counts(raw_counts, metric='std', fp=1, fw=1, fi=1)
Function to estimate the uncertainty of raw counts.
Measurements of proportional neutron detector systems are governed by counting statistics that follow a Poissonian probability distribution (Zreda et al., 2012). The expected uncertainty in the neutron count rate $N$ is defined by the standard deviation $ \sqrt{N} $ (Jakobi et al., 2020). The CV% can be expressed as $ N^{-1/2} $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_counts |
array
|
Raw neutron counts. |
required |
metric |
str
|
Either 'std' or 'cv' for standard deviation or coefficient of variation. |
'std'
|
fp |
float
|
Pressure correction factor. |
1
|
fw |
float
|
Humidity correction factor. |
1
|
fi |
float
|
Incoming neutron flux correction factor. |
1
|
Returns:
Name | Type | Description |
---|---|---|
uncertainty |
float
|
Uncertainty of raw counts. |
References
Jakobi J, Huisman JA, Schrön M, Fiedler J, Brogi C, Vereecken H and Bogena HR (2020) Error Estimation for Soil Moisture Measurements With Cosmic Ray Neutron Sensing and Implications for Rover Surveys. Front. Water 2:10. doi: 10.3389/frwa.2020.00010
Zreda, M., Shuttleworth, W. J., Zeng, X., Zweck, C., Desilets, D., Franz, T., and Rosolem, R.: COSMOS: the COsmic-ray Soil Moisture Observing System, Hydrol. Earth Syst. Sci., 16, 4079–4099, https://doi.org/10.5194/hess-16-4079-2012, 2012.
Source code in crnpy/crnpy.py
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 |
|
uncertainty_vwc(raw_counts, N0, bulk_density, fp=1, fw=1, fi=1, a0=0.0808, a1=0.372, a2=0.115)
Function to estimate the uncertainty propagated to volumetric water content.
The uncertainty of the volumetric water content is estimated by propagating the uncertainty of the raw counts. Following Eq. 10 in Jakobi et al. (2020), the uncertainty of the volumetric water content can be expressed as: $$ \sigma_{\theta_g}(N) = \sigma_N \frac{a_0 N_0}{(N_{cor} - a_1 N_0)^4} \sqrt{(N_{cor} - a_1 N_0)^4 + 8 \sigma_N^2 (N_{cor} - a_1 N_0)^2 + 15 \sigma_N^4} $$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_counts |
array
|
Raw neutron counts. |
required |
N0 |
float
|
Calibration parameter N0. |
required |
bulk_density |
float
|
Bulk density in g cm-3. |
required |
fp |
float
|
Pressure correction factor. |
1
|
fw |
float
|
Humidity correction factor. |
1
|
fi |
float
|
Incoming neutron flux correction factor. |
1
|
Returns:
Name | Type | Description |
---|---|---|
sigma_VWC |
float
|
Uncertainty in terms of volumetric water content. |
References
Jakobi J, Huisman JA, Schrön M, Fiedler J, Brogi C, Vereecken H and Bogena HR (2020) Error Estimation for Soil Moisture Measurements With Cosmic Ray Neutron Sensing and Implications for Rover Surveys. Front. Water 2:10. doi: 10.3389/frwa.2020.00010
Source code in crnpy/crnpy.py
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
|
crnpy
is a package for processing observations from cosmic ray neutron detectors.
Modules exported by this package:
crnpy
: Provide several functions to process observations from cosmic ray neutron detectors.
abs_humidity(relative_humidity, temp)
Compute the actual vapor pressure (e) in g m^-3 using RH (%) and current temperature (c) observations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relative_humidity |
float
|
relative humidity (%) |
required |
temp |
float
|
temperature (Celsius) |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
actual vapor pressure (g m^-3) |
Source code in crnpy/crnpy.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
atmospheric_depth(elevation, latitude)
Function to estimate the atmospheric depth for any point on Earth according to McJannet and Desilets, 2023
This function is required in the calculation of the location-dependent reference correction proposed by McJannet and Desilets, 2023.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elevation |
float
|
Elevation in meters above sea level. |
required |
latitude |
float
|
Geographic latitude in decimal degrees. Value in range -90 to 90 |
required |
Returns:
Type | Description |
---|---|
float
|
Atmospheric depth in g/cm2 |
References
Atmosphere, U. S. (1976). US standard atmosphere. National Oceanic and Atmospheric Administration.
McJannet, D. L., & Desilets, D. (2023). Incoming Neutron Flux Corrections for Cosmic‐Ray Soil and Snow Sensors Using the Global Neutron Monitor Network. Water Resources Research, 59(4), e2022WR033889.
Source code in crnpy/crnpy.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 |
|
biomass_to_bwe(biomass_dry, biomass_fresh, fWE=0.494)
Function to convert biomass to biomass water equivalent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
biomass_dry |
array or Series or DataFrame
|
Above ground dry biomass in kg m-2. |
required |
biomass_fresh |
array or Series or DataFrame
|
Above ground fresh biomass in kg m-2. |
required |
fWE |
float
|
Stoichiometric ratio of H2O to organic carbon molecules in the plant (assuming this is mostly cellulose) Default is 0.494 (Wahbi & Avery, 2018). |
0.494
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Biomass water equivalent in kg m-2. |
References
Wahbi, A., Avery, W. (2018). In Situ Destructive Sampling. In: Cosmic Ray Neutron Sensing: Estimation of Agricultural Crop Biomass Water Equivalent. Springer, Cham. https://doi.org/10.1007/978-3-319-69539-6_2
Source code in crnpy/crnpy.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
correction_bwe(counts, bwe, r2_N0=0.05)
Function to correct for biomass effects in neutron counts. following the approach described in Baatz et al., 2015.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
array or Series or DataFrame
|
Array of ephithermal neutron counts. |
required |
bwe |
float
|
Biomass water equivalent kg m-2. |
required |
r2_N0 |
float
|
Ratio of neutron counts with biomass to neutron counts without biomass. Default is 0.05. |
0.05
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Array of corrected neutron counts for biomass effects. |
References
Baatz, R., H. R. Bogena, H.-J. Hendricks Franssen, J. A. Huisman, C. Montzka, and H. Vereecken (2015), An empiricalvegetation correction for soil water content quantification using cosmic ray probes, Water Resour. Res., 51, 2030–2046, doi:10.1002/ 2014WR016443.
Source code in crnpy/crnpy.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
correction_humidity(abs_humidity, Aref)
Correction factor for absolute humidity.
This function corrects neutron counts for absolute humidity using the method described in Rosolem et al. (2013) and Anderson et al. (2017). The correction is performed using the following equation:
$$ C_{corrected} = C_{raw} \cdot f_w $$
where:
- Ccorrected: corrected neutron counts
- Craw: raw neutron counts
- fw: absolute humidity correction factor
$$ f_w = 1 + 0.0054(A - A_{ref}) $$
where:
- A: absolute humidity
- Aref: reference absolute humidity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
abs_humidity |
list or array
|
Relative humidity readings. |
required |
Aref |
float
|
Reference absolute humidity (g/m^3). The day of the instrument calibration is recommended. |
required |
Returns:
Type | Description |
---|---|
list
|
fw correction factor. |
References
Rosolem, R., W. J. Shuttleworth, M. Zreda, T. E. Franz, X. Zeng, and S. A. Kurc, 2013: The Effect of Atmospheric Water Vapor on Neutron Count in the Cosmic-Ray Soil Moisture Observing System. J. Hydrometeor., 14, 1659–1671, https://doi.org/10.1175/JHM-D-12-0120.1.
M. Andreasen, K.H. Jensen, D. Desilets, T.E. Franz, M. Zreda, H.R. Bogena, and M.C. Looms. 2017. Status and perspectives on the cosmic-ray neutron method for soil moisture estimation and other environmental science applications. Vadose Zone J. 16(8). doi:10.2136/vzj2017.04.0086
Source code in crnpy/crnpy.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
correction_incoming_flux(incoming_neutrons, incoming_Ref=None, fill_na=None, Rc_method=None, Rc_site=None, site_atmdepth=None, Rc_ref=None, ref_atmdepth=None)
Correction factor for incoming neutron flux.
This function corrects neutron counts for incoming neutron flux using the method described in Anderson et al. (2017). The correction is performed using the following equation:
$$ C_{corrected} = \frac{C_{raw}}{f_i} $$
where:
- Ccorrected: corrected neutron counts
- Craw: raw neutron counts
- fi: incoming neutron flux correction factor
$$ f_i = \frac{I}{I_{ref}} $$
where:
- I: incoming neutron flux
- Iref: reference incoming neutron flux
Parameters:
Name | Type | Description | Default |
---|---|---|---|
incoming_neutrons |
list or array
|
Incoming neutron flux readings. |
required |
incoming_Ref |
float
|
Reference incoming neutron flux. Baseline incoming neutron flux. |
None
|
fill_na |
float
|
Value to fill missing data. If None, missing data remains as NaN. |
None
|
Rc_method |
str
|
Optional to correct for differences in cutoff rigidity between the site and the reference station. Possible values are 'McJannetandDesilets2023' or 'Hawdonetal2014'. If None, no correction is performed. |
None
|
Rc_site |
float
|
Cutoff rigidity at the monitoring site. |
None
|
site_atmdepth |
float
|
Atmospheric depth at the monitoring site. |
None
|
Rc_ref |
float
|
Cutoff rigidity at the reference station. |
None
|
ref_atmdepth |
float
|
Atmospheric depth at the reference station. |
None
|
Returns:
Type | Description |
---|---|
list
|
fi correction factor. |
References
Hawdon, A., D. McJannet, and J. Wallace (2014), Calibration and correction procedures for cosmic-ray neutron soil moisture probes located across Australia, Water Resour. Res., 50, 5029–5043, doi:10.1002/2013WR015138.
M. Andreasen, K.H. Jensen, D. Desilets, T.E. Franz, M. Zreda, H.R. Bogena, and M.C. Looms. 2017. Status and perspectives on the cosmic-ray neutron method for soil moisture estimation and other environmental science applications. Vadose Zone J. 16(8). doi:10.2136/vzj2017.04.0086
McJannet, D. L., & Desilets, D. (2023). Incoming neutron flux corrections for cosmic-ray soil and snow sensors using the global neutron monitor network. Water Resources Research, 59, e2022WR033889. https://doi.org/10.1029/2022WR033889
Source code in crnpy/crnpy.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
correction_pressure(pressure, Pref, L)
Correction factor for atmospheric pressure.
This function corrects neutron counts for atmospheric pressure using the method described in Andreasen et al. (2017). The correction is performed using the following equation:
$$ C_{corrected} = \frac{C_{raw}}{fp} $$
where:
- Ccorrected: corrected neutron counts
- Craw: raw neutron counts
- fp: pressure correction factor
$$ fp = e^{\frac{P_{ref} - P}{L}} $$
where:
- P: atmospheric pressure
- Pref: reference atmospheric pressure
- L: Atmospheric attenuation coefficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pressure |
list or array
|
Atmospheric pressure readings. Long-term average pressure is recommended. |
required |
Pref |
float
|
Reference atmospheric pressure. |
required |
L |
float
|
Atmospheric attenuation coefficient. |
required |
Returns:
Type | Description |
---|---|
list
|
fp pressure correction factor. |
References
Zreda, M., Shuttleworth, W. J., Zeng, X., Zweck, C., Desilets, D., Franz, T., and Rosolem, R.: COSMOS: the COsmic-ray Soil Moisture Observing System, Hydrol. Earth Syst. Sci., 16, 4079–4099, https://doi.org/10.5194/hess-16-4079-2012, 2012.
M. Andreasen, K.H. Jensen, D. Desilets, T.E. Franz, M. Zreda, H.R. Bogena, and M.C. Looms. 2017. Status and perspectives on the cosmic-ray neutron method for soil moisture estimation and other environmental science applications. Vadose Zone J. 16(8). doi:10.2136/vzj2017.04.0086
Source code in crnpy/crnpy.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
correction_road(counts, theta_N, road_width, road_distance=0.0, theta_road=0.12, p0=0.42, p1=0.5, p2=1.06, p3=4, p4=0.16, p6=0.94, p7=1.1, p8=2.7, p9=0.01)
Function to correct for road effects in neutron counts. following the approach described in Schrön et al., 2018.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
array or Series or DataFrame
|
Array of ephithermal neutron counts. |
required |
theta_N |
float
|
Volumetric water content of the soil estimated from the uncorrected neutron counts. |
required |
road_width |
float
|
Width of the road in m. |
required |
road_distance |
float
|
Distance of the road from the sensor in m. Default is 0.0. |
0.0
|
theta_road |
float
|
Volumetric water content of the road. Default is 0.12. |
0.12
|
p0-p9 |
float
|
Parameters of the correction function. Default values are from Schrön et al., 2018. |
required |
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Array of corrected neutron counts for road effects. |
References
Schrön,M.,Rosolem,R.,Köhli,M., Piussi,L.,Schröter,I.,Iwema,J.,etal. (2018).Cosmic-ray neutron rover surveys of field soil moisture and the influence of roads.WaterResources Research,54,6441–6459. https://doi. org/10.1029/2017WR021719
Source code in crnpy/crnpy.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
counts_to_vwc(counts, N0, Wlat, Wsoc, bulk_density, a0=0.0808, a1=0.372, a2=0.115)
Function to convert corrected and filtered neutron counts into volumetric water content.
This method implements soil moisture estimation using the non-linear relationship between neutron count and soil volumetric water content following the approach described in Desilets et al., 2010.
$\theta(N) =\frac{a_0}{(\frac{N}{N_0}) - a_1} - a_2 $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
array or Series or DataFrame
|
Array of corrected and filtered neutron counts. |
required |
N0 |
float
|
Device-specific neutron calibration constant. |
required |
Wlat |
float
|
Lattice water content. |
required |
Wsoc |
float
|
Soil organic carbon content. |
required |
bulk_density |
float
|
Soil bulk density. |
required |
a0 |
float
|
Parameter given in Zreda et al., 2012. Default is 0.0808. |
0.0808
|
a1 |
float
|
Parameter given in Zreda et al., 2012. Default is 0.372. |
0.372
|
a2 |
float
|
Parameter given in Zreda et al., 2012. Default is 0.115. |
0.115
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Volumetric water content in m3 m-3. |
References
Desilets, D., M. Zreda, and T.P.A. Ferré. 2010. Nature’s neutron probe: Land surface hydrology at an elusive scale with cosmic rays. Water Resour. Res. 46:W11505. doi.org/10.1029/2009WR008726
Source code in crnpy/crnpy.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
cutoff_rigidity(lat, lon)
Function to estimate the approximate cutoff rigidity for any point on Earth according to the tabulated data of Smart and Shea, 2019. The returned value can be used to select the appropriate neutron monitor station to estimate the cosmic-ray neutron intensity at the location of interest.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat |
float
|
Geographic latitude in decimal degrees. Value in range -90 to 90 |
required |
lon |
float
|
Geographic longitude in decimal degrees. Values in range from 0 to 360. Typical negative longitudes in the west hemisphere will fall in the range 180 to 360. |
required |
Returns:
Type | Description |
---|---|
float
|
Cutoff rigidity in GV. Error is about +/- 0.3 GV |
Examples:
Estimate the cutoff rigidity for Newark, NJ, US
>>> zq = cutoff_rigidity(39.68, -75.75)
>>> print(zq)
2.52 GV (Value from NMD is 2.40 GV)
References
Hawdon, A., McJannet, D., & Wallace, J. (2014). Calibration and correction procedures for cosmic‐ray neutron soil moisture probes located across Australia. Water Resources Research, 50(6), 5029-5043.
Smart, D. & Shea, Matthew. (2001). Geomagnetic Cutoff Rigidity Computer Program: Theory, Software Description and Example. NASA STI/Recon Technical Report N.
Shea, M. A., & Smart, D. F. (2019, July). Re-examination of the First Five Ground-Level Events. In International Cosmic Ray Conference (ICRC2019) (Vol. 36, p. 1149).
Source code in crnpy/crnpy.py
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
|
euclidean_distance(px, py, x, y)
Function that computes the Euclidean distance between one point in space and one or more points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px |
float
|
x projected coordinate of the point. |
required |
py |
float
|
y projected coordinate of the point. |
required |
x |
(list, ndarray, series)
|
vector of x projected coordinates. |
required |
y |
(list, ndarray, series)
|
vector of y projected coordinates. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Numpy array of distances from the point (px,py) to all the points in x and y vectors. |
Source code in crnpy/crnpy.py
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 |
|
exp_filter(sm, T=1)
Exponential filter to estimate soil moisture in the rootzone from surface observtions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
list or array
|
Soil moisture in mm of water for the top layer of the soil profile. |
required |
T |
float
|
Characteristic time length in the same units as the measurement interval. |
1
|
Returns:
Name | Type | Description |
---|---|---|
sm_subsurface |
list or array
|
Subsurface soil moisture in the same units as the input. |
References
Albergel, C., Rüdiger, C., Pellarin, T., Calvet, J.C., Fritz, N., Froissard, F., Suquia, D., Petitpa, A., Piguet, B. and Martin, E., 2008. From near-surface to root-zone soil moisture using an exponential filter: an assessment of the method based on in-situ observations and model simulations. Hydrology and Earth System Sciences, 12(6), pp.1323-1337.
Franz, T.E., Wahbi, A., Zhang, J., Vreugdenhil, M., Heng, L., Dercon, G., Strauss, P., Brocca, L. and Wagner, W., 2020. Practical data products from cosmic-ray neutron sensing for hydrological applications. Frontiers in Water, 2, p.9.
Rossini, P. and Patrignani, A., 2021. Predicting rootzone soil moisture from surface observations in cropland using an exponential filter. Soil Science Society of America Journal.
Source code in crnpy/crnpy.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 |
|
fill_missing_timestamps(df, timestamp_col='timestamp', freq='H', round_timestamp=True, verbose=False)
Helper function to fill rows with missing timestamps in datetime record. Rows are filled with NaN values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas DataFrame. |
required |
timestamp_col |
str
|
Column with the timestamp. Must be in datetime format. Default column name is 'timestamp'. |
'timestamp'
|
freq |
str
|
Timestamp frequency. 'H' for hourly, 'M' for minute, or None. Can also use '3H' for a 3 hour frequency. Default is 'H'. |
'H'
|
round_timestamp |
bool
|
Whether to round timestamps to the nearest frequency. Default is True. |
True
|
verbose |
bool
|
Prints the missing timestamps added to the DatFrame. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with filled missing timestamps. |
Source code in crnpy/crnpy.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
find_neutron_monitor(Rc, start_date=None, end_date=None, verbose=False)
Search for potential reference neutron monitoring stations based on cutoff rigidity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Rc |
float
|
Cutoff rigidity in GV. Values in range 1.0 to 3.0 GV. |
required |
start_date |
datetime
|
Start date for the period of interest. |
None
|
end_date |
datetime
|
End date for the period of interest. |
None
|
verbose |
bool
|
If True, print a expanded output of the incoming neutron flux data. |
False
|
Returns:
Type | Description |
---|---|
list
|
List of top five stations with closes cutoff rigidity. User needs to select station according to site altitude. |
Examples:
>>> from crnpy import crnpy
>>> Rc = 2.40 # 2.40 Newark, NJ, US
>>> crnpy.find_neutron_monitor(Rc)
Select a station with an altitude similar to that of your location. For more information go to: 'https://www.nmdb.eu/nest/help.php#helpstations
Your cutoff rigidity is 2.4 GV STID NAME R Altitude_m 40 NEWK Newark 2.40 50 33 MOSC Moscow 2.43 200 27 KIEL Kiel 2.36 54 28 KIEL2 KielRT 2.36 54 31 MCRL Mobile Cosmic Ray Laboratory 2.46 200 32 MGDN Magadan 2.10 220 42 NVBK Novosibirsk 2.91 163 26 KGSN Kingston 1.88 65 9 CLMX Climax 3.00 3400 57 YKTK Yakutsk 1.65 105
References
https://www.nmdb.eu/nest/help.php#helpstations
Source code in crnpy/crnpy.py
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
|
get_incoming_neutron_flux(start_date, end_date, station, utc_offset=0, expand_window=0, verbose=False)
Function to retrieve neutron flux from the Neutron Monitor Database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_date |
datetime
|
Start date of the time series. |
required |
end_date |
datetime
|
End date of the time series. |
required |
station |
str
|
Neutron Monitor station to retrieve data from. |
required |
utc_offset |
int
|
UTC offset in hours. Default is 0. |
0
|
expand_window |
int
|
Number of hours to expand the time window to retrieve extra data. Default is 0. |
0
|
verbose |
bool
|
Print information about the request. Default is False. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
Neutron flux in counts per hour and timestamps. |
References
Documentation available:https://www.nmdb.eu/nest/help.php#howto
Source code in crnpy/crnpy.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
|
get_reference_neutron_flux(station, date=pd.to_datetime('2011-05-01'))
Function to retrieve reference neutron flux from the Neutron Monitor Database. Default date is 2011-05-01, following previous studies (Zreda et a., 2012, Hawdon et al., 2014, Bogena et al., 2022).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
Neutron Monitor station to retrieve data from. |
required |
date |
datetime
|
Date of the reference neutron flux. Default is 2011-05-01. |
to_datetime('2011-05-01')
|
Returns:
Type | Description |
---|---|
float
|
Reference neutron flux in counts per hour. |
References
Zreda, M., Shuttleworth, W. J., Zeng, X., Zweck, C., Desilets, D., Franz, T., & Rosolem, R. (2012). COSMOS: The cosmic-ray soil moisture observing system. Hydrology and Earth System Sciences, 16(11), 4079-4099.
Hawdon, A., McJannet, D., & Wallace, J. (2014). Calibration and correction procedures for cosmic‐ray neutron soil moisture probes located across Australia. Water Resources Research, 50(6), 5029-5043.
Bogena, H. R., Schrön, M., Jakobi, J., Ney, P., Zacharias, S., Andreasen, M., ... & Vereecken, H. (2022). COSMOS-Europe: a European network of cosmic-ray neutron soil moisture sensors. Earth System Science Data, 14(3), 1125-1151.
Source code in crnpy/crnpy.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
idw(x, y, z, X_pred, Y_pred, neighborhood=1000, p=1)
Function to interpolate data using inverse distance weight.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
list or array
|
UTM x coordinates in meters. |
required |
y |
list or array
|
UTM y coordinates in meters. |
required |
z |
list or array
|
Values to be interpolated. |
required |
X_pred |
list or array
|
UTM x coordinates where z values need to be predicted. |
required |
Y_pred |
list or array
|
UTM y coordinates where z values need to be predicted. |
required |
neighborhood |
float
|
Only points within this radius in meters are considered for the interpolation. |
1000
|
p |
int
|
Exponent of the inverse distance weight formula. Typically, p=1 or p=2. |
1
|
Returns:
Type | Description |
---|---|
array
|
Interpolated values. |
Source code in crnpy/crnpy.py
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 |
|
interpolate_2d(x, y, z, dx=100, dy=100, method='cubic', neighborhood=1000)
Function for interpolating irregular spatial data into a regular grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
list or array
|
UTM x coordinates in meters. |
required |
y |
list or array
|
UTM y coordinates in meters. |
required |
z |
list or array
|
Values to be interpolated. |
required |
dx |
float
|
Pixel width in meters. |
100
|
dy |
float
|
Pixel height in meters. |
100
|
method |
str
|
Interpolation method. One of 'cubic', 'linear', 'nearest', or 'idw'. |
'cubic'
|
neighborhood |
float
|
Only points within this radius in meters are considered for the interpolation. |
1000
|
Returns:
Name | Type | Description |
---|---|---|
x_pred |
array
|
2D array with x coordinates. |
y_pred |
array
|
2D array with y coordinates. |
z_pred |
array
|
2D array with interpolated values. |
Source code in crnpy/crnpy.py
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
|
interpolate_incoming_flux(nmdb_timestamps, nmdb_counts, crnp_timestamps)
Function to interpolate incoming neutron flux to match the timestamps of the observations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nmdb_timestamps |
Series or array
|
Series or array of timestamps in datetime format from the NMDB |
required |
nmdb_counts |
Series or array
|
Series or array of incoming neutron flux counts from the NMDB |
required |
crnp_timestamps |
Series or array
|
Series or array of timestamps in datetime format from the CRNP device |
required |
Returns:
Type | Description |
---|---|
Series
|
Series containing interpolated incoming neutron flux. Length of Series is the same as crnp_timestamps |
Source code in crnpy/crnpy.py
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
|
is_outlier(x, method, window=11, min_val=None, max_val=None)
Function that tests whether values are outliers using a modified moving z-score based on the median absolute difference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
DataFrame or Series
|
Variable containing only the columns with neutron counts. |
required |
method |
str
|
Outlier detection method. One of: range, iqr, moviqr, zscore, movzscore, modified_zscore, and scaled_mad |
required |
window |
int
|
Window size for the moving central tendency. Default is 11. |
11
|
min_val |
int or float
|
Minimum value for a reading to be considered valid. Default is None. |
None
|
max_val(int |
or float
|
Maximum value for a reading to be considered valid. Default is None. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Boolean indicating outliers. |
References
Iglewicz, B. and Hoaglin, D.C., 1993. How to detect and handle outliers (Vol. 16). Asq Press.
Source code in crnpy/crnpy.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
latlon_to_utm(lat, lon, utm_zone_number=None, utm_zone_letter=None)
Convert geographic coordinates (lat, lon) to projected coordinates (utm) using the Military Grid Reference System.
Function only applies to non-polar coordinates. If further functionality is required, consider using the utm module. See references for more information.
UTM zones on an equirectangular world map with irregular zones in red and New York City's zone highlighted. See UTM zones for a full description.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat |
(float, array)
|
Latitude in decimal degrees. |
required |
lon |
(float, array)
|
Longitude in decimal degrees. |
required |
utm_zone_number |
int
|
UTM zone number. If None, the zone number is automatically calculated. |
None
|
utm_zone_letter |
str
|
UTM zone letter. If None, the zone letter is automatically calculated. |
None
|
Returns:
Type | Description |
---|---|
(float, float, int, str)
|
Tuple of easting, northing, zone number and zone letter. First element is easting, second is northing, third is zone number and fourth is zone letter. |
References
Code adapted from utm module created by Tobias Bieniek (Github username: Turbo87) https://github.com/Turbo87/utm
Source code in crnpy/crnpy.py
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 |
|
lattice_water(clay_content, total_carbon=None)
Estimate the amount of water in the lattice of clay minerals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clay_content |
float
|
Clay content in the soil in percent. |
required |
total_carbon |
float
|
Total carbon content in the soil in percent. If None, the amount of water is estimated based on clay content only. |
None
|
Returns:
Type | Description |
---|---|
float
|
Amount of water in the lattice of clay minerals in percent |
Source code in crnpy/crnpy.py
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
|
location_factor(site_atmospheric_depth, site_Rc, reference_atmospheric_depth, reference_Rc)
Function to estimate the location factor between two sites according to McJannet and Desilets, 2023.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_atmospheric_depth |
float
|
Atmospheric depth at the site in g/cm2. Can be estimated using the function |
required |
site_Rc |
float
|
Cutoff rigidity at the site in GV. Can be estimated using the function |
required |
reference_atmospheric_depth |
float
|
Atmospheric depth at the reference location in g/cm2. |
required |
reference_Rc |
float
|
Cutoff rigidity at the reference location in GV. |
required |
Returns:
Type | Description |
---|---|
float
|
Location-dependent correction factor. |
References
McJannet, D. L., & Desilets, D. (2023). Incoming Neutron Flux Corrections for Cosmic‐Ray Soil and Snow Sensors Using the Global Neutron Monitor Network. Water Resources Research, 59(4), e2022WR033889.
Source code in crnpy/crnpy.py
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
|
nrad_weight(h, theta, distances, depth, profiles=None, rhob=1.4, method='Kohli_2015', p=None, Hveg=0, tol=0.01)
Function to compute distance weights corresponding to each soil sample.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h |
array or Series
|
Air Humidity from 0.1 to 50 in g/m^3. When h=0, the function will skip the distance weighting. |
required |
theta |
array or Series
|
Soil Moisture for each sample (0.02 - 0.50 m^3/m^3) |
required |
distances |
array or Series
|
Distances from the location of each sample to the origin (0.5 - 600 m) |
required |
depth |
array or Series
|
Depths for each sample (m) |
required |
profiles |
array or Series
|
Soil profiles id for each sample. Required for the 'Schron_2017' method. |
None
|
rhob |
array or Series
|
Bulk density in g/cm^3 |
1.4
|
p |
array or Series
|
Atmospheric pressure in hPa. Required for the 'Schron_2017' method. |
None
|
Hveg |
array or Series
|
Vegetation height in m. Required for the 'Schron_2017' method. |
0
|
method |
str
|
Method to compute the distance weights. Options are 'Kohli_2015' or 'Schron_2017'. |
'Kohli_2015'
|
tol |
float
|
Tolerance for the iterative solution. Default is 0.01. Required for the 'Schron_2017' method. |
0.01
|
Returns:
Name | Type | Description |
---|---|---|
theta_new |
array or Series
|
Weighted soil moisture values. |
weights |
array or Series
|
Distance weights for each sample. For the 'Schron_2017' method, the weights are computed for each distance. |
References
Köhli, M., Schrön, M., Zreda, M., Schmidt, U., Dietrich, P., and Zacharias, S. (2015). Footprint characteristics revised for field-scale soil moisture monitoring with cosmic-ray neutrons. Water Resour. Res. 51, 5772–5790. doi:10.1002/2015WR017169
Schrön, M., Köhli, M., Scheiffele, L., Iwema, J., Bogena, H. R., Lv, L., Martini, E., Baroni, G., Rosolem, R., Weimar, J., Mai, J., Cuntz, M., Rebmann, C., Oswald, S. E., Dietrich, P., Schmidt, U., and Zacharias, S.: Improving calibration and validation of cosmic-ray neutron sensors in the light of spatial sensitivity, Hydrol. Earth Syst. Sci., 21, 5009–5030, https://doi.org/10.5194/hess-21-5009-2017, 2017.
Source code in crnpy/crnpy.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
|
remove_incomplete_intervals(df, timestamp_col, integration_time, remove_first=False)
Function that removes rows with incomplete integration intervals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas Dataframe with data from stationary or roving CRNP devices. |
required |
timestamp_col |
str
|
Name of the column with timestamps in datetime format. |
required |
integration_time |
int
|
Duration of the neutron counting interval in seconds. Typical values are 60 seconds and 3600 seconds. |
required |
remove_first |
bool
|
Remove first row. Default is False. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
|
Source code in crnpy/crnpy.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
rover_centered_coordinates(x, y)
Function to estimate the intermediate locations between two points, assuming the measurements were taken at a constant speed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
array
|
x coordinates. |
required |
y |
array
|
y coordinates. |
required |
Returns:
Name | Type | Description |
---|---|---|
x_est |
array
|
Estimated x coordinates. |
y_est |
array
|
Estimated y coordinates. |
Source code in crnpy/crnpy.py
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 |
|
sensing_depth(vwc, pressure, p_ref, bulk_density, Wlat, dist=None, method='Schron_2017')
Function that computes the estimated sensing depth of the cosmic-ray neutron probe. The function offers several methods to compute the depth at which 86 % of the neutrons probe the soil profile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vwc |
array or Series or DataFrame
|
Estimated volumetric water content for each timestamp. |
required |
pressure |
array or Series or DataFrame
|
Atmospheric pressure in hPa for each timestamp. |
required |
p_ref |
float
|
Reference pressure in hPa. |
required |
bulk_density |
float
|
Soil bulk density. |
required |
Wlat |
float
|
Lattice water content. |
required |
method |
str
|
Method to compute the sensing depth. Options are 'Schron_2017' or 'Franz_2012'. |
'Schron_2017'
|
dist |
list or array
|
List of radial distances at which to estimate the sensing depth. Only used for the 'Schron_2017' method. |
None
|
Returns:
Type | Description |
---|---|
array or Series or DataFrame
|
Estimated sensing depth in m. |
References
Franz, T.E., Zreda, M., Ferre, T.P.A., Rosolem, R., Zweck, C., Stillman, S., Zeng, X. and Shuttleworth, W.J., 2012. Measurement depth of the cosmic ray soil moisture probe affected by hydrogen from various sources. Water Resources Research, 48(8). doi.org/10.1029/2012WR011871
Schrön, M., Köhli, M., Scheiffele, L., Iwema, J., Bogena, H. R., Lv, L., et al. (2017). Improving calibration and validation of cosmic-ray neutron sensors in the light of spatial sensitivity. Hydrol. Earth Syst. Sci. 21, 5009–5030. doi.org/10.5194/hess-21-5009-2017
Source code in crnpy/crnpy.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
smooth_1d(values, window=5, order=3, method='moving_median')
Use a Savitzky-Golay filter to smooth the signal of corrected neutron counts or another one-dimensional array (e.g. computed volumetric water content).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
DataFrame or Serie
|
Dataframe containing the values to smooth. |
required |
window |
int
|
Window size for the Savitzky-Golay filter. Default is 5. |
5
|
method |
str
|
Method to use for smoothing the data. Default is 'moving_median'. Options are 'moving_average', 'moving_median' and 'savitzky_golay'. |
'moving_median'
|
order |
int
|
Order of the Savitzky-Golay filter. Default is 3. |
3
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with smoothed values. |
References
Franz, T.E., Wahbi, A., Zhang, J., Vreugdenhil, M., Heng, L., Dercon, G., Strauss, P., Brocca, L. and Wagner, W., 2020. Practical data products from cosmic-ray neutron sensing for hydrological applications. Frontiers in Water, 2, p.9. doi.org/10.3389/frwa.2020.00009
Savitzky, A., & Golay, M. J. (1964). Smoothing and differentiation of data by simplified least squares procedures. Analytical chemistry, 36(8), 1627-1639.
Source code in crnpy/crnpy.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
|
spatial_average(x, y, z, buffer=100, min_neighbours=3, method='mean', rnd=False)
Moving buffer filter to smooth georeferenced two-dimensional data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
list or array
|
UTM x coordinates in meters. |
required |
y |
list or array
|
UTM y coordinates in meters. |
required |
z |
list or array
|
Values to be smoothed. |
required |
buffer |
float
|
Radial buffer distance in meters. |
100
|
min_neighbours |
int
|
Minimum number of neighbours to consider for the smoothing. |
3
|
method |
str
|
One of 'mean' or 'median'. |
'mean'
|
rnd |
bool
|
Boolean to round the final result. Useful in case of z representing neutron counts. |
False
|
Returns:
Type | Description |
---|---|
array
|
Smoothed version of z with the same dimension as z. |
Source code in crnpy/crnpy.py
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 |
|
total_raw_counts(counts)
Compute the sum of uncorrected neutron counts for all detectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts |
DataFrame
|
Dataframe containing only the columns with neutron counts. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe with the sum of uncorrected neutron counts for all detectors. |
Source code in crnpy/crnpy.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
uncertainty_counts(raw_counts, metric='std', fp=1, fw=1, fi=1)
Function to estimate the uncertainty of raw counts.
Measurements of proportional neutron detector systems are governed by counting statistics that follow a Poissonian probability distribution (Zreda et al., 2012). The expected uncertainty in the neutron count rate $N$ is defined by the standard deviation $ \sqrt{N} $ (Jakobi et al., 2020). The CV% can be expressed as $ N^{-1/2} $
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_counts |
array
|
Raw neutron counts. |
required |
metric |
str
|
Either 'std' or 'cv' for standard deviation or coefficient of variation. |
'std'
|
fp |
float
|
Pressure correction factor. |
1
|
fw |
float
|
Humidity correction factor. |
1
|
fi |
float
|
Incoming neutron flux correction factor. |
1
|
Returns:
Name | Type | Description |
---|---|---|
uncertainty |
float
|
Uncertainty of raw counts. |
References
Jakobi J, Huisman JA, Schrön M, Fiedler J, Brogi C, Vereecken H and Bogena HR (2020) Error Estimation for Soil Moisture Measurements With Cosmic Ray Neutron Sensing and Implications for Rover Surveys. Front. Water 2:10. doi: 10.3389/frwa.2020.00010
Zreda, M., Shuttleworth, W. J., Zeng, X., Zweck, C., Desilets, D., Franz, T., and Rosolem, R.: COSMOS: the COsmic-ray Soil Moisture Observing System, Hydrol. Earth Syst. Sci., 16, 4079–4099, https://doi.org/10.5194/hess-16-4079-2012, 2012.
Source code in crnpy/crnpy.py
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 |
|
uncertainty_vwc(raw_counts, N0, bulk_density, fp=1, fw=1, fi=1, a0=0.0808, a1=0.372, a2=0.115)
Function to estimate the uncertainty propagated to volumetric water content.
The uncertainty of the volumetric water content is estimated by propagating the uncertainty of the raw counts. Following Eq. 10 in Jakobi et al. (2020), the uncertainty of the volumetric water content can be expressed as: $$ \sigma_{\theta_g}(N) = \sigma_N \frac{a_0 N_0}{(N_{cor} - a_1 N_0)^4} \sqrt{(N_{cor} - a_1 N_0)^4 + 8 \sigma_N^2 (N_{cor} - a_1 N_0)^2 + 15 \sigma_N^4} $$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_counts |
array
|
Raw neutron counts. |
required |
N0 |
float
|
Calibration parameter N0. |
required |
bulk_density |
float
|
Bulk density in g cm-3. |
required |
fp |
float
|
Pressure correction factor. |
1
|
fw |
float
|
Humidity correction factor. |
1
|
fi |
float
|
Incoming neutron flux correction factor. |
1
|
Returns:
Name | Type | Description |
---|---|---|
sigma_VWC |
float
|
Uncertainty in terms of volumetric water content. |
References
Jakobi J, Huisman JA, Schrön M, Fiedler J, Brogi C, Vereecken H and Bogena HR (2020) Error Estimation for Soil Moisture Measurements With Cosmic Ray Neutron Sensing and Implications for Rover Surveys. Front. Water 2:10. doi: 10.3389/frwa.2020.00010
Source code in crnpy/crnpy.py
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
|