[docs]deferiksson_1986_humidity(longitude:float,latitude:float,epsg:int=4326):""" Estimate humidity during the vegetation period for Swedish sites. Source: Eriksson, B. (1986). "Nederbörds- och humiditetsklimatet i Sverige under vegetationsperiod." Sveriges Meteorologiska och Hydrologiska Institut (SMHI), rapporter i meteorologi och klimatologi (RMK) 46. Args: latitude (float): Latitude in degrees. longitude (float): Longitude in degrees. epsg (int): Reference system. Default is 4326 (WGS84). For SWEREF99TM, use 3006. Returns: float: Humidity during the vegetation period (mm). """# Validate input for SWEREF99TMifepsg==3006andlongitude>1e6:raiseValueError("Latitude and Longitude appear to be mixed up.")# Locate the humidity shapefile using importlib.resources in a context manager# This is the corrected sectionwithas_file(files("pyforestry.sweden.geo.humidity").joinpath("humidity.shp"))ashumidity_shapefile_path:# Load the humidity shapefilehumidity_gdf=gpd.read_file(humidity_shapefile_path)# Create a GeoDataFrame with the input pointpoint=gpd.GeoDataFrame(geometry=[Point(longitude,latitude)],crs=f"EPSG:{epsg}")# Reproject the point to match the shapefile CRS if neededifepsg!=4326:point=point.to_crs(epsg=4326)# Ensure the humidity shapefile is in the same CRSifhumidity_gdf.crs!=point.crs:humidity_gdf=humidity_gdf.to_crs(epsg=4326)# Perform spatial join to extract humidity valuejoined=gpd.sjoin(point,humidity_gdf,how="left",predicate="intersects")# Extract the humidity valueif"humiditet"injoined.columns:returnjoined.iloc[0]['humiditet']else:raiseValueError("Humidity value could not be determined for the given location.")