Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barometer offset correction #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .idea/crnpy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
[![GitHub Workflow Status (publish)](https://img.shields.io/github/actions/workflow/status/soilwater/crnpy/python-publish.yml?label=publish)](https://github.com/soilwater/crnpy/actions/workflows/python-publish.yml)
[![PyPI - Status](https://img.shields.io/pypi/v/crnpy)](https://pypi.org/project/crnpy/)
[![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/soilwater/crnpy/latest/main)](https://github.com/soilwater/crnpy)
![JOSS submission status](https://joss.theoj.org/papers/e65c1bb5fee58c39289efc4547d1fd10/status.svg)
[![JOSS submission status](https://joss.theoj.org/papers/e65c1bb5fee58c39289efc4547d1fd10/status.svg)](https://joss.theoj.org/papers/e65c1bb5fee58c39289efc4547d1fd10)


# Cosmic-Ray Neutron Python (CRNPy) Library

Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![GitHub Workflow Status (publish)](https://img.shields.io/github/actions/workflow/status/soilwater/crnpy/python-publish.yml?label=publish)](https://github.com/soilwater/crnpy/actions/workflows/python-publish.yml)
[![PyPI - Status](https://img.shields.io/pypi/v/crnpy)](https://pypi.org/project/crnpy/)
[![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/soilwater/crnpy/latest/main)](https://github.com/soilwater/crnpy)
[![JOSS submission status](https://joss.theoj.org/papers/e65c1bb5fee58c39289efc4547d1fd10/status.svg)](https://joss.theoj.org/papers/e65c1bb5fee58c39289efc4547d1fd10)

Welcome to the homepage of the CRNPy (Cosmic-Ray Neutron Python) library, an open-source Python library designed for the processing and conversion of raw neutron counts from cosmic-ray neutron probes (CRNP) into soil moisture data.

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

setuptools.setup(
name="crnpy",
version="0.5.1",
version="0.5.2",
packages=['crnpy'],
package_dir = {"": "src"},
description="A Python package for the estimation and processing of soil moisture data from cosmic-ray neutron counts.",
include_package_data=True,
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url="https://github.com/soilwater/crnpy",
url="https://soilwater.github.io/crnpy/",
author="Joaquin Peraza, Andres Patrignani",
author_email="jperaza@ksu.edu, andrespatrignani@ksu.edu",
license="MIT",
Expand Down
55 changes: 55 additions & 0 deletions src/crnpy/crnpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,61 @@ def uncertainty_vwc(raw_counts, N0, bulk_density, fp=1, fw=1, fi=1, a0=0.0808,a1

return sigma_VWC

def barometer_offset(pressure, temperature, delta_h, return_correction=False):
"""Function to correct readings from a barometer at a different altitude.

The barometric formula describes the decrease of the atmospheric pressure with altitude.
The pressure at a certain altitude can be calculated as:
$$
P2 = P1 \cdot e^{\frac{g \cdot M \cdot \Delta h}{R \cdot T}}
$$

where $P_1$ is the pressure at a different altitude, $P_2$ is the pressure at the target altitude, $g$ is the gravitational acceleration, $M$ is the molar mass of air, $\Delta h$ is the difference in altitude, $R$ is the universal gas constant, and $T$ is the temperature in Kelvin.

Args:
pressure (float): Pressure reading at the reference altitude in hPa.
temperature (float): Temperature at the reference altitude in Celsius.
delta_h (float): Difference in altitude between the reference and target altitude in meters.

Returns:
pressure_corrected (float): Pressure reading at the target altitude in hPa.
correction (float): Correction factor applied to the pressure reading (optional).

References:
Bellamy, J. C. (1945). The use of pressure altitude and altimeter corrections in meteorology. Journal of the Atmospheric Sciences, 2(1), 1-79.

Examples:
>>> import numpy as np
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> from crnpy import barometer_offset
>>> mesonetGypsum = pd.read_csv("http://mesonet.k-state.edu/rest/stationdata?stn=Gypsum&int=day&t_start=20200101000000&t_end=20231230000000", na_values='M', parse_dates=['TIMESTAMP'])
>>> mesonetAshland = pd.read_csv("http://mesonet.k-state.edu/rest/stationdata?stn=Ashland%20Bottoms&int=day&t_start=20200101000000&t_end=20231230000000", na_values='M', parse_dates=['TIMESTAMP'])
>>> merged = pd.merge(mesonetGypsum,mesonetAshland, left_on='TIMESTAMP', right_on='TIMESTAMP', suffixes=['_g', '_a'])
>>> delta_h = -52
>>> merged['P_g_corrected'] = barometer_offset(merged['PRESSUREAVG_g'], merged['TEMP2MAVG_g'], delta_h)
>>> plt.scatter(merged['PRESSUREAVG_a'], merged['P_g_corrected'], label='Corrected', color='teal')
>>> plt.scatter(merged['PRESSUREAVG_a'], merged['PRESSUREAVG_g'], label='Raw', color='orange', alpha=0.5)
>>> plt.xlabel('Ashland Bottoms Pressure (hPa)')
>>> plt.ylabel('Gypsum Pressure (hPa)')
>>> plt.legend()
>>> plt.show()
"""
# Define constants
G = -9.80665 # m/s^2
m = 0.0289644 # kg/mol
R = 8.31432
T= (temperature + 273.15)

if return_correction:
correction = np.exp((G * m * delta_h) / (R * T))
pressure_corrected = pressure * correction
return pressure_corrected, correction

pressure_corrected = pressure * np.exp((G * m * delta_h) / (R * T))
return pressure_corrected





Expand Down