11"""Docstring for public module."""
22from datetime import datetime , timedelta
3+ from zoneinfo import ZoneInfo
34
45import numpy as np
56
@@ -275,6 +276,8 @@ def _get_paired_data(self, pathname):
275276 unitsDependent2 = ["" ]
276277 typeIndependent2 = ["" ]
277278 typeDependent2 = ["" ]
279+ timeZoneName = ["" ]
280+ timeZoneNameLength = ["" ]
278281 status = self ._native .hec_dss_pdRetrieve (pathname ,
279282 doubleOrdinates , numberOrdinates [0 ],
280283 doubleValues , numberCurves [0 ] * numberOrdinates [0 ],
@@ -283,7 +286,8 @@ def _get_paired_data(self, pathname):
283286 typeIndependent2 , len (typeIndependent [0 ]) + 1 ,
284287 unitsDependent2 , len (unitsDependent [0 ]) + 1 ,
285288 typeDependent2 , len (typeDependent [0 ]) + 1 ,
286- labels , labelsLength [0 ])
289+ labels , labelsLength [0 ],
290+ timeZoneName , len (timeZoneNameLength [0 ]) + 1 )
287291
288292 if status != 0 :
289293 print (f"Error reading paired-data from '{ pathname } '" )
@@ -300,6 +304,7 @@ def _get_paired_data(self, pathname):
300304 pd .type_dependent = typeDependent2 [0 ]
301305 pd .units_independent = unitsIndependent2 [0 ]
302306 pd .units_dependent = unitsDependent2 [0 ]
307+ pd .time_zone_name = timeZoneName [0 ]
303308 pd .id = pathname
304309 pd .location_info = self ._get_location_info (pathname )
305310
@@ -392,6 +397,7 @@ def _get_timeseries(self, pathname, startDateTime, endDateTime, trim):
392397 units = ["" ]
393398 bufferLength = 40
394399 dataType = ["" ]
400+ timeZoneName = ["" ]
395401
396402 status = self ._native .hec_dss_tsRetrieve (
397403 pathname ,
@@ -411,6 +417,8 @@ def _get_timeseries(self, pathname, startDateTime, endDateTime, trim):
411417 bufferLength ,
412418 dataType ,
413419 bufferLength ,
420+ timeZoneName ,
421+ bufferLength
414422 )
415423
416424 # print("units = "+units[0])
@@ -453,8 +461,11 @@ def _get_timeseries(self, pathname, startDateTime, endDateTime, trim):
453461 start_date = [] if len (new_times ) == 0 else new_times [0 ]
454462 time_granularity_seconds = timeGranularitySeconds [0 ]
455463 julian_base_date = julianBaseDate [0 ]
464+ timeZoneName = timeZoneName [0 ]
465+ if (timeZoneName ):
466+ new_times = [i .replace (tzinfo = ZoneInfo (timeZoneName )) for i in new_times ]
456467 location_info = self ._get_location_info (pathname )
457- ts = ts .create (values = values , times = new_times , quality = quality , units = units , data_type = data_type , start_date = start_date , time_granularity_seconds = time_granularity_seconds , julian_base_date = julian_base_date , path = pathname , location_info = location_info )
468+ ts = ts .create (values = values , times = new_times , quality = quality , units = units , data_type = data_type , start_date = start_date , time_granularity_seconds = time_granularity_seconds , julian_base_date = julian_base_date , time_zone_name = timeZoneName , path = pathname , location_info = location_info )
458469 return ts
459470
460471 def _get_location_info (self , pathname : str ):
@@ -544,6 +555,8 @@ def put(self, container) -> int:
544555 False ,
545556 ts .units ,
546557 ts .data_type ,
558+ ts .time_zone_name ,
559+ 0
547560 )
548561 self ._catalog = None
549562 elif type (container ) is IrregularTimeSeries :
@@ -567,6 +580,8 @@ def put(self, container) -> int:
567580 False ,
568581 its .units ,
569582 its .data_type ,
583+ its .time_zone_name ,
584+ 1
570585 )
571586 self ._catalog = None
572587 elif type (container ) is PairedData :
@@ -600,6 +615,91 @@ def put(self, container) -> int:
600615
601616 return status
602617
618+ def delete (self , pathname : str , allrecords : bool = False , startdatetime = None , enddatetime = None ) -> int :
619+ """deletes a record from the DSS file
620+ Args:
621+ pathname (str): dss pathname, if only the pathname is provided, delete only the record with this pathname
622+ allRecords (bool): if True, delete all records with this pathname that have different dates
623+ startdatetime (datetime): start date for query, if only start date is provided, delete all records at or after this date
624+ enddatetime (datetime): end date for the query, if only end date is provided, delete all records at or before this date
625+ Returns:
626+ int: status of zero when successful. Non zero for errors.
627+ """
628+ rt = self .get_record_type (pathname )
629+ delete_path = DssPath (pathname )
630+ if (rt == RecordType .RegularTimeSeries or rt == RecordType .IrregularTimeSeries ) and allrecords :
631+ for i in self .get_catalog ().uncondensed_paths :
632+ uncondensed_path = DssPath (i )
633+ if uncondensed_path .path_without_date ().__eq__ (delete_path .path_without_date ()):
634+ status = self ._native .hec_dss_delete (i )
635+ if status == 0 :
636+ self ._catalog = None
637+ elif rt == RecordType .RegularTimeSeries and (startdatetime or enddatetime ):
638+ newStartDateTime , newEndDateTime = self ._get_date_time_range (pathname , 1 )
639+ if startdatetime :
640+ newStartDateTime = startdatetime
641+ if enddatetime :
642+ newEndDateTime = enddatetime
643+
644+ interval_seconds = DateConverter .intervalString_to_sec (delete_path .E )
645+
646+ firstMinutes = DateConverter .julian_array_from_date_times ([newStartDateTime ])[0 ]
647+ firstSeconds , firstJulian = [firstMinutes % 1440 * 60 ], [firstMinutes // 1440 ]
648+
649+ lastMinutes = DateConverter .julian_array_from_date_times ([newEndDateTime ])[0 ]
650+ lastSeconds , lastJulian = [lastMinutes % 1440 * 60 ], [lastMinutes // 1440 ]
651+
652+ number_periods = self ._native .hec_dss_numberPeriods (
653+ interval_seconds ,
654+ firstJulian [0 ],
655+ firstSeconds [0 ],
656+ lastJulian [0 ],
657+ lastSeconds [0 ],
658+ )
659+
660+ RTS = RegularTimeSeries ()
661+ RTS .values = [DSS_UNDEFINED_VALUE ]* number_periods
662+ RTS .times = [newStartDateTime , newEndDateTime ]
663+ RTS .start_date = startdatetime
664+ RTS .id = pathname
665+
666+ startDate , startTime = DateConverter .dss_datetime_strings_from_datetime (RTS .times [0 ])
667+
668+ status = self ._native .hec_dss_tsStoreRegular (
669+ RTS .id ,
670+ startDate ,
671+ startTime ,
672+ RTS .values ,
673+ RTS .quality ,
674+ False ,
675+ RTS .units ,
676+ RTS .data_type ,
677+ RTS .time_zone_name ,
678+ 3
679+ )
680+ self ._catalog = None
681+ elif rt == RecordType .IrregularTimeSeries and (startdatetime or enddatetime ):
682+ newStartDateTime , newEndDateTime = self ._get_date_time_range (pathname , 1 )
683+ if startdatetime :
684+ newStartDateTime = startdatetime
685+ if enddatetime :
686+ newEndDateTime = enddatetime
687+
688+ IRTS = IrregularTimeSeries ()
689+ IRTS .values = [DSS_UNDEFINED_VALUE , DSS_UNDEFINED_VALUE ]
690+ IRTS .times = [newStartDateTime , newEndDateTime ]
691+ IRTS .start_date = startdatetime
692+ IRTS .id = pathname
693+
694+ dss .put (IRTS )
695+ else :
696+ status = self ._native .hec_dss_delete (pathname )
697+ if status == 0 :
698+ self ._catalog = None
699+ else :
700+ print (f"Error deleting record from '{ pathname } ', Record does not exist or timeseries path must be uncondensed" )
701+ return status
702+
603703 def get_catalog (self ) -> Catalog :
604704 """gets the DSS Catalog of all items in the DSS file
605705
0 commit comments