def get_windpark(self, target_idx, radius): """ This method fetches and returns a windpark from AEMO, which consists of the target turbine with the given target_idx and the surrounding turbine within a given radius around the target turbine. When called, the wind measurements for a given range of years are downloaded for every turbine in the park. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. Returns ------- Windpark An according windpark for target id, radius. """ self.check_availability(target_idx=target_idx) result = Windpark(target_idx, radius) target_turbine = self.get_turbine(target_idx) lat_target = radians(target_turbine.latitude) lon_target = radians(target_turbine.longitude) turbines = self.get_all_turbines() Earth_Radius = 6371 for turbine in turbines: # because we append the target as last element if (turbine.idx == target_idx): continue lat_act = radians(turbine.latitude) lon_act = radians(turbine.longitude) dLat = (lat_act - lat_target) dLon = (lon_act - lon_target) # Haversine formula: a = sin(dLat/2) * sin(dLat/2) + cos(lat_target) *\ cos(lat_act) * sin(dLon/2) * sin(dLon/2) c = 2 * atan2(sqrt(a), sqrt(1 - a)) distance_act = Earth_Radius * c if (distance_act < radius): result.add_turbine(turbine) result.add_turbine(target_turbine) return result
def get_windpark(self, target_idx, radius): """ This method fetches and returns a windpark from AEMO, which consists of the target turbine with the given target_idx and the surrounding turbine within a given radius around the target turbine. When called, the wind measurements for a given range of years are downloaded for every turbine in the park. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. Returns ------- Windpark An according windpark for target id, radius. """ self.check_availability(target_idx=target_idx) result = Windpark(target_idx, radius) target_turbine = self.get_turbine(target_idx) lat_target = radians(target_turbine.latitude) lon_target = radians(target_turbine.longitude) turbines = self.get_all_turbines() Earth_Radius = 6371 for turbine in turbines: # because we append the target as last element if(turbine.idx == target_idx): continue lat_act = radians(turbine.latitude) lon_act = radians(turbine.longitude) dLat = (lat_act - lat_target) dLon = (lon_act - lon_target) # Haversine formula: a = sin(dLat/2) * sin(dLat/2) + cos(lat_target) *\ cos(lat_act) * sin(dLon/2) * sin(dLon/2) c = 2 * atan2(sqrt(a), sqrt(1-a)) distance_act = Earth_Radius * c; if(distance_act < radius): result.add_turbine(turbine) result.add_turbine(target_turbine) return result
def get_windpark(self, target_idx, radius, year_from=0, year_to=0): """This method fetches and returns a windpark from NREL, which consists of the target turbine with the given target_idx and the surrounding turbine within a given radius around the target turbine. When called, the wind measurements for a given range of years are downloaded for every turbine in the park. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. year_from : int 2004 - 2006 year_to : int 2004 - 2006 Returns ------- Windpark An according windpark for target id, radius, and time span. """ #if only one year is desired if year_to == 0: year_to = year_from result = Windpark(target_idx, radius) # determine the coordinates of the target target = self.fetch_nrel_meta_data(target_idx) Earth_Radius = 6371 lat_target = math.radians(np.float64(target[1])) lon_target = math.radians(np.float64(target[2])) rel_input_lat = [] rel_input_lon = [] #fetch all turbines turbines = self.fetch_nrel_meta_data_all() for row in turbines: turbine_index = np.int(row[0]) if (turbine_index != target_idx): lat_act = math.radians(np.float64(row[1])) lon_act = math.radians(np.float64(row[2])) dLat = (lat_act - lat_target) dLon = (lon_act - lon_target) # Haversine formula: a = math.sin(dLat / 2) * math.sin(dLat / 2) + math.cos( lat_target) * math.cos(lat_act) * math.sin( dLon / 2) * math.sin(dLon / 2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) distance_act = Earth_Radius * c if (distance_act < radius): newturbine = Turbine(row[0], row[1], row[2], row[3], row[4], row[5], row[6]) if year_from != 0: for y in range(year_from, year_to + 1): measurement = self.fetch_nrel_data( row[0], y, ['date', 'corrected_score', 'speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate( (measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) #add target turbine as last element newturbine = Turbine(target[0], target[1], target[2], target[3], target[4], target[5], target[6]) if year_from != 0: for y in range(year_from, year_to + 1): measurement = self.fetch_nrel_data( target[0], y, ['date', 'corrected_score', 'speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) return result
def get_windpark_nearest(self, target_idx, n_nearest,\ year_from=0, year_to=0): """This method fetches and returns a windpark from NREL, which consists of the target turbine with the given target_idx and the surrounding n-nearest turbines around the target turbine. When called, the wind measurements for a given range of years are downloaded for every turbine in the park. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. year_from : int 2004 - 2006 year_to : int 2004 - 2006 Returns ------- Windpark An according windpark for target id, n-nearest, and time span. """ #if only one year is desired if year_to == 0: year_to = year_from meta = self.fetch_nrel_meta_data_all() target = self.fetch_nrel_meta_data(target_idx) tlat, tlon = target[1], target[2] marked = [] nearest = [] distances = [] for i in xrange(n_nearest): smallest = None for t in xrange(meta.shape[0]): d = haversine((tlat, tlon), (meta[t][1], meta[t][2])) if (smallest == None and t != target_idx - 1 and t not in marked): smallest = t smallest_d = d else: if (d <= smallest_d and t != target_idx - 1 and t not in marked): smallest = t smallest_d = d marked.append(smallest) nearest.append(meta[smallest]) distances.append(smallest_d) result = Windpark(target_idx, distances[-1]) for row in nearest: newturbine = Turbine(row[0], row[1] , row[2] , row[3] , row[4],\ row[5], row[6]) if year_from != 0: for y in range(year_from, year_to + 1): measurement = self.fetch_nrel_data(row[0], y,\ ['date','corrected_score','speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate( (measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) #add target turbine as last element newturbine = Turbine(target[0], target[1] , target[2] , target[3],\ target[4] , target[5], target[6]) if year_from != 0: for y in range(year_from, year_to + 1): measurement = self.fetch_nrel_data(target[0], y,\ ['date','corrected_score','speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) return result
for row in turbines: turbine_index = np.int(row[0]) if (turbine_index != target_idx): if (pick[turbine_index - 1] == pick[target_idx - 1]): d = d + 1 newturbine = Turbine(row[0], row[1], row[2], row[3], row[4], row[5], row[6]) for y in range(year_from, year_to + 1): measurement = nrel.fetch_nrel_data( row[0], y, ['date', 'corrected_score', 'speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) target = nrel.fetch_nrel_meta_data(target_idx) newturbine = Turbine(target[0], target[1] , target[2] , target[3],\ target[4] , target[5], target[6]) for y in range(year_from, year_to + 1): measurement = nrel.fetch_nrel_data(target[0], y,\ ['date','corrected_score','speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) windpark = result
def get_windpark(self, target_idx, radius, year_from=0, year_to=0): """This method fetches and returns a windpark from NREL, which consists of the target turbine with the given target_idx and the surrounding turbine within a given radius around the target turbine. When called, the wind measurements for a given range of years are downloaded for every turbine in the park. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. year_from : int 2004 - 2006 year_to : int 2004 - 2006 Returns ------- Windpark An according windpark for target id, radius, and time span. """ #if only one year is desired if year_to == 0: year_to = year_from result = Windpark(target_idx, radius) # determine the coordinates of the target target=self.fetch_nrel_meta_data(target_idx) Earth_Radius = 6371 lat_target = math.radians(np.float64(target[1])) lon_target = math.radians(np.float64(target[2])) rel_input_lat = [] rel_input_lon = [] #fetch all turbines turbines = self.fetch_nrel_meta_data_all() for row in turbines: turbine_index = np.int(row[0]) if (turbine_index != target_idx): lat_act = math.radians(np.float64(row[1])) lon_act = math.radians(np.float64(row[2])) dLat = (lat_act-lat_target) dLon = (lon_act-lon_target) # Haversine formula: a = (math.sin(dLat/2) * math.sin(dLat/2) + math.cos(lat_target) * math.cos(lat_act) * math.sin(dLon/2) * math.sin(dLon/2)) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) distance_act = Earth_Radius * c; if (distance_act < radius): newturbine = Turbine(row[0], row[1] , row[2] , row[3] , row[4] , row[5], row[6]) if year_from != 0: for y in range(year_from, year_to+1): measurement = self.fetch_nrel_data(row[0], y, ['date','corrected_score','speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) #add target turbine as last element newturbine = Turbine(target[0], target[1], target[2], target[3], target[4], target[5], target[6]) if year_from != 0: for y in range(year_from, year_to+1): measurement = self.fetch_nrel_data(target[0], y, ['date','corrected_score','speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) return result
def get_windpark_nearest(self, target_idx, n_nearest,\ year_from=0, year_to=0): """This method fetches and returns a windpark from NREL, which consists of the target turbine with the given target_idx and the surrounding n-nearest turbines around the target turbine. When called, the wind measurements for a given range of years are downloaded for every turbine in the park. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. year_from : int 2004 - 2006 year_to : int 2004 - 2006 Returns ------- Windpark An according windpark for target id, n-nearest, and time span. """ #if only one year is desired if year_to == 0: year_to=year_from meta = self.fetch_nrel_meta_data_all() target = self.fetch_nrel_meta_data(target_idx) tlat, tlon = target[1], target[2] marked = [] nearest = [] distances = [] for i in range(n_nearest): smallest = None for t in range(meta.shape[0]): d = haversine((tlat, tlon), (meta[t][1], meta[t][2])) if(smallest == None and t != target_idx - 1 and t not in marked): smallest = t smallest_d = d else: if(d <= smallest_d and t != target_idx - 1 and t not in marked): smallest = t smallest_d = d marked.append(smallest) nearest.append(meta[smallest]) distances.append(smallest_d) result = Windpark(target_idx, distances[-1]) for row in nearest: newturbine = Turbine(row[0], row[1] , row[2] , row[3] , row[4],\ row[5], row[6]) if year_from != 0: for y in range(year_from, year_to+1): measurement = self.fetch_nrel_data(row[0], y,\ ['date','corrected_score','speed']) if y==year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) #add target turbine as last element newturbine = Turbine(target[0], target[1] , target[2] , target[3],\ target[4] , target[5], target[6]) if year_from != 0: for y in range(year_from, year_to+1): measurement = self.fetch_nrel_data(target[0], y,\ ['date','corrected_score','speed']) if y == year_from: measurements = measurement else: measurements = np.concatenate((measurements, measurement)) newturbine.add_measurements(measurements) result.add_turbine(newturbine) return result