solarmoonpy 0.1.0__tar.gz → 1.0.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: solarmoonpy
3
- Version: 0.1.0
3
+ Version: 1.0.0
4
4
  Summary: Precise solar and lunar calculations for astronomical applications
5
5
  Author-email: figorr <jdcuartero@yahoo.es>
6
6
  License: Apache License
@@ -220,5 +220,18 @@ Description-Content-Type: text/markdown
220
220
  License-File: LICENSE
221
221
  Dynamic: license-file
222
222
 
223
- # solarmoonpy
224
- solar and moon calculations
223
+ # ☀️🌙 solarmoonpy
224
+ Solar and moon calculations for Meteocat Home Assistant integration.
225
+
226
+ **solarmoonpy** is a Python library that provides accurate calculations of solar and lunar positions, specifically designed to integrate with Home Assistant and Meteocat data.
227
+
228
+ This project enables you to obtain information such as sunrise, sunset, moon phases, and more, for advanced automations in your home automation system.
229
+
230
+ ## 🚀 Features
231
+
232
+ - ☀️ Solar position calculations (sunrise, sunset, zenith, etc.).
233
+ - 🌙 Moon phase and position calculations.
234
+ - Integration with meteorological data from Meteocat.
235
+ - Compatible with Home Assistant for automations based on solar and lunar events.
236
+ - Lightweight, easy to use, and well-documented.
237
+ - Configurable for different geographic locations.
@@ -0,0 +1,15 @@
1
+ # ☀️🌙 solarmoonpy
2
+ Solar and moon calculations for Meteocat Home Assistant integration.
3
+
4
+ **solarmoonpy** is a Python library that provides accurate calculations of solar and lunar positions, specifically designed to integrate with Home Assistant and Meteocat data.
5
+
6
+ This project enables you to obtain information such as sunrise, sunset, moon phases, and more, for advanced automations in your home automation system.
7
+
8
+ ## 🚀 Features
9
+
10
+ - ☀️ Solar position calculations (sunrise, sunset, zenith, etc.).
11
+ - 🌙 Moon phase and position calculations.
12
+ - Integration with meteorological data from Meteocat.
13
+ - Compatible with Home Assistant for automations based on solar and lunar events.
14
+ - Lightweight, easy to use, and well-documented.
15
+ - Configurable for different geographic locations.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "solarmoonpy"
7
- version = "0.1.0"
7
+ version = "1.0.0"
8
8
  description = "Precise solar and lunar calculations for astronomical applications"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "figorr", email = "jdcuartero@yahoo.es" }]
@@ -9,11 +9,12 @@ https://github.com/figorr/solarmoonpy
9
9
 
10
10
  # solarmoonpy/__init__.py
11
11
  from .version import __version__
12
- from .moon import moon_phase, moon_rise_set, illuminated_percentage, moon_distance, moon_angular_diameter
12
+ from .moon import moon_phase, moon_day, moon_rise_set, illuminated_percentage, moon_distance, moon_angular_diameter
13
13
  from .location import Location, LocationInfo
14
14
 
15
15
  __all__ = [
16
- "moon_phase",
16
+ "moon_phase",
17
+ "moon_day",
17
18
  "moon_rise_set",
18
19
  "illuminated_percentage",
19
20
  "moon_distance",
@@ -40,6 +40,58 @@ def moon_phase(date_utc: date) -> float:
40
40
  # Promedio ponderado: favorece cálculo preciso, pero usa aproximado como respaldo
41
41
  return round(0.9 * precise_phase + 0.1 * approx_phase, 6)
42
42
 
43
+ def moon_day(date_utc: date, tol_hours: float = 0.01) -> int:
44
+ """
45
+ Calcula el día lunar 0–29 usando la última luna nueva exacta calculada por elongación.
46
+ Usa el fin del día UTC para alinear con convenciones de timeanddate/NASA (etiqueta el día con la fase si ocurre en él).
47
+ tol_hours: precisión en horas.
48
+ """
49
+ dt = datetime(date_utc.year, date_utc.month, date_utc.day, 23, 59, tzinfo=timezone.utc)
50
+
51
+ def elongation(t: datetime) -> float:
52
+ jd = julianday(t.date()) + (t.hour + t.minute/60 + t.second/3600)/24
53
+ jc = julianday_to_juliancentury(jd)
54
+ lambda_m, _, _, _ = _moon_ecliptic_position(jd)
55
+ lambda_s = sun_apparent_long(jc)
56
+ diff = (lambda_m - lambda_s) % 360.0
57
+ if diff > 180:
58
+ diff -= 360
59
+ return diff
60
+
61
+ # Buscar la última luna nueva antes de la fecha
62
+ step = timedelta(hours=6)
63
+ t_back = dt
64
+ prev_el = elongation(t_back)
65
+ for _ in range(int(30*24/6)):
66
+ t_back -= step
67
+ el = elongation(t_back)
68
+ if prev_el > 0 >= el: # cruce 0 hacia abajo indica luna nueva
69
+ break
70
+ prev_el = el
71
+
72
+ # Refinar el momento exacto con bisección
73
+ low = t_back
74
+ high = t_back + step
75
+ while (high - low).total_seconds() / 3600 > tol_hours:
76
+ mid = low + (high - low)/2
77
+ if elongation(mid) > 0:
78
+ high = mid
79
+ else:
80
+ low = mid
81
+ last_new_moon = low + (high - low)/2
82
+
83
+ # Edad lunar en días
84
+ age_days = (dt - last_new_moon).total_seconds() / 86400.0
85
+
86
+ # Día lunar: 0–29, redondeado correctamente
87
+ if age_days < 0:
88
+ day = 0
89
+ else:
90
+ day = int(math.floor(age_days))
91
+ if day > 29:
92
+ day = 29
93
+ return day
94
+
43
95
  def illuminated_percentage(date_utc: date) -> float:
44
96
  """
45
97
  Calcula el porcentaje de luna iluminada para una fecha UTC (versión precisa).
@@ -0,0 +1,2 @@
1
+ # version.py
2
+ __version__ = "1.0.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: solarmoonpy
3
- Version: 0.1.0
3
+ Version: 1.0.0
4
4
  Summary: Precise solar and lunar calculations for astronomical applications
5
5
  Author-email: figorr <jdcuartero@yahoo.es>
6
6
  License: Apache License
@@ -220,5 +220,18 @@ Description-Content-Type: text/markdown
220
220
  License-File: LICENSE
221
221
  Dynamic: license-file
222
222
 
223
- # solarmoonpy
224
- solar and moon calculations
223
+ # ☀️🌙 solarmoonpy
224
+ Solar and moon calculations for Meteocat Home Assistant integration.
225
+
226
+ **solarmoonpy** is a Python library that provides accurate calculations of solar and lunar positions, specifically designed to integrate with Home Assistant and Meteocat data.
227
+
228
+ This project enables you to obtain information such as sunrise, sunset, moon phases, and more, for advanced automations in your home automation system.
229
+
230
+ ## 🚀 Features
231
+
232
+ - ☀️ Solar position calculations (sunrise, sunset, zenith, etc.).
233
+ - 🌙 Moon phase and position calculations.
234
+ - Integration with meteorological data from Meteocat.
235
+ - Compatible with Home Assistant for automations based on solar and lunar events.
236
+ - Lightweight, easy to use, and well-documented.
237
+ - Configurable for different geographic locations.
@@ -1,2 +0,0 @@
1
- # solarmoonpy
2
- solar and moon calculations
@@ -1,2 +0,0 @@
1
- # version.py
2
- __version__ = "0.1.0"
File without changes
File without changes