finitespace / BME280

Provides an Arduino library for reading and interpreting Bosch BME280 data over I2C, SPI or Sw SPI.
GNU General Public License v3.0
212 stars 105 forks source link

rename sealevelAltitude #40

Closed coelner closed 7 years ago

coelner commented 7 years ago

rename sealevelAltitude to seaLevelPressure. It is a little bit misleading.

finitespace commented 7 years ago

It returns altitude so I am not sure why you are suggesting the change in name.

coelner commented 7 years ago

Maybe I understand that completely wrong, but the Altitude at SeaLevel is 0. But we need a function to get a SeaLevel correlated Pressure. So far I read the code, you calculate this. ( https://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Internationale_H.C3.B6henformel ) (You need a SeaLevelAltitude while converting between different geodetic reference systems)

jirkaptr commented 7 years ago

Hi, Tyler, it seems you have caught yourself in the trap of misleading name. The function sealevelAlitude really calculates the sea-level pressure which we know from meteorological reports. To the formula itself:

I recommend the comparison with http://drkfs.net/correctiontosealevel.htm.

finitespace commented 7 years ago

Alright all, good data. I should have required more documentation on the pull request. Let me try to clean this up.

jirkaptr commented 7 years ago

Hello, A lot of the time spent to compare calculation methods with official data of weather stations. Generally it is difficult to find complete set of data – usually the Pstation is omitted. I found complete data from Austria and Czech Republic only. https://www.zamg.ac.at/cms/de/wetter/wetterwerte-analysen http://portal.chmi.cz/aktualni-situace/aktualni-stav-pocasi/ceska-republika/stanice/profesionalni-stanice/mapy/teplota-a-vlhkost/stanice

Regarding differences A vs. CZ: Each country uses a bit different algorithm. The table is usable to check different calculation formulas and compare with official data. Secondary it is usable to calibrate pressure sensors. Note: Excel document is created in European language. If you need decimal “.” instead of “,” in numbers then you have to change the character…

Regards jirkaptr Atmospheric calculations test.xlsx

rpaskowitz commented 7 years ago

I believe some renaming is in order. The readme claims that altitude is returned, but the source paints a more confusing picture:

  /// Convert current pressure to sea-level pressure, returns
  /// Altitude (in meters), temperature in Celsius
  /// return the equivalent pressure at sea level.

It says that it is converting pressures, then says it returns altitude in meters (and temperature), and then says it returns pressure at sea level. A simple test shows that it returns values that as much more in the range of pressure in Pa than altitude in m. It seems much more correct to say it accepts pressure (in Pa), Altitude (in meters) and Temperature (in Celsius), and returns pressure (in Pa). The returns on the first line of the comment seems erroneous and if left out, the comment as written makes far more sense (name of the method notwithstanding)

For example, a current reading from my BMP280 has a pressure of 101425 Pa, and the sealevel calculation returns 102105 Pa. Note that this is using a known-good altitude, and not the altitude as derived from the Altitude() method, which returns a significantly different value, but is computed with a default sealevel altitude of 101325 Pa as defined in the header

Given that this method seems to return a value in Pa, and that sealevel altitude should be pretty relatively constant, one might wonder what use this method has? For me, it seems to be for calibration of the Altitude(). When using the 101325 sealevel pressure, my altitude is about 70m from reality, so instead, using my known-good altitude, and obtaining the 102105 Pa pressure from the method, it seems I can use this value in place of the default sea-level pressure in Altitude() to get calibrated altitudes.

finitespace commented 7 years ago

Here is the original pull request: #22

Looks like it was originally written to calculate equivalent sea level pressure in mb. When I refactored the code my analysis showed it was unit independent code. So, using Pa would not impact the calculation.

@guruathwal can you shed some light on the situation.

rpaskowitz commented 7 years ago

I'd have to give it a more careful read, but that sounds correct. There winds up being a ratio of sealevel pressure to atmospheric pressure, and since the conversions between various units of pressure are linear, you should be able to pass in pressure in any unit, and get the adjusted pressure back out in the same unit.

It will just be pressure that it converted though, the temperature/altitude are fixed and used to determine the sealevel pressure.

finitespace commented 7 years ago

Alright, a change is in order:

finitespace commented 7 years ago

Completed: #49

guruathwal commented 7 years ago

Hi.. there should not be any confusion.. You input your current altitude in "Meters", Current Pressure in "mb" and current temperature in "celcius" The function will return equivalent Sea Level Pressure in "mb"