This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Compound list | |
y_predict = ['PT08.S1(CO)','PT08.S2(NMHC)','PT08.S3(NOx)','PT08.S4(NO2)','PT08.S5(O3)'] | |
#Select compound to optimize model for | |
compound = y_predict[0] | |
#Designate independent and dependent variables | |
x = aq_final.drop([compound], axis = 1) | |
y = aq_final[compound] | |
#Split data into test and training sets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Need function that reads pixel hue value | |
hsv = cv2.cvtColor(ori_img, cv2.COLOR_BGR2HSV) | |
#Plot the image | |
fig, axs = plt.subplots(1, 3, figsize = (15,15)) | |
names = ['BGR','RGB','HSV'] | |
imgs = [ori_img, img, hsv] | |
i = 0 | |
for elem in imgs: | |
axs[i].title.set_text(names[i]) | |
axs[i].imshow(elem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i=0 ; j=0 | |
#Initialize array the will contain Hues for every pixel in image | |
hues = [] | |
for i in range(height): | |
for j in range(width): | |
hue = hsv[i][j][0] #This is the hue value at pixel coordinate (i,j) | |
hues.append(hue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Define frequencies that make up A-Harmonic Minor Scale | |
scale_freqs = [220.00, 246.94 ,261.63, 293.66, 329.63, 349.23, 415.30] | |
def hue2freq(h,scale_freqs): | |
thresholds = [26 , 52 , 78 , 104, 128 , 154 , 180] | |
note = scale_freqs[0] | |
if (h <= thresholds[0]): | |
note = scale_freqs[0] | |
elif (h > thresholds[0]) & (h <= thresholds[1]): | |
note = scale_freqs[1] | |
elif (h > thresholds[1]) & (h <= thresholds[2]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pixels_df['notes'] = pixels_df.apply(lambda row : hue2freq(row['hues'],scale_freqs), axis = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frequencies = pixels_df['notes'].to_numpy() | |
song = np.array([]) | |
sr = 22050 # sample rate | |
T = 0.1 # 0.1 second duration | |
t = np.linspace(0, T, int(T*sr), endpoint=False) # time variable | |
#Make a song with numpy array :] | |
#nPixels = int(len(frequencies))#All pixels in image | |
nPixels = 60 | |
for i in range(nPixels): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
song = np.array([]) | |
octaves = np.array([0.5,1,2]) | |
sr = 22050 # sample rate | |
T = 0.1 # 0.1 second duration | |
t = np.linspace(0, T, int(T*sr), endpoint=False) # time variable | |
#Make a song with numpy array :] | |
#nPixels = int(len(frequencies))#All pixels in image | |
nPixels = 60 | |
for i in range(nPixels): | |
octave = random.choice(octaves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
song = np.array([]) | |
octaves = np.array([1/2,1,2]) | |
sr = 22050 # sample rate | |
T = 0.1 # 0.1 second duration | |
t = np.linspace(0, T, int(T*sr), endpoint=False) # time variable | |
#Make a song with numpy array :] | |
#nPixels = int(len(frequencies))#All pixels in image | |
nPixels = 60 | |
for i in range(nPixels): | |
octave = random.choice(octaves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_piano_notes(): | |
# White keys are in Uppercase and black keys (sharps) are in lowercase | |
octave = ['C', 'c', 'D', 'd', 'E', 'F', 'f', 'G', 'g', 'A', 'a', 'B'] | |
base_freq = 440 #Frequency of Note A4 | |
keys = np.array([x+str(y) for y in range(0,9) for x in octave]) | |
# Trim to standard 88 keys | |
start = np.where(keys == 'A0')[0][0] | |
end = np.where(keys == 'C8')[0][0] | |
keys = keys[start:end+1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Load note dictionary | |
note_freqs = get_piano_notes() |
OlderNewer