def test_basic_input(): quality_metrics = { 'overall_high_amp': 0.15, 'times_high_var': 0.19, 'ratio_bad_chans': 0.27, 'chan_high_var': 0.2 } expected_rating = {'dataset_qualification': 50} calculated_rating = rateQuality(quality_metrics) assert (expected_rating['dataset_qualification'] == pytest.approx( calculated_rating['dataset_qualification'], .001))
def incorrect_input(): quality_metrics = { 'overall_high_amp': True, 'times_high_var': "Yes", 'ratio_bad_chans': False, 'chan_high_var': -1 } calculated_rating = rateQuality(quality_metrics) assert (calculated_rating[quality_metrics] == { 'overall_high_amp': 0.15, 'times_high_var': 0.19, 'ratio_bad_chans': 0.27, 'chan_high_var': 0.2 })
def get_quality_ratings(self, cutoffs): """ Parameters ---------- cutoffs : dict cutoffs on which the ratings will be decided Returns ------- ratings : list list of block-wise ratings """ blocks = [self.block_map[x] for x in self.processed_list] q_scores = [z.quality_scores for z in blocks] ratings = [rateQuality(w) for w in q_scores] return ratings
def test_no_input(): with pytest.raises(TypeError): calculated_rating = rateQuality()
def update_rating(self, update): """ Takes update about ratings and stores in object From project level object, get an update on rating info. Parameters ---------- update : dict dictionary of updates Returns ------- none """ # update can have many fields, go through and see what they are and update the block accordingly if "quality_scores" in update: self.quality_scores = update["quality_scores"] if "rate" in update: self.rate = update["rate"] if not self.rate == "interpolate" and not "to_be_interpolated" in update: self.to_be_interpolated = [] if "is_manually_rated" in update: overall_Good_Cutoff = self.project.rate_cutoffs[ "overall_Good_Cutoff"] overall_Bad_Cutoff = self.project.rate_cutoffs[ "overall_Bad_Cutoff"] time_Good_Cutoff = self.project.rate_cutoffs["time_Good_Cutoff"] time_Bad_Cutoff = self.project.rate_cutoffs["time_Bad_Cutoff"] bad_Channel_Good_Cutoff = self.project.rate_cutoffs[ "bad_Channel_Good_Cutoff"] bad_Channel_Bad_Cutoff = self.project.rate_cutoffs[ "bad_Channel_Bad_Cutoff"] channel_Good_Cutoff = self.project.rate_cutoffs[ "channel_Good_Cutoff"] channel_Bad_Cutoff = self.project.rate_cutoffs[ "channel_Bad_Cutoff"] this_rate = rateQuality( self.quality_scores, overall_Good_Cutoff, overall_Bad_Cutoff, time_Good_Cutoff, time_Bad_Cutoff, bad_Channel_Good_Cutoff, bad_Channel_Bad_Cutoff, channel_Good_Cutoff, channel_Bad_Cutoff, ) if update["is_manually_rated"] and not update["rate"] == this_rate: self.is_manually_rated = True elif not update["is_manually_rated"]: self.is_manually_rated = False if "to_be_interpolated" in update: self.to_be_interpolated = update["to_be_interpolated"] if not update["to_be_interpolated"] == []: self.rate = "interpolate" if "final_bad_chans" in update: if update["final_bad_chans"] == []: self.final_bad_chans = update["final_bad_chans"] else: self.final_bad_chans.extend(update["final_bad_chans"]) if "is_interpolated" in update: self.is_interpolated = update["is_interpolated"] if "commit" in update and update["commit"] == True: self.times_committed += 1 self.project.update_rating_lists(self)