Skip to content

Commit

Permalink
Finalize 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
clampr committed Oct 15, 2020
1 parent ff6df8d commit 2f0de84
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Meteostat Python library provides a simple API for accessing open weather an
## Installation
The Meteostat Python package is available through PyPI:
```
pip install
pip install meteostat
```

## Documentation
Expand Down Expand Up @@ -35,7 +35,7 @@ data.plot(x = 'time', y = ['tavg', 'tmin', 'tmax'], kind = 'line')
plt.show()
```
Take a look at the expected output:
![2018 temperature data for Vancouver, BC](examples/daily/chart.png)
![2018 temperature data for Vancouver, BC](https://raw.githubusercontent.com/meteostat/meteostat-python/master/examples/daily/chart.png)

## Contributing
Instructions on building and testing the Meteostat Python package can be found in the [documentation](https://github.com/meteostat/meteostat-python/wiki/Contributing). More information about the Meteostat bulk data interface can be found [here](https://dev.meteostat.net/bulk).
Expand Down
2 changes: 1 addition & 1 deletion examples/daily/aggregation_regional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
import matplotlib.pyplot as plt

stations = Stations(country = 'US', daily = datetime(2005, 1, 1)).sample(50).fetch()
stations = Stations(country = 'US', daily = datetime(2005, 1, 1)).sample(5).fetch()

data = Daily(stations, start = datetime(1980, 1, 1), end = datetime(2019, 12, 31))
data = data.normalize().aggregate(freq = '1Y', spatial = True).fetch()
Expand Down
9 changes: 9 additions & 0 deletions examples/hourly/aggregation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from meteostat import Stations, Hourly
from datetime import datetime

# Hourly
stations = Stations(wmo = '10637')
station = stations.fetch(1)

data = Hourly(station, start = datetime(2020, 1, 1), end = datetime(2020, 1, 1, 23, 59)).aggregate(freq = '1D')
print(data.fetch())
2 changes: 1 addition & 1 deletion meteostat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

__appname__ = "meteostat"
__version__ = "0.1"
__version__ = "0.1.0"

from .core import Core
from .stations import Stations
Expand Down
2 changes: 1 addition & 1 deletion meteostat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def clear_cache(self, max_age = None):
# Delete file
os.remove(path)

def copy(self):
def clone(self):

# Return copy of class instance
return copy(self)
2 changes: 1 addition & 1 deletion meteostat/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Daily(Core):
# Columns for date parsing
_parse_dates = { 'time': [0] }

# Default aggregations
# Default aggregation functions
_aggregations = {
'time': 'first',
'tavg': 'mean',
Expand Down
34 changes: 33 additions & 1 deletion meteostat/hourly.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ class Hourly(Core):
# Columns for date parsing
_parse_dates = { 'time': [0, 1] }

# Default aggregation functions
_aggregations = {
'time': 'first',
'temp': 'mean',
'dwpt': 'mean',
'rhum': 'mean',
'prcp': 'sum',
'snow': 'mean',
'wdir': 'mean',
'wspd': 'mean',
'wpgt': 'max',
'pres': 'mean',
'tsun': 'sum',
'coco': 'max'
}

def _get_data(self, stations = None):

if len(stations.index) > 0:
Expand Down Expand Up @@ -148,6 +164,22 @@ def interpolate(self, limit = 3):
# Return self
return self

def aggregate(self, freq = None, functions = None, spatial = False):

# Update default aggregations
if functions is not None:
self._aggregations.update(functions)

# Time aggregation
self._data = self._data.groupby(['station', pd.Grouper(key = 'time', freq = freq)]).agg(self._aggregations)

# Spatial aggregation
if spatial:
self._data = self._data.groupby([pd.Grouper(key = 'time', freq = freq)]).mean()

# Return self
return self

def coverage(self, parameter = None):

expect = floor((self._end - self._start).total_seconds() / 3600) + 1
Expand All @@ -160,4 +192,4 @@ def coverage(self, parameter = None):
def fetch(self):

# Return data frame
return copy(self.data)
return copy(self._data)
30 changes: 16 additions & 14 deletions meteostat/stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ class Stations(Core):
'name',
'country',
'region',
'national',
'wmo',
'icao',
'latitude',
'longitude',
'altitude',
'elevation',
'timezone',
'hourly_start',
'hourly_end',
Expand All @@ -40,7 +39,7 @@ class Stations(Core):
]

# Columns for date parsing
_parse_dates = [11, 12, 13, 14]
_parse_dates = [10, 11, 12, 13]

def __init__(
self,
Expand Down Expand Up @@ -104,24 +103,27 @@ def _identifier(self, id = None, wmo = None, icao = None):

# Get station by Meteostat ID
if id != None:
if isinstance(id, list):
self._stations = self._stations[self._stations['id'].isin(id)]
else:
self._stations = self._stations[self._stations['id'] == id]

if not isinstance(id, list):
id = [id]

self._stations = self._stations[self._stations['id'].isin(id)]

# Get station by WMO ID
elif wmo != None:
if isinstance(wmo, list):
self._stations = self._stations[self._stations['wmo'].isin(wmo)]
else:
self._stations = self._stations[self._stations['wmo'] == wmo]

if not isinstance(wmo, list):
wmo = [wmo]

self._stations = self._stations[self._stations['wmo'].isin(wmo)]

# Get stations by ICAO ID
elif icao != None:

if isinstance(icao, list):
self._stations = self._stations[self._stations['icao'].isin(icao)]
else:
self._stations = self._stations[self._stations['icao'] == icao]
icao = [icao]

self._stations = self._stations[self._stations['icao'] == icao]

# Return self
return self
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pandas==1.1.0
pyarrow==1.0.0
pandas>=1.1.0
pyarrow>=1.0.0
39 changes: 25 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import setuptools
from os import path
from setuptools import setup, find_packages

setuptools.setup(
name='meteostat',
version='0.1',
author="Meteostat",
author_email="[email protected]",
description="A Python library for working with weather and climate data.",
url="https://dev.meteostat.net",
packages=setuptools.find_packages(),
install_requires=["pandas", "pyarrow"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
# Content of the README file
here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md')) as f:
long_description = f.read()

# Setup
setup(
name = 'meteostat',
version = '0.1.0',
author = 'Meteostat',
author_email = '[email protected]',
description = 'Access and analyze historical weather and climate data with Python.',
long_description = long_description,
long_description_content_type = 'text/markdown',
url = 'https://github.com/meteostat/meteostat-python',
packages = find_packages(),
include_package_data = True,
install_requires = ['pandas', 'pyarrow'],
license = 'MIT',
classifiers = [
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
],
)

0 comments on commit 2f0de84

Please sign in to comment.