Skip to content

Instantly share code, notes, and snippets.

View victormurcia's full-sized avatar
😀
Playing with data :]

Victor Murcia victormurcia

😀
Playing with data :]
View GitHub Profile
@victormurcia
victormurcia / grid_search_gradient_boosting_regressor_air_quality.py
Last active September 2, 2022 20:24
Parameter Space Exploration for Gradient Boosting Regressor on Air Quality Dataset
#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
@victormurcia
victormurcia / color_space_compare.py
Created September 3, 2022 01:33
Color space conversion with Open CV
#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)
@victormurcia
victormurcia / get_hues.py
Created September 3, 2022 01:41
Get hue channel from image
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)
@victormurcia
victormurcia / hue_2_freq_v1.py
Created September 3, 2022 01:46
Hue to Frequency Converter
#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]):
@victormurcia
victormurcia / hues_to_frequencies_lambda.py
Created September 3, 2022 01:51
lambda function for hues to frequency conversion
pixels_df['notes'] = pixels_df.apply(lambda row : hue2freq(row['hues'],scale_freqs), axis = 1)
@victormurcia
victormurcia / numpy_to_song.py
Last active September 3, 2022 02:10
Convert pandas dataframe to numpy array and make a playable audiofile
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):
@victormurcia
victormurcia / numpy_to_song_octaves.py
Created September 3, 2022 02:29
Make a song from numpy array generated from image in HSV space
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)
@victormurcia
victormurcia / numpy_to_song_octaves_rand.py
Created September 3, 2022 02:47
Numpy to song with octaves and random pixel choice
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)
@victormurcia
victormurcia / piano_notes_to_freqs.py
Created September 3, 2022 03:05
Piano notes to frequencies converter
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]
@victormurcia
victormurcia / get_note_dictionary.py
Created September 3, 2022 03:09
piano notes to frequncies
#Load note dictionary
note_freqs = get_piano_notes()