pyastroweatherio 0.76.0.dev3__tar.gz → 0.76.0.dev4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/PKG-INFO +1 -1
  2. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio/client.py +70 -95
  3. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio/const.py +12 -12
  4. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio/helper_functions.py +1 -269
  5. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio.egg-info/PKG-INFO +1 -1
  6. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/setup.py +1 -1
  7. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/tests/test_calculations.py +14 -108
  8. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/LICENSE +0 -0
  9. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/README.md +0 -0
  10. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio/__init__.py +0 -0
  11. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio/dataclasses.py +0 -0
  12. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio/errors.py +0 -0
  13. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio.egg-info/SOURCES.txt +0 -0
  14. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio.egg-info/dependency_links.txt +0 -0
  15. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio.egg-info/requires.txt +0 -0
  16. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/pyastroweatherio.egg-info/top_level.txt +0 -0
  17. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/setup.cfg +0 -0
  18. {pyastroweatherio-0.76.0.dev3 → pyastroweatherio-0.76.0.dev4}/tests/test_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyastroweatherio
3
- Version: 0.76.0.dev3
3
+ Version: 0.76.0.dev4
4
4
  Summary: Python Wrapper for OpenMeteo and Met.no REST API
5
5
  Home-page: https://github.com/mawinkler/pyastroweatherio
6
6
  Author: Markus Winkler
@@ -152,7 +152,7 @@ class AstroWeather:
152
152
 
153
153
  if self._experimental_features:
154
154
  _LOGGER.debug(
155
- "Using experimental features for Seeing, Magnitude Degradation, Lifted Index, and Fog Density"
155
+ "experimental_features is set but no longer has any effect — improved calculations are now always active"
156
156
  )
157
157
 
158
158
  # Testing
@@ -198,76 +198,48 @@ class AstroWeather:
198
198
  return [r if not isinstance(r, BaseException) else (_LOGGER.warning("Dew point calculation failed: %s", r) or float("nan")) for r in results]
199
199
 
200
200
  async def _calculate_seeing(self, df):
201
- if self._experimental_features:
202
- has_pbl = "gfs_boundary_layer_height" in df.columns
203
- tasks = [
204
- self._atmosphere.calculate_seeing_11(
205
- temperature=row["air_temperature"],
206
- humidity=row["relative_humidity"],
207
- dew_point_temperature=row["dew_point_temperature"],
208
- wind_speed=row["wind_speed"],
209
- cloud_cover=row["cloud_area_fraction"],
210
- altitude=self._location_data.elevation,
211
- air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
212
- boundary_layer_height=row["gfs_boundary_layer_height"] if has_pbl else None,
213
- )
214
- for _, row in df.iterrows()
215
- ]
216
- else:
217
- tasks = [
218
- self._atmosphere.calculate_seeing(
219
- temperature=row["air_temperature"],
220
- humidity=row["relative_humidity"],
221
- dew_point_temperature=row["dew_point_temperature"],
222
- wind_speed=row["wind_speed"],
223
- cloud_cover=row["cloud_area_fraction"],
224
- altitude=self._location_data.elevation,
225
- air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
226
- )
227
- for _, row in df.iterrows()
228
- ]
201
+ has_pbl = "gfs_boundary_layer_height" in df.columns
202
+ tasks = [
203
+ self._atmosphere.calculate_seeing(
204
+ temperature=row["air_temperature"],
205
+ humidity=row["relative_humidity"],
206
+ dew_point_temperature=row["dew_point_temperature"],
207
+ wind_speed=row["wind_speed"],
208
+ cloud_cover=row["cloud_area_fraction"],
209
+ altitude=self._location_data.elevation,
210
+ air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
211
+ boundary_layer_height=row["gfs_boundary_layer_height"] if has_pbl else None,
212
+ )
213
+ for _, row in df.iterrows()
214
+ ]
229
215
  results = await asyncio.gather(*tasks, return_exceptions=True)
230
216
  return [r if not isinstance(r, BaseException) else (_LOGGER.warning("Seeing calculation failed: %s", r) or float("nan")) for r in results]
231
217
 
232
218
  async def _calculate_transparency(self, df):
233
- if self._experimental_features:
234
- tasks = [
235
- self._atmosphere.magnitude_degradation_11(
236
- temperature=row["air_temperature"],
237
- humidity=row["relative_humidity"],
238
- dew_point_temperature=row["dew_point_temperature"],
239
- wind_speed=row["wind_speed"],
240
- cloud_cover=row["cloud_area_fraction"],
241
- altitude=self._location_data.elevation,
242
- air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
243
- )
244
- for _, row in df.iterrows()
245
- ]
246
- else:
247
- tasks = [
248
- self._atmosphere.magnitude_degradation(
249
- temperature=row["air_temperature"],
250
- humidity=row["relative_humidity"],
251
- dew_point_temperature=row["dew_point_temperature"],
252
- wind_speed=row["wind_speed"],
253
- cloud_cover=row["cloud_area_fraction"],
254
- altitude=self._location_data.elevation,
255
- air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
256
- )
257
- for _, row in df.iterrows()
258
- ]
219
+ tasks = [
220
+ self._atmosphere.magnitude_degradation(
221
+ temperature=row["air_temperature"],
222
+ humidity=row["relative_humidity"],
223
+ dew_point_temperature=row["dew_point_temperature"],
224
+ wind_speed=row["wind_speed"],
225
+ cloud_cover=row["cloud_area_fraction"],
226
+ altitude=self._location_data.elevation,
227
+ air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
228
+ )
229
+ for _, row in df.iterrows()
230
+ ]
259
231
  results = await asyncio.gather(*tasks, return_exceptions=True)
