def get_turbine(self, target_idx): """This method fetches and returns a single turbine object. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. Returns ------- Turbine An according turbine for target id. """ self.check_availability(target_idx=target_idx) meta = load(self.data_home_npy + "meta.npy") mdata = meta[target_idx] measurements = load(self.data_home_npy + "%i.npy" % target_idx) latitude, longitude = mdata['latitude'], mdata['longitude'] power_density = nan power_capacity = mdata['power_capacity'] speed = nan elevation = nan turbine = Turbine(target_idx, latitude, longitude, power_density,\ power_capacity, speed, elevation) turbine.add_measurements(measurements) return turbine
def get_turbine(self, target_idx): """This method fetches and returns a single turbine object. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. Returns ------- Turbine An according turbine for target id. """ self.check_availability() meta = load(self.data_home_npy + "meta.npy") mdata = meta[target_idx] measurements = load(self.data_home_npy + "%i.npy" % target_idx) latitude, longitude = mdata['latitude'], mdata['longitude'] power_density = nan power_capacity = mdata['power_capacity'] speed = nan elevation = nan turbine = Turbine(target_idx, latitude, longitude, power_density,\ power_capacity, speed, elevation) turbine.add_measurements(measurements) return turbine
def get_turbine(self, target_idx, year_from, year_to=0): """This method fetches and returns a single turbine object. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. year_from : int 2004 - 2006 year_to : int 2004 - 2006 Returns ------- Turbine An according turbine for target id and time span. """ # if only one year is desired if year_to == 0: year_to=year_from # determine the coordinates of the target target = self.fetch_nrel_meta_data(target_idx) # add target turbine as last element 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 = 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) return newturbine
def get_turbine(self, target_idx, year_from, year_to=0): """This method fetches and returns a single turbine object. Parameters ---------- target_idx : int see windml.datasets.nrel.park_id for example ids. year_from : int 2004 - 2006 year_to : int 2004 - 2006 Returns ------- Turbine An according turbine for target id and time span. """ # if only one year is desired if year_to == 0: year_to = year_from # determine the coordinates of the target target = self.fetch_nrel_meta_data(target_idx) # add target turbine as last element 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 = 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) return newturbine
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
pick = [] with open(csvfile, mode) as csv_arch: reader = csv.reader(csv_arch, delimiter=',') for row in reader: pick.append(int(row[0])) nrel = NREL() d = 0 turbines = nrel.fetch_nrel_meta_data_all() result = Windpark(target_idx, 0) 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'])
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