Skip to content

Commit

Permalink
Meteostat 1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
clampr committed Jun 19, 2021
1 parent dee4399 commit 246b321
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/normals/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from meteostat import Normals

# Get normals
data = Normals('10637')
data = data.fetch()
data = Normals('72407')
data = data.normalize().fetch()

# Plot chart
data.plot(y=['tavg', 'tmin', 'tmax'])
Expand Down
2 changes: 1 addition & 1 deletion meteostat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

__appname__ = 'meteostat'
__version__ = '1.4.2'
__version__ = '1.4.3'

from .interface.stations import Stations
from .interface.point import Point
Expand Down
38 changes: 38 additions & 0 deletions meteostat/interface/normals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pandas as pd
from meteostat.core.cache import get_file_path, file_in_cache
from meteostat.core.loader import processing_handler, load_handler
from meteostat.core.warn import warn
from meteostat.utilities.aggregations import weighted_average
from meteostat.interface.base import Base
from meteostat.interface.point import Point
Expand Down Expand Up @@ -249,6 +250,43 @@ def __init__(
if self.max_age > 0:
self.clear_cache()

def normalize(self):
"""
Normalize the DataFrame
"""

# Create temporal instance
temp = copy(self)

if self.count() == 0:
warn('Pointless normalization of empty DataFrame')

else:
# Go through list of weather stations
for station in temp._stations:
# Get periods
periods = temp._data[temp._data.index.get_level_values(
'station') == station].index.unique('end')
# Go through all periods
for period in periods:
# Create DataFrame
df = pd.DataFrame(
columns=temp._columns[temp._first_met_col:])
# Populate index columns
df['month'] = range(1, 13)
df['station'] = station
df['start'] = period - 29
df['end'] = period
# Set index
df.set_index(
['station', 'start', 'end', 'month'], inplace=True)
# Merge data
temp._data = pd.concat([temp._data, df], axis=0).groupby(
['station', 'start', 'end', 'month'], as_index=True).first()

# Return class instance
return temp

def fetch(self) -> pd.DataFrame:
"""
Fetch DataFrame
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Setup
setup(
name='meteostat',
version='1.4.2',
version='1.4.3',
author='Meteostat',
author_email='[email protected]',
description='Access and analyze historical weather and climate data with Python.',
Expand Down

0 comments on commit 246b321

Please sign in to comment.