or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

agro.mdair-pollution.mdalerts.mdgeocoding.mdindex.mdstations.mdtiles.mduv-index.mdweather.md

stations.mddocs/

0

# Weather Stations

1

2

Personal weather station management for creating, updating stations and sending/retrieving measurement data. Enables users to create their own weather monitoring network and contribute data to OpenWeatherMap.

3

4

## Capabilities

5

6

### Station Management

7

8

```python { .api }

9

class StationsManager:

10

def stations_api_version(self) -> tuple:

11

"""

12

Get Stations API version.

13

14

Returns:

15

Tuple representing the API version

16

"""

17

18

def create_station(self, external_id: str, name: str, lat: float, lon: float, alt: float = None) -> Station:

19

"""

20

Create a new weather station.

21

22

Parameters:

23

- external_id: User-defined station identifier

24

- name: Station name

25

- lat: Latitude (-90.0 to 90.0)

26

- lon: Longitude (-180.0 to 180.0)

27

- alt: Altitude in meters (optional, must be >= 0)

28

29

Returns:

30

Station object representing the created station

31

"""

32

33

def get_stations(self) -> List[Station]:

34

"""Get all user stations."""

35

36

def get_station(self, id: str) -> Station:

37

"""Get specific station by ID."""

38

39

def update_station(self, station: Station) -> None:

40

"""Update station information."""

41

42

def delete_station(self, station: Station) -> None:

43

"""Delete a station."""

44

```

45

46

### Measurement Management

47

48

```python { .api }

49

class StationsManager:

50

def send_measurement(self, measurement: Measurement) -> None:

51

"""Send single measurement to a station."""

52

53

def send_measurements(self, list_of_measurements: List[Measurement]) -> None:

54

"""Send multiple measurements to stations."""

55

56

def get_measurements(self, station_id: str, aggregated_on: str, from_timestamp: int,

57

to_timestamp: int, limit: int = 100) -> List[AggregatedMeasurement]:

58

"""

59

Retrieve aggregated measurements from a station.

60

61

Parameters:

62

- station_id: Station ID

63

- aggregated_on: 'm' (minute), 'h' (hour), 'd' (day)

64

- from_timestamp: Start time (UNIX timestamp)

65

- to_timestamp: End time (UNIX timestamp)

66

- limit: Maximum number of results (default 100)

67

68

Returns:

69

List of AggregatedMeasurement objects

70

"""

71

72

def send_buffer(self, buffer: Buffer) -> None:

73

"""Send buffered measurements."""

74

```

75

76

## Usage Examples

77

78

```python

79

from pyowm import OWM

80

from pyowm.stationsapi30.measurement import Measurement

81

from datetime import datetime

82

83

owm = OWM('your-api-key')

84

stations_mgr = owm.stations_manager()

85

86

# Create a weather station

87

station = stations_mgr.create_station(

88

external_id='my_station_001',

89

name='Home Weather Station',

90

lat=40.7128,

91

lon=-74.0060,

92

alt=10.0 # 10 meters above sea level

93

)

94

95

print(f"Created station: {station.name} (ID: {station.id})")

96

97

# Send weather measurement

98

measurement = Measurement(

99

station_id=station.id,

100

timestamp=int(datetime.now().timestamp()),

101

temperature=22.5,

102

humidity=65,

103

pressure=1013.25,

104

wind_speed=5.2,

105

wind_deg=270,

106

rain_1h=0.0

107

)

108

109

stations_mgr.send_measurement(measurement)

110

print("Measurement sent successfully")

111

112

# Retrieve measurements

113

from_time = int((datetime.now() - timedelta(days=1)).timestamp())

114

to_time = int(datetime.now().timestamp())

115

116

measurements = stations_mgr.get_measurements(

117

station_id=station.id,

118

aggregated_on='h', # Hourly aggregation

119

from_timestamp=from_time,

120

to_timestamp=to_time

121

)

122

123

print(f"Retrieved {len(measurements)} hourly measurements")

124

for measurement in measurements[-5:]: # Last 5 measurements

125

print(f"Time: {measurement.creation_time('iso')}")

126

if measurement.temp:

127

print(f" Temperature: {measurement.temp['avg']}°C")

128

if measurement.humidity:

129

print(f" Humidity: {measurement.humidity['avg']}%")

130

```

131

132

## Data Types

133

134

```python { .api }

135

class Station:

136

def __init__(self, id: str, created_at: str, updated_at: str, external_id: str,

137

name: str, lon: float, lat: float, alt: float, rank: int): ...

138

139

def creation_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...

140

def last_update_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...

141

142

@property

143

def id(self) -> str: ...

144

@property

145

def external_id(self) -> str: ...

146

@property

147

def name(self) -> str: ...

148

@property

149

def lon(self) -> float: ...

150

@property

151

def lat(self) -> float: ...

152

@property

153

def alt(self) -> float: ...

154

@property

155

def rank(self) -> int: ...

156

157

class Measurement:

158

def __init__(self, station_id: str, timestamp: int, **kwargs): ...

159

160

def creation_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...

161

def to_JSON(self) -> str: ...

162

163

@property

164

def station_id(self) -> str: ...

165

@property

166

def timestamp(self) -> int: ...

167

# Weather parameters (all optional)

168

@property

169

def temperature(self) -> Union[float, None]: ...

170

@property

171

def wind_speed(self) -> Union[float, None]: ...

172

@property

173

def wind_gust(self) -> Union[float, None]: ...

174

@property

175

def wind_deg(self) -> Union[float, None]: ...

176

@property

177

def pressure(self) -> Union[float, None]: ...

178

@property

179

def humidity(self) -> Union[int, None]: ...

180

# Precipitation parameters

181

@property

182

def rain_1h(self) -> Union[float, None]: ...

183

@property

184

def rain_6h(self) -> Union[float, None]: ...

185

@property

186

def rain_24h(self) -> Union[float, None]: ...

187

@property

188

def snow_1h(self) -> Union[float, None]: ...

189

@property

190

def snow_6h(self) -> Union[float, None]: ...

191

@property

192

def snow_24h(self) -> Union[float, None]: ...

193

194

class AggregatedMeasurement:

195

def __init__(self, station_id: str, timestamp: int, aggregated_on: str,

196

temp: dict = None, humidity: dict = None, wind: dict = None,

197

pressure: dict = None, precipitation: dict = None): ...

198

199

def creation_time(self, timeformat: str = 'unix') -> Union[int, str, datetime, None]: ...

200

201

@property

202

def station_id(self) -> str: ...

203

@property

204

def timestamp(self) -> int: ...

205

@property

206

def aggregated_on(self) -> str: # 'm', 'h', or 'd'

207

"""Aggregation timeframe: 'm' (minute), 'h' (hour), 'd' (day)"""

208

@property

209

def temp(self) -> Union[dict, None]:

210

"""Temperature statistics: {'min': float, 'max': float, 'avg': float}"""

211

@property

212

def humidity(self) -> Union[dict, None]:

213

"""Humidity statistics: {'min': int, 'max': int, 'avg': int}"""

214

@property

215

def wind(self) -> Union[dict, None]:

216

"""Wind statistics: {'speed': {'min': float, 'max': float, 'avg': float}, 'deg': {'avg': float}}"""

217

@property

218

def pressure(self) -> Union[dict, None]:

219

"""Pressure statistics: {'min': float, 'max': float, 'avg': float}"""

220

@property

221

def precipitation(self) -> Union[dict, None]:

222

"""Precipitation statistics: {'sum': float}"""

223

```