Skip to content

Commit 246b321

Browse files
committed
Meteostat 1.4.3
1 parent dee4399 commit 246b321

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

examples/normals/simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from meteostat import Normals
1313

1414
# Get normals
15-
data = Normals('10637')
16-
data = data.fetch()
15+
data = Normals('72407')
16+
data = data.normalize().fetch()
1717

1818
# Plot chart
1919
data.plot(y=['tavg', 'tmin', 'tmax'])

meteostat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313

1414
__appname__ = 'meteostat'
15-
__version__ = '1.4.2'
15+
__version__ = '1.4.3'
1616

1717
from .interface.stations import Stations
1818
from .interface.point import Point

meteostat/interface/normals.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pandas as pd
1616
from meteostat.core.cache import get_file_path, file_in_cache
1717
from meteostat.core.loader import processing_handler, load_handler
18+
from meteostat.core.warn import warn
1819
from meteostat.utilities.aggregations import weighted_average
1920
from meteostat.interface.base import Base
2021
from meteostat.interface.point import Point
@@ -249,6 +250,43 @@ def __init__(
249250
if self.max_age > 0:
250251
self.clear_cache()
251252

253+
def normalize(self):
254+
"""
255+
Normalize the DataFrame
256+
"""
257+
258+
# Create temporal instance
259+
temp = copy(self)
260+
261+
if self.count() == 0:
262+
warn('Pointless normalization of empty DataFrame')
263+
264+
else:
265+
# Go through list of weather stations
266+
for station in temp._stations:
267+
# Get periods
268+
periods = temp._data[temp._data.index.get_level_values(
269+
'station') == station].index.unique('end')
270+
# Go through all periods
271+
for period in periods:
272+
# Create DataFrame
273+
df = pd.DataFrame(
274+
columns=temp._columns[temp._first_met_col:])
275+
# Populate index columns
276+
df['month'] = range(1, 13)
277+
df['station'] = station
278+
df['start'] = period - 29
279+
df['end'] = period
280+
# Set index
281+
df.set_index(
282+
['station', 'start', 'end', 'month'], inplace=True)
283+
# Merge data
284+
temp._data = pd.concat([temp._data, df], axis=0).groupby(
285+
['station', 'start', 'end', 'month'], as_index=True).first()
286+
287+
# Return class instance
288+
return temp
289+
252290
def fetch(self) -> pd.DataFrame:
253291
"""
254292
Fetch DataFrame

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Setup
1616
setup(
1717
name='meteostat',
18-
version='1.4.2',
18+
version='1.4.3',
1919
author='Meteostat',
2020
author_email='[email protected]',
2121
description='Access and analyze historical weather and climate data with Python.',

0 commit comments

Comments
 (0)