@@ -85,46 +85,79 @@ def __repr__(self):
8585 ('{}: {}' .format (attr , getattr (self , attr )) for attr in attrs )))
8686
8787 @classmethod
88- def from_tmy (cls , tmy_metadata , tmy_data = None , ** kwargs ):
88+ def from_tmy_or_epw (cls , weather_metadata , weather_data = None , ** kwargs ):
8989 """
9090 Create an object based on a metadata
91- dictionary from tmy2 or tmy3 data readers.
91+ dictionary from tmy2, tmy3 or epw data readers.
9292
9393 Parameters
9494 ----------
95- tmy_metadata : dict
96- Returned from tmy.readtmy2 or tmy.readtmy3
97- tmy_data : None or DataFrame, default None
98- Optionally attach the TMY data to this object.
95+ weather_metadata : dict
96+ Returned from tmy.readtmy2, tmy.readtmy3 or epw.read_epw
97+ weather_data : None or DataFrame, default None
98+ Optionally attach the weather data to this object.
9999
100100 Returns
101101 -------
102102 Location object (or the child class of Location that you
103103 called this method from).
104104 """
105- # not complete, but hopefully you get the idea.
106- # might need code to handle the difference between tmy2 and tmy3
107-
108- # determine if we're dealing with TMY2 or TMY3 data
109- tmy2 = tmy_metadata .get ('City' , False )
110-
111- latitude = tmy_metadata ['latitude' ]
112- longitude = tmy_metadata ['longitude' ]
105+ # determine if we're dealing with TMY2, TMY3 or data formatted
106+ # in .epw (Note that TMY2 and TMY3 can be formatted in epw sometimes)
107+ tmy2 = weather_metadata .get ('City' , False )
108+ tmy3 = weather_metadata .get ('Name' , False )
113109
114110 if tmy2 :
115- name = tmy_metadata ['City' ]
111+ name = weather_metadata ['City' ]
112+ elif tmy3 :
113+ name = weather_metadata ['Name' ]
116114 else :
117- name = tmy_metadata ['Name' ]
115+ name = weather_metadata ['city' ]
116+
117+ latitude = weather_metadata ['latitude' ]
118+ longitude = weather_metadata ['longitude' ]
118119
119- tz = tmy_metadata ['TZ' ]
120- altitude = tmy_metadata ['altitude' ]
120+ tz = weather_metadata ['TZ' ]
121+ altitude = weather_metadata ['altitude' ]
121122
122123 new_object = cls (latitude , longitude , tz = tz , altitude = altitude ,
123124 name = name , ** kwargs )
124125
125126 # not sure if this should be assigned regardless of input.
126- if tmy_data is not None :
127- new_object .tmy_data = tmy_data
127+ if weather_data is not None :
128+ new_object .weather_data = weather_data
129+
130+ return new_object
131+
132+ @classmethod
133+ def from_epw (cls , epw_metadata , epw_data = None , ** kwargs ):
134+ """
135+ Create a Location object based on a metadata
136+ dictionary from epw data readers.
137+
138+ Parameters
139+ ----------
140+ epw_metadata : dict
141+ Returned from epw.read_epw
142+ epw_data : None or DataFrame, default None
143+ Optionally attach the epw data to this object.
144+
145+ Returns
146+ -------
147+ Location object (or the child class of Location that you
148+ called this method from).
149+ """
150+
151+ latitude = epw_metadata ['latitude' ]
152+ longitude = epw_metadata ['longitude' ]
153+
154+ name = epw_metadata ['city' ]
155+
156+ tz = epw_metadata ['TZ' ]
157+ altitude = epw_metadata ['altitude' ]
158+
159+ new_object = cls (latitude , longitude , tz = tz , altitude = altitude ,
160+ name = name , ** kwargs )
128161
129162 return new_object
130163
0 commit comments