<commit_before># -*- coding: utf-8 -*-
import essentia
import essentia.standard as std
import matplotlib.pyplot as pl
import numpy as np
import json

def load(fname, dist_dir='./'):
	with open((dist_dir + fname)) as f:    
		dist = json.load(f)
		f.close()
	return PitchDistribution(np.array(dist[0]['bins']), np.array(dist[0]['vals']), kernel_width=dist[0]['kernel_width'], source=dist[0]['source'], ref_freq=dist[0]['ref_freq'], segment=dist[0]['segmentation'])

class PitchDistribution:
	def __init__(self, pd_bins, pd_vals, kernel_width=7.5, source='', ref_freq=440, segment='all'):
		self.bins = pd_bins
		self.vals = pd_vals
		self.ref_freq = ref_freq
		self.kernel_width = kernel_width
		self.step_size = self.bins[1] - self.bins[0]
		self.segmentation = segment
		self.source = source

	def save(self, fname, save_dir='./'):
		dist_json = [{'bins':self.bins.tolist(), 'vals':self.vals.tolist(), 'kernel_width':self.kernel_width, 'source':self.source, 'ref_freq':self.ref_freq, 'segmentation':self.segmentation}]
		with open((save_dir + fname), 'w') as f:
			json.dump(dist_json, f, indent=0)
			f.close()

	def get(self):
		return self.bins, self.vals

	def is_pcd(self):
		"""---------------------------------------------------------------------------------------
		Checks if the pitch distribution is a Pitch Class Distribution
		---------------------------------------------------------------------------------------"""
		return (max(self.bins) == (1200 - self.step_size) and min(self.bins) == 0)

	def detect_peaks(self):
		detector = std.PeakDetection()
		peak_bins, peak_vals = detector(essentia.array(self.vals))
		# Essentia normalizes the positions to 1
		peak_idxs = [round(bn * len(self.bins)) for bn in peak_bins]
		lim = peak_idxs[len(peak_idxs) - 1]
		peak_idxs[len(peak_idxs) - 1] = (lim-1) if (lim==len(peak_bins)) else lim<commit_msg>Peak Detection Edited<commit_after># -*- coding: utf-8 -*-
import essentia
import essentia.standard as std
import matplotlib.pyplot as pl
import numpy as np
import json

def load(fname, dist_dir='./'):
	with open((dist_dir + fname)) as f:    
		dist = json.load(f)
		f.close()
	return PitchDistribution(np.array(dist[0]['bins']), np.array(dist[0]['vals']), kernel_width=dist[0]['kernel_width'], source=dist[0]['source'], ref_freq=dist[0]['ref_freq'], segment=dist[0]['segmentation'])

class PitchDistribution:
	def __init__(self, pd_bins, pd_vals, kernel_width=7.5, source='', ref_freq=440, segment='all'):
		self.bins = pd_bins
		self.vals = pd_vals
		self.ref_freq = ref_freq
		self.kernel_width = kernel_width
		self.step_size = self.bins[1] - self.bins[0]
		self.segmentation = segment
		self.source = source

	def save(self, fname, save_dir='./'):
		dist_json = [{'bins':self.bins.tolist(), 'vals':self.vals.tolist(), 'kernel_width':self.kernel_width, 'source':self.source, 'ref_freq':self.ref_freq, 'segmentation':self.segmentation}]
		with open((save_dir + fname), 'w') as f:
			json.dump(dist_json, f, indent=0)
			f.close()

	def get(self):
		return self.bins, self.vals

	def is_pcd(self):
		"""---------------------------------------------------------------------------------------
		Checks if the pitch distribution is a Pitch Class Distribution
		---------------------------------------------------------------------------------------"""
		return (max(self.bins) == (1200 - self.step_size) and min(self.bins) == 0)

	def detect_peaks(self):
		detector = std.PeakDetection()
		peak_bins, peak_vals = detector(essentia.array(self.vals))
		# Essentia normalizes the positions to 1
		peak_idxs = [round(bn * (len(self.bins) - 1)) for bn in peak_bins]
{'fraction_non_alphanumeric': 0.24267551133222776, 'fraction_numerical': 0.01271420674405749, 'mean_word_length': 3.0526315789473686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5731423', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1193, 'n_words': 266}