test_models.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #******************************************************************************
  2. #******************************************************************************
  3. # import libraries
  4. from math import isclose, pi
  5. import datetime as dt
  6. from src.pysoleng.models import tilted_plane_irradiance_isotropic
  7. from src.pysoleng.timeplace import Location, FlatSurface
  8. # *****************************************************************************
  9. # *****************************************************************************
  10. class TestIrradianceModels:
  11. def test_isotropic_model(self):
  12. # *********************************************************************
  13. # *********************************************************************
  14. # Example 2.15.1, page
  15. # Using the isotropic diffuse model, estimate the beam, diffuse, and
  16. # ground-reflected components of solar radiation and the total radiation
  17. # on a surface sloped 60◦ toward the south at a latitude of 40◦ N for
  18. # the hour 9 to 10 AM on February 20. Here I = 1.04 MJ/m2 and ρ_g = 0.6
  19. # >>> from datetime import datetime
  20. # >>> datetime.fromisoformat('2011-11-04T00:05:23+04:00')
  21. site_ground_reflectance = 0.6
  22. site_horizontal_total = 1.04 # MJ/m2
  23. site_horizontal_diffuse = site_horizontal_total*0.766 # kt=0.445
  24. surface = FlatSurface(
  25. azimuth=0*pi/180,
  26. slope=60*pi/180
  27. )
  28. site = Location(
  29. coordinates=(40,0),
  30. crs_string='epsg:4326')
  31. local_time = dt.datetime.fromisoformat('2011-02-20 09:30:00+00:00')
  32. # final results (expected)
  33. efr_itt = 1.17 # MJ/m2 # original: 1.170
  34. efr_itt_tol = 0.01 # MJ/m2
  35. efr_itb = 0.417 # MJ/m2
  36. efr_itb_tol = 0.01 # MJ/m2
  37. efr_itsd = 0.596 # MJ/m2
  38. efr_itsd_tol = 0.01 # MJ/m2
  39. efr_ita = 0.156 # MJ/m2
  40. efr_ita_tol = 0.01 # MJ/m2
  41. # *********************************************************************
  42. # *********************************************************************
  43. (I_tilted_total,
  44. I_tilted_beam,
  45. I_tilted_sky_diffuse,
  46. I_tilted_albedo) = tilted_plane_irradiance_isotropic(
  47. site,
  48. #surface,
  49. surface.slope,
  50. surface.azimuth,
  51. local_time,
  52. site_ground_reflectance,
  53. site_horizontal_total,
  54. site_horizontal_diffuse)
  55. # *********************************************************************
  56. # *********************************************************************
  57. # total
  58. assert isclose(I_tilted_total, efr_itt, abs_tol=efr_itt_tol)
  59. # beam
  60. assert isclose(I_tilted_beam, efr_itb, abs_tol=efr_itb_tol)
  61. # sky diffuse
  62. assert isclose(I_tilted_sky_diffuse, efr_itsd, abs_tol=efr_itsd_tol)
  63. # albedo
  64. assert isclose(I_tilted_albedo, efr_ita, abs_tol=efr_ita_tol)
  65. # *********************************************************************
  66. # *********************************************************************
  67. # *****************************************************************************
  68. # *****************************************************************************