Skip to content

Commit

Permalink
Update Readme and removes debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
FL550 committed Sep 4, 2024
1 parent af3989d commit 0358876
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,50 @@ class WeatherBackgroundMapType(Enum):
GEMEINDEN = "dwd:Warngebiete_Gemeinden"
SATELLIT = "dwd:bluemarble"

def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height) #Returns map as pillow image with given radius from coordinates
get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height) #Returns map as pillow image with given radius from coordinates

get_germany(map_type: WeatherMapType, optional WeatherBackgroundMapType background_type, optional integer image_width, optional integer image_height, optional string save_to_filename) #Returns map as pillow image of whole germany

get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height, optional string save_to_filename) #Returns map as pillow image
```


### Image loop

There is also the possibility to retrieve multiple images as a loop. This can be done by the class ImageLoop.


#### Usage example
```python
from simple_dwd_weatherforecast import dwdmap

maploop = dwdmap.ImageLoop(
dwdmap.germany_boundaries.minx,
dwdmap.germany_boundaries.miny,
dwdmap.germany_boundaries.maxx,
dwdmap.germany_boundaries.maxy,
dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR,
dwdmap.WeatherBackgroundMapType.BUNDESLAENDER,
steps=5,
)

for image in enumerate(maploop._images):
image[1].save(f"image{image[0]}.png")

```

#### Available methods

```python
ImageLoop(minx: float, miny: float, maxx: float, maxy: float, map_type: WeatherMapType, background_type: WeatherBackgroundMapType,
steps: int = 6, image_width: int = 520,image_height: int = 580) -> ImageLoop

get_images() -> Iterable[ImageFile.ImageFile] # Returns the image loop

update() # Updates the loop to the most recent files

```

## Help and Contribution

Feel free to open an issue if you find one and I will do my best to help you. If you want to contribute, your help is appreciated! If you want to add a new feature, add a pull request first so we can chat about the details.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="simple_dwd_weatherforecast",
version="2.0.34",
version="2.1.0",
author="Max Fermor",
description="A simple tool to retrieve a weather forecast from DWD OpenData",
long_description=long_description,
Expand Down
6 changes: 2 additions & 4 deletions simple_dwd_weatherforecast/dwdmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,17 @@ def _full_reload(self):
def update(self):
now = get_time_last_5_min(datetime.now(timezone.utc))

# wenn last update länger her als buffer, dann lade alles neu
# If last update is older than the buffer can hold, reload the whole buffer
if now - self._last_update > self._steps * timedelta(minutes=5):
self._full_reload()
# wenn last update innerhalb des buffers ist, dann lade die bilder vom ältesten zum neuesten neu in den buffer
# Update the buffer and fetch only the new images
else:
while now > self._last_update:
self._last_update += timedelta(minutes=5)
self._images.append(self._get_image(self._last_update))

def _get_image(self, date: datetime) -> ImageFile.ImageFile:
print(f"{date.strftime('%Y-%m-%dT%H:%M:00.0Z')}")
url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.0&request=GetMap&layers={self._map_type.value},{self._background_type.value}&bbox={self._minx},{self._miny},{self._maxx},{self._maxy}&width={self._image_width}&height={self._image_height}&srs=EPSG:4326&styles=&format=image/png&TIME={date.strftime("%Y-%m-%dT%H:%M:00.0Z")}"
print(url)
request = requests.get(url, stream=True)
if request.status_code != 200:
raise ConnectionError("Error during image request from DWD servers")
Expand Down

0 comments on commit 0358876

Please sign in to comment.