260
232
  return [r if not isinstance(r, BaseException) else (_LOGGER.warning("Transparency calculation failed: %s", r) or float("nan")) for r in results]
261
233
 
262
234
  async def _calculate_lifted_index(self, df):
263
- if self._experimental_features and "gfs_lifted_index" in df.columns:
264
- # Use NWP model output from GFS; fall back to Bolton approximation for any missing values
235
+ # Prefer GFS NWP output; Bolton _11 approximation fills any missing slots.
236
+ if "gfs_lifted_index" in df.columns:
265
237
  results = []
266
238
  fallback_idx = [i for i, (_, row) in enumerate(df.iterrows()) if pd.isna(row["gfs_lifted_index"])]
267
239
  if fallback_idx:
268
240
  fallback_rows = df.iloc[fallback_idx]
269
241
  fallback_tasks = [
270
- self._atmosphere.calculate_lifted_index_11(
242
+ self._atmosphere.calculate_lifted_index(
271
243
  temperature=row["air_temperature"],
272
244
  dew_point_temperature=row["dew_point_temperature"],
273
245
  altitude=self._location_data.elevation,
@@ -286,26 +258,15 @@ class AstroWeather:
286
258
  r = fallback_map.get(i)
287
259
  results.append(r if not isinstance(r, BaseException) else float("nan"))
288
260
  return results
289
- if self._experimental_features:
290
- tasks = [
291
- self._atmosphere.calculate_lifted_index_11(
292
- temperature=row["air_temperature"],
293
- dew_point_temperature=row["dew_point_temperature"],
294
- altitude=self._location_data.elevation,
295
- air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
296
- )
297
- for _, row in df.iterrows()
298
- ]
299
- else:
300
- tasks = [
301
- self._atmosphere.calculate_lifted_index(
302
- temperature=row["air_temperature"],
303
- dew_point_temperature=row["dew_point_temperature"],
304
- altitude=self._location_data.elevation,
305
- air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
306
- )
307
- for _, row in df.iterrows()
308
- ]
261
+ tasks = [
262
+ self._atmosphere.calculate_lifted_index(
263
+ temperature=row["air_temperature"],
264
+ dew_point_temperature=row["dew_point_temperature"],
265
+ altitude=self._location_data.elevation,
266
+ air_pressure_at_sea_level=row["air_pressure_at_sea_level"],
267
+ )
268
+ for _, row in df.iterrows()
269
+ ]
309
270
  results = await asyncio.gather(*tasks, return_exceptions=True)
310
271
  return [r if not isinstance(r, BaseException) else (_LOGGER.warning("Lifted index calculation failed: %s", r) or float("nan")) for r in results]
311
272
 
@@ -491,15 +452,12 @@ class AstroWeather:
491
452
  transparency = max(transparency, aod_mag)
492
453
  aerosol_optical_depth = aod if not math.isnan(aod) else 0.0
493
454
 
494
- # Calculate Fog Density
495
- if self._experimental_features:
496
- gfs_vis = row.get("gfs_visibility", float("nan"))
497
- gfs_vis = float(gfs_vis) if gfs_vis is not None else float("nan")
498
- if not math.isnan(gfs_vis):
499
- # Map GFS visibility (m) to fog density [0, 1]: 0 m = dense fog, ≥10 km = clear
500
- fog2m = max(0.0, min(100.0, (1.0 - gfs_vis / 10000.0) * 100.0))
501
- else:
502
- fog2m = await self._atmosphere.calculate_fog_density_11(temp2m, rh2m, dewpoint2m, wind_speed) * 100
455
+ # Calculate Fog Density: GFS visibility takes priority when available.
456
+ gfs_vis = row.get("gfs_visibility", float("nan"))
457
+ gfs_vis = float(gfs_vis) if gfs_vis is not None else float("nan")
458
+ if not math.isnan(gfs_vis):
459
+ # Map GFS visibility (m) to fog density [0, 1]: 0 m = dense fog, ≥10 km = clear
460
+ fog2m = max(0.0, min(100.0, (1.0 - gfs_vis / 10000.0) * 100.0))
503
461
  else:
504
462
  fog2m = await self._atmosphere.calculate_fog_density(temp2m, rh2m, dewpoint2m, wind_speed) * 100
505
463
 
@@ -568,8 +526,20 @@ class AstroWeather:
568
526
  ) -> int:
569
527
  """Return condition based on cloud cover, fog, seeing, transparency, wind speed, and precipitation."""
570
528
 
529
+ # Guard against NaN from failed atmospheric calculations.
530
+ # Seeing and transparency use worst-case so a data gap never produces an
531
+ # optimistic score; fog defaults to 0 (unknown ≠ foggy).
532
+ if math.isnan(seeing):
533
+ seeing = SEEING_MAX
534
+ if math.isnan(transparency):
535
+ transparency = MAG_DEGRATION_MAX
536
+ if math.isnan(fog):
537
+ fog = 0.0
538
+ if math.isnan(fog2m):
539
+ fog2m = 0.0
540
+
571
541
  # Seeing is something in between 0 and 2.5 arcsecs
572
- seeing = seeing * 100 / SEEING_MAX # arcsecs up to 2.5
542
+ seeing = seeing * 100 / SEEING_MAX # arcsecs up to 4.0
573
543
  # transparency = int(transparency * 40) # mag degration up to 2.5
574
544
  transparency = transparency * 100 / MAG_DEGRATION_MAX # mag degration up to MAG_DEGRATION_MAX
575
545
  # Wind speed is something in between 0 and 16.5 m/s
@@ -588,6 +558,17 @@ class AstroWeather:
588
558
  # heavy rain cannot push the score below 0 before the final clamp.
589
559
  precip_penalty = min(precipitation_amount / PRECIP_MAX, 1.0) * 100
590
560
 
561
+ total_weight = (
562
+ self._cloudcover_weight
563
+ + self._fog_weight
564
+ + self._seeing_weight
565
+ + self._transparency_weight
566
+ + self._calm_weight
567
+ )
568
+ if total_weight == 0:
569
+ _LOGGER.warning("All condition weights are zero; returning 0")
570
+ return 0
571
+
591
572
  condition = int(
592
573
  100
593
574
  - (
@@ -597,13 +578,7 @@ class AstroWeather:
597
578
  + self._transparency_weight * transparency
598
579
  + self._calm_weight * wind_speed_value
599
580
  )
600
- / (
601
- self._cloudcover_weight
602
- + self._fog_weight
603
- + self._seeing_weight
604
- + self._transparency_weight
605
- + self._calm_weight
606
- )
581
+ / total_weight
607
582
  - precip_penalty
608
583
  )
609
584
 
@@ -46,18 +46,18 @@ ASTRONOMICAL_DUSK_DAWN = -18
46
46
  # #####################################################
47
47
  # Seeing
48
48
  # #####################################################
49
- SEEING = [0.25, 0.625, 0.875, 1.125, 1.375, 1.75, 2.25, 2.5]
49
+ SEEING = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
50
50
  # SEEING_PLAIN = [
51
51
  # 'Below 0.5"',
52
- # '0.5 to 0.75"',
53
- # '0.75 to 1"',
54
- # '1 to 1.25"',
55
- # '1.25 to 1.5"',
56
- # '1.5 to 2"',
57
- # '2 to 2.5"',
58
- # 'Over 2.5"',
52
+ # '0.5 to 1.0"',
53
+ # '1.0 to 1.5"',
54
+ # '1.5 to 2.0"',
55
+ # '2.0 to 2.5"',
56
+ # '2.5 to 3.0"',
57
+ # '3.0 to 3.5"',
58
+ # 'Over 3.5"',
59
59
  # ]
60
- SEEING_MAX = 2.5
60
+ SEEING_MAX = 4.0
61
61
 
62
62
  # #####################################################
63
63
  # Transparency
@@ -167,9 +167,9 @@ AOD_TO_MAG_FACTOR = 1.086 # Bouguer-Lambert: mag extinction ≈ AOD × 1
167
167
  # Condition
168
168
  # #####################################################
169
169
  DEFAULT_CONDITION_CLOUDCOVER_WEIGHT = 3
170
- DEFAULT_CONDITION_CLOUDCOVER_HIGH_WEAKENING = 1
171
- DEFAULT_CONDITION_CLOUDCOVER_MEDIUM_WEAKENING = 1
172
- DEFAULT_CONDITION_CLOUDCOVER_LOW_WEAKENING = 1
170
+ DEFAULT_CONDITION_CLOUDCOVER_HIGH_WEAKENING = 0.40 # cirrus is largely transparent
171
+ DEFAULT_CONDITION_CLOUDCOVER_MEDIUM_WEAKENING = 0.70 # altocumulus is semi-opaque
172
+ DEFAULT_CONDITION_CLOUDCOVER_LOW_WEAKENING = 1.00 # stratus/fog blocks fully
173
173
  DEFAULT_CONDITION_FOG_WEIGHT = 3
174
174
  DEFAULT_CONDITION_SEEING_WEIGHT = 2
175
175
  DEFAULT_CONDITION_TRANSPARENCY_WEIGHT = 1
@@ -116,56 +116,6 @@ class AtmosphericRoutines:
116
116
  @typechecked
117
117
  async def calculate_lifted_index(
118
118
  self, temperature, altitude, dew_point_temperature, air_pressure_at_sea_level
119
- ) -> None | float:
120
- """Calculate atmospheric lifted index."""
121
- # https://en.wikipedia.org/wiki/Lifted_index
122
-
123
- values = {
124
- "temperature": temperature,
125
- "altitude": altitude,
126
- "dew_point_temperature": dew_point_temperature,
127
- "air_pressure_at_sea_level": air_pressure_at_sea_level,
128
- }
129
-
130
- missing = [name for name, val in values.items() if val is None or (isinstance(val, float) and math.isnan(val))]
131
-
132
- if missing:
133
- _LOGGER.warning(f"calculate_lifted_index: The following variables are None or NaN: {', '.join(missing)}")
134
- return None
135
-
136
- env_temp_500mb = -20.0 # °C, approximate environmental temperature at 500 hPa
137
-
138
- # Calculate saturation vapor pressure at surface temperature
139
- # Checked with https://www.weather.gov/epz/wxcalc_vaporpressure
140
- # es = self._calculate_vapor_pressure(temperature)
141
-
142
- # Calculate actual Vapor Pressure at surface
143
- # Checked with https://www.weather.gov/epz/wxcalc_vaporpressure
144
- e = self._calculate_vapor_pressure(dew_point_temperature)
145
-
146
- # Calculate Mixing Ratio at Surface in grams per kilogram
147
- # Checked with https://www.weather.gov/epz/wxcalc_mixingratio
148
- w = self._calculate_mixing_ratio(e, air_pressure_at_sea_level)
149
-
150
- # Calculate Lifting Condensation Level
151
- lcl = self._calculate_lifting_condensation_level(w, air_pressure_at_sea_level)
152
-
153
- # Calculate temperature of lifted parcel at 500 mb level
154
- lifted_temp_500mb = (
155
- env_temp_500mb + (temperature - lcl) * 0.5
156
- ) # Assumption: 500 mb is halfway through the troposphere
157
-
158
- # Calculate Lifted Index
159
- lifted_index = (env_temp_500mb - lifted_temp_500mb) * 2 + 7
160
-
161
- # Ensure lifted index is within the valid range [-7, 7]
162
- lifted_index = max(-7, min(7, lifted_index))
163
-
164
- return lifted_index
165
-
166
- @typechecked
167
- async def calculate_lifted_index_11(
168
- self, temperature, altitude, dew_point_temperature, air_pressure_at_sea_level
169
119
  ) -> None | float:
170
120
  """
171
121
  Returns a rough Lifted Index (LI) proxy in °C, clamped to [-7, +7].
@@ -250,92 +200,10 @@ class AtmosphericRoutines:
250
200
  return LI
251
201
 
252
202
  # #####################################################
253
- # Calculate magniture degradation based on transparency
254
- #
255
- # Version _11:
256
- # Extinction coefficient k (mag/airmass)
257
- # Use pressure-scaled Rayleigh and an aerosol term
203
+ # Calculate magnitude degradation based on transparency
258
204
  # #####################################################
259
205
  @typechecked
260
206
  async def magnitude_degradation(
261
- self,
262
- temperature,
263
- humidity,
264
- cloud_cover,
265
- wind_speed,
266
- altitude,
267
- dew_point_temperature,
268
- air_pressure_at_sea_level,
269
- ) -> None | float:
270
- """
271
- Calculates the magnitude_degradation of the atmosphere.
272
- This algorithm first calculates the lifted index and the seeing and uses them to calculate
273
- the transparency from which the magnitude degradation is derived from.
274
-
275
- Args:
276
- - temperature: Surface temperature in Celsius.
277
- - humidity: Humidity in Percent.
278
- - dew_point_temperature: Dew point temperature in Celsius.
279
- - wind_speed: Wind speed in meters per second.
280
- - altitude: Altitude in meters.
281
- - air_pressure_at_sea_level: Air pressure at sea level.
282
- - cloud_cover: Cloud cover in Percent.
283
- - lifted_index:
284
- - seeing:
285
-
286
- Returns:
287
- - magnitude_degradation: In magnitude
288
- """
289
-
290
- values = {
291
- "temperature": temperature,
292
- "humidity": humidity,
293
- "cloud_cover": cloud_cover,
294
- "wind_speed": wind_speed,
295
- "altitude": altitude,
296
- "dew_point_temperature": dew_point_temperature,
297
- "air_pressure_at_sea_level": air_pressure_at_sea_level,
298
- }
299
-
300
- missing = [name for name, val in values.items() if val is None or (isinstance(val, float) and math.isnan(val))]
301
-
302
- if missing:
303
- _LOGGER.warning(f"magnitude_degradation: The following variables are None or NaN: {', '.join(missing)}")
304
- return None
305
-
306
- lifted_index = await self.calculate_lifted_index(
307
- temperature, altitude, dew_point_temperature, air_pressure_at_sea_level
308
- )
309
- seeing = await self.calculate_seeing(
310
- temperature,
311
- humidity,
312
- dew_point_temperature,
313
- wind_speed,
314
- cloud_cover,
315
- altitude,
316
- air_pressure_at_sea_level,
317
- )
318
-
319
- # Calculate transparency
320
- transparency = self._calculate_transparency(
321
- humidity,
322
- temperature,
323
- cloud_cover,
324
- wind_speed,
325
- altitude,
326
- dew_point_temperature,
327
- air_pressure_at_sea_level,
328
- lifted_index,
329
- seeing,
330
- )
331
-
332
- # Convert transparency to magnitude degradation
333
- magnitude_degradation = self._transparency_to_magnitude_degradation(transparency)
334
-
335
- return magnitude_degradation
336
-
337
- @typechecked
338
- async def magnitude_degradation_11(
339
207
  self, temperature, humidity, cloud_cover, wind_speed, altitude, dew_point_temperature, air_pressure_at_sea_level
340
208
  ) -> None | float:
341
209
  """
@@ -433,88 +301,9 @@ class AtmosphericRoutines:
433
301
 
434
302
  # #####################################################
435
303
  # Calculate atmospheric seeing
436
- #
437
- # Version _11:
438
- # A more physical way is to estimate optical turbulence C2,n(z)
439
- # with the Hufnagel–Valley 5/7 profile, integrate to get r0,
440
- # then ϵ≈0.98λ/r.
441
304
  # #####################################################
442
305
  @typechecked
443
306
  async def calculate_seeing(
444
- self,
445
- temperature,
446
- humidity,
447
- dew_point_temperature,
448
- wind_speed,
449
- cloud_cover,
450
- altitude,
451
- air_pressure_at_sea_level,
452
- ) -> None | float:
453
- """
454
- Calculated seeing of the atmosphere. This algorithm first calculates the seeing factor based on temperature,
455
- humidity, wind speed and altitude above sea level. The seeing factor is then used to calculate the astronomical
456
- seeing in arcseconds. The empirical relationship used here states that the seeing in arcseconds is approximately
457
- equal to the reciprocal of the seeing factor multiplied by a conversion factor of 0.98.
458
-
459
- Used by: magnitude degradation
460
-
461
- Args:
462
- - temperature: Surface temperature in Celsius.
463
- - humidity: Humidity in Percent.
464
- - dew_point_temperature: Dew point temperature in Celsius.
465
- - wind_speed: Wind speed in meters per second.
466
- - cloud_cover: Cloud cover in Percent.
467
- - altitude: Altitude in meters.
468
- - air_pressure_at_sea_level: Air pressure at sea level.
469
-
470
- Returns:
471
- - seeing: In arcsecs
472
-
473
- Flow:
474
- - _calculate_water_vapor_pressure
475
- - adjusted_pressure
476
- - relative_pressure
477
- - seeing_factor
478
- - seeing
479
- """
480
-
481
- values = {
482
- "temperature": temperature,
483
- "humidity": humidity,
484
- "dew_point_temperature": dew_point_temperature,
485
- "wind_speed": wind_speed,
486
- "cloud_cover": cloud_cover,
487
- "altitude": altitude,
488
- "air_pressure_at_sea_level": air_pressure_at_sea_level,
489
- }
490
-
491
- missing = [name for name, val in values.items() if val is None or (isinstance(val, float) and math.isnan(val))]
492
-
493
- if missing:
494
- _LOGGER.warning(f"calculate_seeing: The following variables are None or NaN: {', '.join(missing)}")
495
- return None
496
-
497
- # Constants
498
- C = 6.5 # 1.7
499
-
500
- water_vapor_pressure = self._calculate_water_vapor_pressure(dew_point_temperature, humidity)
501
-
502
- # adjusted_pressure = air_pressure_at_sea_level * math.exp(-0.00012 * altitude)
503
- adjusted_pressure = self._calculate_adjusted_pressure(air_pressure_at_sea_level, altitude)
504
- relative_pressure = adjusted_pressure / air_pressure_at_sea_level
505
-
506
- if wind_speed == 0:
507
- wind_speed = 0.01
508
- seeing_factor = C * (water_vapor_pressure / 10) ** 0.25 * (wind_speed / 10) ** 0.75 * relative_pressure
509
- seeing = 0.98 / seeing_factor
510
-
511
- if seeing > SEEING_MAX:
512
- seeing = SEEING_MAX # max out seeing
513
-
514
- return seeing
515
-
516
- @typechecked
517
- async def calculate_seeing_11(
518
307
  self, temperature, humidity, dew_point_temperature, wind_speed, cloud_cover, altitude, air_pressure_at_sea_level,
519
308
  boundary_layer_height=None,
520
309
  ) -> None | float:
@@ -650,66 +439,9 @@ class AtmosphericRoutines:
650
439
 
651
440
  # #####################################################
652
441
  # Calculate fog density at 2m
653
- #
654
- # Version _11:
655
- # Tie to physics and aviation practice, estimate meteorological visibility
656
- # V and then map it to a “fog density” in [0,1].
657
- # anchor the metric to visibility vs extinction, a standard framework (Koschmieder).
658
- # It’s still simple but behaves correctly near saturation and with wind
659
- # Uses Koschmieder law: V = 3.912/betaext where betaext is the extinction coefficient
660
442
  # #####################################################
661
443
  @typechecked
662
444
  async def calculate_fog_density(self, temp2m, rh2m, dewpoint2m, wind_speed) -> float:
663
- """
664
- To calculate fog density, one can use a method based on the Liquid Water Content (LWC)
665
- in fog, which depends on the difference between air temperature and dew point, relative
666
- humidity, and wind speed. While there is no universally agreed-upon formula for fog
667
- density, the implemented approximate method can provide a rough measure.
668
- Note that actual fog density can be influenced by more complex microclimatic factors,
669
- so this approach serves as a simplified approximation.
670
-
671
- Args:
672
- - temp2m: Surface temperature in Celsius.
673
- - rh2m: Humidity in Percent.
674
- - dewpoint2m: Dew point temperature in Celsius.
675
- - wind_speed: Wind speed in meters per second.
676
-
677
- Returns:
678
- - adjusted_fog_density
679
- """
680
-
681
- # Constants
682
- # A normalizing constant chosen empirically to scale the fog density to a reasonable
683
- # range. Adjust this based on the desired scale of output (e.g., 0.1 for very light
684
- # fog, 1 for dense fog).
685
- k = 0.50
686
-
687
- # Controls how sensitive the density calculation is to the temperature-dew point
688
- # difference. Smaller values of a make fog density increase faster as the temperature
689
- # approaches the dew point.
690
- a = 1.5
691
-
692
- # Dampening constant for wind speed. This value ensures a gradual decay in fog density
693
- # as wind speed increases, which reflects that moderate wind disperses fog.
694
- b = 10
695
-
696
- # Calculate initial fog density based on temperature and humidity
697
- humidity_factor = rh2m / 100 # Relative humidity as a fraction
698
- temp_dew_diff = temp2m - dewpoint2m
699
-
700
- # Calculate fog density
701
- fog_density = k * humidity_factor * math.exp(-temp_dew_diff / a)
702
-
703
- # Adjust for wind speed
704
- adjusted_fog_density = fog_density * math.exp(-wind_speed / b)
705
-
706
- # Ensure fog density is within the valid range [0, 1]
707
- adjusted_fog_density = max(0, min(1, adjusted_fog_density))
708
-
709
- return float(adjusted_fog_density)
710
-
711
- @typechecked
712
- async def calculate_fog_density_11(self, temp2m, rh2m, dewpoint2m, wind_speed) -> float:
713
445
  """
714
446
  Estimate fog likelihood as a dimensionless density in [0, 1].
715
447
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyastroweatherio
3
- Version: 0.76.0.dev3
3
+ Version: 0.76.0.dev4
4
4
  Summary: Python Wrapper for OpenMeteo and Met.no REST API
5
5
  Home-page: https://github.com/mawinkler/pyastroweatherio
6
6
  Author: Markus Winkler
@@ -11,7 +11,7 @@ if os.path.isfile(requirement_path):
11
11
  setup(
12
12
  name="pyastroweatherio",
13
13
  packages=["pyastroweatherio"],
14
- version="0.76.0.dev3",
14
+ version="0.76.0.dev4",
15
15
  license="MIT",
16
16
  description="Python Wrapper for OpenMeteo and Met.no REST API",
17
17
  long_description=" ".join(
@@ -1,7 +1,6 @@
1
1
  """Unit tests for atmospheric calculations in AtmosphericRoutines."""
2
2
 
3
3
  import asyncio
4
- import math
5
4
  import unittest
6
5
 
7
6
  from pyastroweatherio.helper_functions import AtmosphericRoutines
@@ -97,27 +96,6 @@ class TestAtmosphericCalculations(unittest.TestCase):
97
96
  ))
98
97
  self.assertIsNone(result)
99
98
 
100
- # ---------------------------------------------------------------
101
- # calculate_lifted_index_11
102
- # ---------------------------------------------------------------
103
- def test_lifted_index_11_in_range(self):
104
- c = self.clear
105
- result = asyncio.run(self.atm.calculate_lifted_index_11(
106
- temperature=c["temperature"], altitude=c["altitude"],
107
- dew_point_temperature=c["dew_point_temperature"],
108
- air_pressure_at_sea_level=c["air_pressure_at_sea_level"],
109
- ))
110
- self.assertIsNotNone(result)
111
- self.assertGreaterEqual(result, -7.0)
112
- self.assertLessEqual(result, 7.0)
113
-
114
- def test_lifted_index_11_returns_none_on_missing(self):
115
- result = asyncio.run(self.atm.calculate_lifted_index_11(
116
- temperature=None, altitude=500.0,
117
- dew_point_temperature=5.0, air_pressure_at_sea_level=1013.25,
118
- ))
119
- self.assertIsNone(result)
120
-
121
99
  # ---------------------------------------------------------------
122
100
  # calculate_seeing
123
101
  # ---------------------------------------------------------------
@@ -131,40 +109,17 @@ class TestAtmosphericCalculations(unittest.TestCase):
131
109
  ))
132
110
  self.assertIsNotNone(result)
133
111
  self.assertGreater(result, 0.0)
134
- self.assertLessEqual(result, 2.5)
112
+ self.assertLessEqual(result, 4.0)
135
113
 
136
- def test_seeing_returns_none_on_missing(self):
137
- result = asyncio.run(self.atm.calculate_seeing(
138
- temperature=None, humidity=50.0, dew_point_temperature=5.0,
139
- wind_speed=2.0, cloud_cover=0.0, altitude=500.0,
140
- air_pressure_at_sea_level=1013.25,
141
- ))
142
- self.assertIsNone(result)
143
-
144
- # ---------------------------------------------------------------
145
- # calculate_seeing_11
146
- # ---------------------------------------------------------------
147
- def test_seeing_11_clear_in_range(self):
148
- c = self.clear
149
- result = asyncio.run(self.atm.calculate_seeing_11(
150
- temperature=c["temperature"], humidity=c["humidity"],
151
- dew_point_temperature=c["dew_point_temperature"],
152
- wind_speed=c["wind_speed"], cloud_cover=c["cloud_cover"],
153
- altitude=c["altitude"], air_pressure_at_sea_level=c["air_pressure_at_sea_level"],
154
- ))
155
- self.assertIsNotNone(result)
156
- self.assertGreater(result, 0.0)
157
- self.assertLessEqual(result, 2.5)
158
-
159
- def test_seeing_11_worse_overcast(self):
114
+ def test_seeing_worse_overcast(self):
160
115
  c, o = self.clear, self.overcast
161
- r_clear = asyncio.run(self.atm.calculate_seeing_11(
116
+ r_clear = asyncio.run(self.atm.calculate_seeing(
162
117
  temperature=c["temperature"], humidity=c["humidity"],
163
118
  dew_point_temperature=c["dew_point_temperature"],
164
119
  wind_speed=c["wind_speed"], cloud_cover=c["cloud_cover"],
165
120
  altitude=c["altitude"], air_pressure_at_sea_level=c["air_pressure_at_sea_level"],
166
121
  ))
167
- r_overcast = asyncio.run(self.atm.calculate_seeing_11(
122
+ r_overcast = asyncio.run(self.atm.calculate_seeing(
168
123
  temperature=o["temperature"], humidity=o["humidity"],
169
124
  dew_point_temperature=o["dew_point_temperature"],
170
125
  wind_speed=o["wind_speed"], cloud_cover=o["cloud_cover"],
@@ -173,8 +128,8 @@ class TestAtmosphericCalculations(unittest.TestCase):
173
128
  # Larger arcsec value = worse seeing
174
129
  self.assertGreater(r_overcast, r_clear)
175
130
 
176
- def test_seeing_11_returns_none_on_missing(self):
177
- result = asyncio.run(self.atm.calculate_seeing_11(
131
+ def test_seeing_returns_none_on_missing(self):
132
+ result = asyncio.run(self.atm.calculate_seeing(
178
133
  temperature=None, humidity=50.0, dew_point_temperature=5.0,
179
134
  wind_speed=2.0, cloud_cover=0.0, altitude=500.0,
180
135
  air_pressure_at_sea_level=1013.25,
@@ -194,22 +149,9 @@ class TestAtmosphericCalculations(unittest.TestCase):
194
149
  result = asyncio.run(self.atm.calculate_fog_density(10.0, 99.0, 9.8, 0.5))
195
150
  self.assertGreater(result, 0.3)
196
151
 
197
- # ---------------------------------------------------------------
198
- # calculate_fog_density_11
199
- # ---------------------------------------------------------------
200
- def test_fog_density_11_clear_is_low(self):
201
- result = asyncio.run(self.atm.calculate_fog_density_11(15.0, 50.0, 4.6, 2.0))
202
- self.assertGreaterEqual(result, 0.0)
203
- self.assertLessEqual(result, 1.0)
204
- self.assertLess(result, 0.3)
205
-
206
- def test_fog_density_11_saturated_is_high(self):
207
- result = asyncio.run(self.atm.calculate_fog_density_11(10.0, 99.0, 9.8, 0.5))
208
- self.assertGreater(result, 0.3)
209
-
210
- def test_fog_density_11_wind_disperses_fog(self):
211
- result_calm = asyncio.run(self.atm.calculate_fog_density_11(10.0, 99.0, 9.8, 0.0))
212
- result_windy = asyncio.run(self.atm.calculate_fog_density_11(10.0, 99.0, 9.8, 15.0))
152
+ def test_fog_density_wind_disperses_fog(self):
153
+ result_calm = asyncio.run(self.atm.calculate_fog_density(10.0, 99.0, 9.8, 0.0))
154
+ result_windy = asyncio.run(self.atm.calculate_fog_density(10.0, 99.0, 9.8, 15.0))
213
155
  self.assertGreater(result_calm, result_windy)
214
156
 
215
157
  # ---------------------------------------------------------------
@@ -227,51 +169,15 @@ class TestAtmosphericCalculations(unittest.TestCase):
227
169
  self.assertGreaterEqual(result, 0.0)
228
170
  self.assertLessEqual(result, 1.0)
229
171
 
230
- def test_magnitude_degradation_overcast_is_high(self):
231
- o = self.overcast
232
- result = asyncio.run(self.atm.magnitude_degradation(
233
- temperature=o["temperature"], humidity=o["humidity"],
234
- cloud_cover=o["cloud_cover"], wind_speed=o["wind_speed"],
235
- altitude=o["altitude"], dew_point_temperature=o["dew_point_temperature"],
236
- air_pressure_at_sea_level=o["air_pressure_at_sea_level"],
237
- ))
238
- self.assertIsNotNone(result)
239
- self.assertGreaterEqual(result, 0.5)
240
-
241
- def test_magnitude_degradation_returns_none_on_missing(self):
242
- c = self.clear
243
- result = asyncio.run(self.atm.magnitude_degradation(
244
- temperature=None, humidity=c["humidity"],
245
- cloud_cover=c["cloud_cover"], wind_speed=c["wind_speed"],
246
- altitude=c["altitude"], dew_point_temperature=c["dew_point_temperature"],
247
- air_pressure_at_sea_level=c["air_pressure_at_sea_level"],
248
- ))
249
- self.assertIsNone(result)
250
-
251
- # ---------------------------------------------------------------
252
- # magnitude_degradation_11
253
- # ---------------------------------------------------------------
254
- def test_magnitude_degradation_11_clear_in_range(self):
255
- c = self.clear
256
- result = asyncio.run(self.atm.magnitude_degradation_11(
257
- temperature=c["temperature"], humidity=c["humidity"],
258
- cloud_cover=c["cloud_cover"], wind_speed=c["wind_speed"],
259
- altitude=c["altitude"], dew_point_temperature=c["dew_point_temperature"],
260
- air_pressure_at_sea_level=c["air_pressure_at_sea_level"],
261
- ))
262
- self.assertIsNotNone(result)
263
- self.assertGreaterEqual(result, 0.0)
264
- self.assertLessEqual(result, 1.0)
265
-
266
- def test_magnitude_degradation_11_worse_overcast(self):
172
+ def test_magnitude_degradation_worse_overcast(self):
267
173
  c, o = self.clear, self.overcast
268
- r_clear = asyncio.run(self.atm.magnitude_degradation_11(
174
+ r_clear = asyncio.run(self.atm.magnitude_degradation(
269
175
  temperature=c["temperature"], humidity=c["humidity"],
270
176
  cloud_cover=c["cloud_cover"], wind_speed=c["wind_speed"],
271
177
  altitude=c["altitude"], dew_point_temperature=c["dew_point_temperature"],
272
178
  air_pressure_at_sea_level=c["air_pressure_at_sea_level"],
273
179
  ))
274
- r_overcast = asyncio.run(self.atm.magnitude_degradation_11(
180
+ r_overcast = asyncio.run(self.atm.magnitude_degradation(
275
181
  temperature=o["temperature"], humidity=o["humidity"],
276
182
  cloud_cover=o["cloud_cover"], wind_speed=o["wind_speed"],
277
183
  altitude=o["altitude"], dew_point_temperature=o["dew_point_temperature"],
@@ -279,9 +185,9 @@ class TestAtmosphericCalculations(unittest.TestCase):
279
185
  ))
280
186
  self.assertGreater(r_overcast, r_clear)
281
187
 
282
- def test_magnitude_degradation_11_returns_none_on_missing(self):
188
+ def test_magnitude_degradation_returns_none_on_missing(self):
283
189
  c = self.clear
284
- result = asyncio.run(self.atm.magnitude_degradation_11(
190
+ result = asyncio.run(self.atm.magnitude_degradation(
285
191
  temperature=None, humidity=c["humidity"],
286
192
  cloud_cover=c["cloud_cover"], wind_speed=c["wind_speed"],
287
193
  altitude=c["altitude"], dew_point_temperature=c["dew_point_temperature"],