@@ -665,3 +665,57 @@ def read_pvgis_tmy(filename, pvgis_format=None, map_variables=None):
665
665
data = data .rename (columns = VARIABLE_MAP )
666
666
667
667
return data , months_selected , inputs , meta
668
+
669
+
670
+ def get_pvgis_horizon (latitude , longitude , url = URL , ** kwargs ):
671
+ """Get horizon data from PVGIS.
672
+
673
+ Parameters
674
+ ----------
675
+ latitude : float
676
+ Latitude in degrees north
677
+ longitude : float
678
+ Longitude in degrees east
679
+ url: str, default: :const:`pvlib.iotools.pvgis.URL`
680
+ Base URL for PVGIS
681
+ kwargs:
682
+ Passed to requests.get
683
+
684
+ Returns
685
+ -------
686
+ data : pd.Series
687
+ Pandas Series of the retrived horizon elevation angles. Index is the
688
+ corresponding horizon azimuth angles.
689
+ metadata : dict
690
+ Metadata returned by PVGIS.
691
+
692
+ Notes
693
+ -----
694
+ The horizon azimuths are specified clockwise from north, e.g., south=180.
695
+ This is the standard pvlib convention, although the PVGIS website specifies
696
+ south=0.
697
+
698
+ References
699
+ ----------
700
+ .. [1] `PVGIS horizon profile tool
701
+ <https://ec.europa.eu/jrc/en/PVGIS/tools/horizon>`_
702
+ """
703
+ params = {'lat' : latitude , 'lon' : longitude , 'outputformat' : 'json' }
704
+ res = requests .get (url + 'printhorizon' , params = params , ** kwargs )
705
+ if not res .ok :
706
+ try :
707
+ err_msg = res .json ()
708
+ except Exception :
709
+ res .raise_for_status ()
710
+ else :
711
+ raise requests .HTTPError (err_msg ['message' ])
712
+ json_output = res .json ()
713
+ metadata = json_output ['meta' ]
714
+ data = pd .DataFrame (json_output ['outputs' ]['horizon_profile' ])
715
+ data .columns = ['horizon_azimuth' , 'horizon_elevation' ]
716
+ # Convert azimuth to pvlib convention (north=0, south=180)
717
+ data ['horizon_azimuth' ] += 180
718
+ data .set_index ('horizon_azimuth' , inplace = True )
719
+ data = data ['horizon_elevation' ] # convert to pd.Series
720
+ data = data [data .index < 360 ] # remove duplicate north point (0 and 360)
721
+ return data , metadata
0 commit comments