pydae 0.57__py3-none-any.whl → 0.57.1__py3-none-any.whl

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.
pydae/__init__.py CHANGED
@@ -7,5 +7,5 @@ Differential Algebraic Equations in Python
7
7
 
8
8
  """
9
9
 
10
- __version__ = "0.57"
10
+ __version__ = "0.57.1"
11
11
 
pydae/utils/dates.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import datetime
2
2
  import pytz
3
- from typing import Optional,List
3
+ from typing import Optional,List,Tuple
4
4
 
5
5
  def get_absolute_hour_of_year_with_dst(month: int, day: int, day_hour: int, year: int, timezone_name: str) -> int:
6
6
  """
@@ -205,18 +205,70 @@ def list_full_hours_between(start_dt: datetime, end_dt: datetime) -> List[dateti
205
205
 
206
206
  return hours_list
207
207
 
208
- def absolute_hours_list(datetime_list,time_zone='Europe/Paris'):
209
-
210
- result_ini = parse_datetime( '1/12/2024 23:00', 'Europe/Paris')
211
- result_end = parse_datetime('31/12/2024 23:00', 'Europe/Paris')
208
+ def absolute_hours_list(date_ini,date_end,time_zone='Europe/Paris'):
212
209
 
210
+ result_ini = parse_datetime(date_ini, time_zone)
211
+ result_end = parse_datetime(date_end, time_zone)
213
212
 
214
213
  hours_list = []
215
214
  for item in list_full_hours_between(result_ini,result_end):
216
215
  hours_list += [datetime_to_hour_of_year(item)]
217
216
 
218
217
  return hours_list
218
+
219
+
220
+
221
+ def hour_index_to_date_components(absolute_hour_index: int, timezone_name: str) -> Optional[Tuple[int, int]]:
222
+ """
223
+ Converts an absolute hour of the year index (0-indexed) to the corresponding
224
+ day of the year and hour of the day, respecting DST rules.
225
+
226
+ Args:
227
+ absolute_hour_index: The 0-indexed hour of the year (e.g., 8759 is the last hour).
228
+ timezone_name: The IANA time zone string (e.g., 'Europe/Madrid').
229
+
230
+ Returns:
231
+ A tuple (day_of_year, hour_of_day) as integers, or None on error.
232
+ """
233
+
234
+ current_year = datetime.datetime.now().year # Use the current year for the calculation
235
+
236
+ try:
237
+ # 1. Define the time zone
238
+ tz = pytz.timezone(timezone_name)
239
+
240
+ # 2. Create the start-of-year time (Jan 1st, 00:00)
241
+ # This is the reference point for hour index 0.
242
+ start_of_year_naive = datetime.datetime(current_year, 1, 1, 0, 0, 0)
219
243
 
244
+ # Localize the start of the year to make it aware
245
+ start_of_year_aware = tz.localize(start_of_year_naive)
246
+
247
+ # 3. Create the time difference
248
+ # Multiplying the hour index by 3600 gives the exact number of seconds
249
+ # that have elapsed since the start_of_year_aware.
250
+ time_difference = datetime.timedelta(hours=absolute_hour_index)
251
+
252
+ # 4. Calculate the target time
253
+ # This addition operation correctly handles DST shifts. If 25 hours have
254
+ # passed since Jan 1st, and one hour was lost due to DST, the target time
255
+ # will only be advanced by 24 clock hours.
256
+ target_time_aware = start_of_year_aware + time_difference
257
+
258
+ # 5. Extract the required components
259
+ # %j gives the 1-indexed day of the year (1-366).
260
+ day_of_year = int(target_time_aware.strftime('%j'))
261
+ hour_of_day = target_time_aware.hour # 0-23
262
+
263
+ return (day_of_year, hour_of_day)
264
+
265
+ except pytz.exceptions.UnknownTimeZoneError:
266
+ print(f"Error: Timezone '{timezone_name}' is not recognized.")
267
+ return None
268
+ except Exception as e:
269
+ print(f"An unexpected error occurred: {e}")
270
+ return None
271
+
220
272
 
221
273
 
222
274
  if __name__ == '__main__':
@@ -229,5 +281,5 @@ if __name__ == '__main__':
229
281
 
230
282
  print(list_full_hours_between(result_ini,result_end))
231
283
 
232
- print(absolute_hours_list('1/12/2024 23:00','1/12/2024 23:00'))
284
+ print(absolute_hours_list('1/1/2024 00:00','31/1/2024 23:00'))
233
285
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydae
3
- Version: 0.57
3
+ Version: 0.57.1
4
4
  Summary: =====
5
5
  Keywords: engineering
6
6
  Author-email: Juan Manuel Mauricio <jmmauricio6@gmail.com>
@@ -1,5 +1,5 @@
1
1
  pydae/.gitignore,sha256=c1jUQV9WXX3PWrlOzHiKvUWFomLJUrfYogbU7nYwAwc,288
2
- pydae/__init__.py,sha256=RO7L59GtEqyO3RIZ2ZKEMR8WFEua04JOz4qlCqq10q4,104
2
+ pydae/__init__.py,sha256=AooVv7ncEnuMOCQXzdgZBl_YmdIa5ILy7R4W22vxoNw,106
3
3
  pydae/b_pu.py,sha256=FdRRVieJLQDYPwYNWhbXJ0SXvf4jtPdbvIZTKWi16I0,6775
4
4
  pydae/bpu.py,sha256=FdRRVieJLQDYPwYNWhbXJ0SXvf4jtPdbvIZTKWi16I0,6775
5
5
  pydae/build.py,sha256=ECfc_doyK9PhrjEAlWJGLfirQmpT24XuYNxUgtrXI74,46151
@@ -735,15 +735,15 @@ pydae/urisi/vsgs/vsg_lpf_ib.hjson,sha256=xpuo5fPCdO5Ze0X-KDCsa_eRpde5f5KDDFoDkWI
735
735
  pydae/urisi/vsgs/vsgs.py,sha256=v17sLm7EaaAyBVJk9-8DnLtxPDtXmkyizFlGhgqyFEE,644
736
736
  pydae/urisi/vsgs/xy_0.json,sha256=Q6qWPIqEP-w5Qu2twd3S4PX4zMggpNpG2W62e7ry70g,851
737
737
  pydae/utils/__init__.py,sha256=kwp76qeU2mnwrCexDSF15id9ih12Q0VRL3l-_c6omcQ,184
738
- pydae/utils/dates.py,sha256=gIJAVlZxLcGoahS_eMzowyqS6a-CUtgWsqpOOIQkl8U,9175
738
+ pydae/utils/dates.py,sha256=wWVhgprZ6Iu8garC8BASKrPWDtXtZY1_ss3iDMLE2mA,11349
739
739
  pydae/utils/ss_num2sym.py,sha256=ZA-x01y1mEWk1HdlpNv9rNspFdH0RBlTq_JRDHmjlpU,3209
740
740
  pydae/utils/svg2pdf.py,sha256=6tNORhlu_cMPDp264Kg3X_eBORfT9Q1cqAcWaWgDs7k,1861
741
741
  pydae/utils/tools.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
742
742
  pydae/utils/types_converter.py,sha256=3eAWwELgG1d6iFX8sn8iGPIp6NBaX4I-eyUriRDOFyE,7929
743
743
  pydae/utils/utils.py,sha256=AI0wZr4PJ3Td3vjfAW06FJdgcK01TpUAukhG37gZP5g,1079
744
744
  pydae/utils/emtp/readPL4.py,sha256=R59KhXTmFrqtdv-9nv5tkdHoTs9uoofGqEfBCF4fGEY,3088
745
- pydae-0.57.dist-info/licenses/COPYING,sha256=QWnWoslbTjQmtlFSRoGF3wxJEJuTJdlEMZ7lHtbGAeQ,1139
746
- pydae-0.57.dist-info/licenses/LICENSE,sha256=8hQe1oM4ySdliF3R-NEvR6HqrcGDKvsLFJC3gA1sNjY,1108
747
- pydae-0.57.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
748
- pydae-0.57.dist-info/METADATA,sha256=RtYLcND2I5k6bKSbUwwBUCnwB8ILrJr7jsEQmLXigjY,1088
749
- pydae-0.57.dist-info/RECORD,,
745
+ pydae-0.57.1.dist-info/licenses/COPYING,sha256=QWnWoslbTjQmtlFSRoGF3wxJEJuTJdlEMZ7lHtbGAeQ,1139
746
+ pydae-0.57.1.dist-info/licenses/LICENSE,sha256=8hQe1oM4ySdliF3R-NEvR6HqrcGDKvsLFJC3gA1sNjY,1108
747
+ pydae-0.57.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
748
+ pydae-0.57.1.dist-info/METADATA,sha256=JFOPnyIcoXWAmiFg-hoAZwyQ_QrkH-hKD45FgPG9vrs,1090
749
+ pydae-0.57.1.dist-info/RECORD,,
File without changes