mabuseif commited on
Commit
0044cdb
·
verified ·
1 Parent(s): 37a4af2

Upload 2 files

Browse files
Files changed (1) hide show
  1. data/ashrae_tables.py +74 -0
data/ashrae_tables.py CHANGED
@@ -499,6 +499,41 @@ class ASHRAETables:
499
 
500
  def get_cltd_roof(self, roof_group: str, latitude: str, hour: int) -> float:
501
  """Get CLTD value for a roof."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  key = f"{roof_group}_{latitude}"
503
  if key not in self.cltd_roof:
504
  raise ValueError(f"Invalid roof group or latitude: {key}")
@@ -508,6 +543,45 @@ class ASHRAETables:
508
 
509
  def get_scl(self, latitude: str, month: str, orientation: str, hour: int) -> float:
510
  """Get SCL value for a window."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  key = f"{latitude}_{month}"
512
  if key not in self.scl:
513
  raise ValueError(f"Invalid latitude or month: {key}")
 
499
 
500
  def get_cltd_roof(self, roof_group: str, latitude: str, hour: int) -> float:
501
  """Get CLTD value for a roof."""
502
+ # Map latitude to standard format before forming the key
503
+ valid_latitudes = ['24N', '36N', '48N']
504
+
505
+ # Handle numeric or non-standard latitude values
506
+ if latitude not in valid_latitudes:
507
+ # Try to convert to standard format
508
+ try:
509
+ # First, handle string representations that might contain direction indicators
510
+ if isinstance(latitude, str):
511
+ # Extract numeric part, removing 'N' or 'S'
512
+ lat_str = latitude.upper().strip()
513
+ num_part = ''.join(c for c in lat_str if c.isdigit() or c == '.')
514
+ lat_val = float(num_part)
515
+
516
+ # Adjust for southern hemisphere if needed
517
+ if 'S' in lat_str:
518
+ lat_val = -lat_val
519
+ else:
520
+ # Handle direct numeric input
521
+ lat_val = float(latitude)
522
+
523
+ # Take absolute value for mapping purposes
524
+ abs_lat = abs(lat_val)
525
+
526
+ # Map to the closest standard latitude for roof data
527
+ if abs_lat < 30:
528
+ latitude = '24N'
529
+ elif abs_lat < 42:
530
+ latitude = '36N'
531
+ else:
532
+ latitude = '48N'
533
+
534
+ except (ValueError, TypeError):
535
+ raise ValueError(f"Invalid latitude format: {latitude}")
536
+
537
  key = f"{roof_group}_{latitude}"
538
  if key not in self.cltd_roof:
539
  raise ValueError(f"Invalid roof group or latitude: {key}")
 
543
 
544
  def get_scl(self, latitude: str, month: str, orientation: str, hour: int) -> float:
545
  """Get SCL value for a window."""
546
+ # Map latitude to standard format before forming the key
547
+ valid_latitudes = ['24N', '32N', '40N', '48N', '56N']
548
+
549
+ # Handle numeric or non-standard latitude values
550
+ if latitude not in valid_latitudes:
551
+ # Try to convert to standard format
552
+ try:
553
+ # First, handle string representations that might contain direction indicators
554
+ if isinstance(latitude, str):
555
+ # Extract numeric part, removing 'N' or 'S'
556
+ lat_str = latitude.upper().strip()
557
+ num_part = ''.join(c for c in lat_str if c.isdigit() or c == '.')
558
+ lat_val = float(num_part)
559
+
560
+ # Adjust for southern hemisphere if needed
561
+ if 'S' in lat_str:
562
+ lat_val = -lat_val
563
+ else:
564
+ # Handle direct numeric input
565
+ lat_val = float(latitude)
566
+
567
+ # Take absolute value for mapping purposes
568
+ abs_lat = abs(lat_val)
569
+
570
+ # Map to the closest standard latitude for SCL data
571
+ if abs_lat < 28:
572
+ latitude = '24N'
573
+ elif abs_lat < 36:
574
+ latitude = '32N'
575
+ elif abs_lat < 44:
576
+ latitude = '40N'
577
+ elif abs_lat < 52:
578
+ latitude = '48N'
579
+ else:
580
+ latitude = '56N'
581
+
582
+ except (ValueError, TypeError):
583
+ raise ValueError(f"Invalid latitude format: {latitude}")
584
+
585
  key = f"{latitude}_{month}"
586
  if key not in self.scl:
587
  raise ValueError(f"Invalid latitude or month: {key}")