Beispiel #1
0
 def generateWHOparameters(self, common_ages, features, data):
     features, data = super(IsraeliChild, self).generateWHOparameters(
         common_ages, features, data)
     calculator = Calculator(adjust_height_data=False,
                             adjust_weight_scores=False,
                             include_cdc=False,
                             logger_name='pygrowup',
                             log_level='INFO')
     common_ages = common_ages[1:-2]
     for age in common_ages:
         features += ["WHO hcfa z-score at %s" % str(age)]
         i = find_nearest([a.age for a in self.goodSamples], age)
         if abs(self.goodSamples[i].age - age) > 2 / MONTHS:
             data += [np.nan]
         else:
             child_age, height, hc = str(
                 self.goodSamples[i].age * MONTHS), str(
                     self.goodSamples[i].height), str(
                         self.goodSamples[i].HC)
             sex = 'M' if self.sex == 1 else 'F'
             try:
                 data += [calculator.hcfa(hc, child_age, sex, height)]
             except Exception as e:
                 data += [np.nan]
     return features, data
Beispiel #2
0
 def generateWHOparameters(self, common_ages, features, data):
     calculator = Calculator(adjust_height_data=False,
                             adjust_weight_scores=False,
                             include_cdc=False,
                             logger_name='pygrowup',
                             log_level='INFO')
     common_ages = common_ages[1:]
     for age in common_ages:
         i = find_nearest([a.age for a in self.goodSamples], age)
         features += [
             "WHO wfa z-score at %s" % str(age),
             "WHO wfl z-score at age %s" % str(age),
             "WHO lfa z-score at age %s" % str(age)
         ]
         if abs(self.goodSamples[i].age - age) > 2 / MONTHS:
             data += [np.nan, np.nan, np.nan]
         else:
             s = self.goodSamples[i]
             child_age, height, weight = str(
                 self.goodSamples[i].age * MONTHS), str(
                     self.goodSamples[i].height), str(
                         self.goodSamples[i].weight)
             sex = 'M' if self.sex == 1 else 'F'
             try:
                 data += [
                     calculator.wfa(weight, child_age, sex),
                     calculator.wfl(weight, child_age, sex, height),
                     calculator.lhfa(height, child_age, sex)
                 ]
             except Exception as e:
                 data += [np.nan, np.nan, np.nan]
     return features, data
Beispiel #3
0
def findHeightAroundAge(listOfChildren):
    six_months_heights = []
    six_years_heights = []
    seven_years_heights = []
    for child in listOfChildren:
        if not child.goodSamples:
            continue
        six_months_idx = find_nearest([a.age for a in child.goodSamples], 0.5)
        six_years_idx = find_nearest([a.age for a in child.goodSamples], 6)
        seven_years_idx = find_nearest([a.age for a in child.goodSamples], 7)
        if (abs(child.goodSamples[six_months_idx].age - 0.5) < 0.3) and \
                (abs(child.goodSamples[six_years_idx].age - 6) < 0.8) and \
                (abs(child.goodSamples[seven_years_idx].age - 7) < 0.8):
            six_months_heights.append(child.goodSamples[six_months_idx].height)
            six_years_heights.append(child.goodSamples[six_years_idx].height)
            seven_years_heights.append(
                child.goodSamples[seven_years_idx].height)
    return normalizeZScore(six_months_heights, six_years_heights,
                           seven_years_heights)
Beispiel #4
0
def swedishNormalityTests(listOfChildren):
    six_months_heights = []
    seven_years_heights = []
    for child in listOfChildren:
        six_idx = find_nearest([a.age for a in child.goodSamples], 0.5)
        if abs(child.goodSamples[six_idx].age - 0.5) < 0.3:
            six_months_heights.append(child.goodSamples[six_idx].height)
        seven_idx = find_nearest([a.age for a in child.goodSamples], 7)
        if abs(child.goodSamples[seven_idx].age - 7) < 0.8:
            seven_years_heights.append(child.goodSamples[seven_idx].height)

    print("Height at age 6 months")
    for x in sorted(list(set(six_months_heights))):
        print(x, ",", len([y for y in six_months_heights if abs(x - y) < 0.05]))

    print("Height at age 7 years")
    for x in sorted(list(set(seven_years_heights))):
        print(x, ",", len([y for y in seven_years_heights if abs(x - y) < 0.05]))
    print()
Beispiel #5
0
def printICTAndHeights(newICT, printMode):
    if not printMode:
        return
    print("New ict tags: ")
    print([p * MONTHS for c, p in newICT if p != NA])
    print("heights at age 7 years: ")
    print([
        c.goodSamples[find_nearest([a.age for a in c.goodSamples], 7)].height
        for c, p in newICT if p != NA
    ])
    print()
Beispiel #6
0
def israeliNormalityTests(listOfChildren):
    six_months_heights = []
    for child in listOfChildren:
        if len(child.goodSamples) == 0:
            continue
        six_idx = find_nearest([a.age for a in child.goodSamples], 0.5)
        if abs(child.goodSamples[six_idx].age - 0.5) < 0.3:
            six_months_heights.append(child.goodSamples[six_idx].height)

    print("Height at age 6 months: ")
    for x in sorted(list(set(six_months_heights))):
        print(x, ",", len([y for y in six_months_heights if abs(x - y) < 0.05]))
    print()
Beispiel #7
0
 def generateParametersForRegressionDecisionTree(self,
                                                 common_ages,
                                                 first=True):
     features = [
         "sex", "birthWeight (KG)", "birthHeight (M)",
         "gestationalAge (Weeks)", "birthMonth", "season", "preterm flag",
         "max of weightToAgeLevel1", "max of weightDivAgeLevel1",
         "min of weightToAgeLevel1", "min of weightDivAgeLevel1",
         "avg of weightToAgeLevel1", "avg of weightDivAgeLevel1",
         "max of weightToAgeLevel2", "max of weightDivAgeLevel2",
         "min of weightToAgeLevel2", "min of weightDivAgeLevel2",
         "avg of weightToAgeLevel2", "avg of weightDivAgeLevel2",
         "max of heightToAgeLevel1", "max of heightDivAgeLevel1",
         "min of heightToAgeLevel1", "min of heightDivAgeLevel1",
         "avg of heightToAgeLevel1", "avg of heightDivAgeLevel1",
         "max of heightToAgeLevel2", "max of heightDivAgeLevel2",
         "min of heightToAgeLevel2", "min of heightDivAgeLevel2",
         "avg of heightToAgeLevel2", "avg of heightDivAgeLevel2",
         "max of BMIToAgeLevel1", "max of BMIDivAgeLevel1",
         "min of BMIToAgeLevel1", "min of BMIDivAgeLevel1",
         "avg of BMIToAgeLevel1", "avg of BMIDivAgeLevel1",
         "max of BMIToAgeLevel2", "max of BMIDivAgeLevel2",
         "min of BMIToAgeLevel2", "min of BMIDivAgeLevel2",
         "avg of BMIToAgeLevel2", "avg of BMIDivAgeLevel2",
         "Height at 6 months (m)", "Weight at 6 months (KG)",
         "Height at 6 months (m) Avg'd", "Weight at 6 months (KG) Avg'd"
     ]
     birthWeight = NA if self.birthWeight == NA else float(
         self.birthWeight) / KILO
     data = [
         self.sex, birthWeight, self.birthHeight, self.gestationalAge,
         self.birthMonth, self.season, self.preterm,
         self.max_weightToAgeLevel1, self.max_weightDivAgeLevel1,
         self.min_weightToAgeLevel1, self.min_weightDivAgeLevel1,
         self.avg_weightToAgeLevel1, self.avg_weightDivAgeLevel1,
         self.max_weightToAgeLevel2, self.max_weightDivAgeLevel2,
         self.min_weightToAgeLevel2, self.min_weightDivAgeLevel2,
         self.avg_weightToAgeLevel2, self.avg_weightDivAgeLevel2,
         self.max_heightToAgeLevel1, self.max_heightDivAgeLevel1,
         self.min_heightToAgeLevel1, self.min_heightDivAgeLevel1,
         self.avg_heightToAgeLevel1, self.avg_heightDivAgeLevel1,
         self.max_heightToAgeLevel2, self.max_heightDivAgeLevel2,
         self.min_heightToAgeLevel2, self.min_heightDivAgeLevel2,
         self.avg_heightToAgeLevel2, self.avg_heightDivAgeLevel2,
         self.max_bmiToAgeLevel1, self.max_bmiDivAgeLevel1,
         self.min_bmiToAgeLevel1, self.min_bmiDivAgeLevel1,
         self.avg_bmiToAgeLevel1, self.avg_bmiDivAgeLevel1,
         self.max_bmiToAgeLevel2, self.max_bmiDivAgeLevel2,
         self.min_bmiToAgeLevel2, self.min_bmiDivAgeLevel2,
         self.avg_bmiToAgeLevel2, self.avg_bmiDivAgeLevel2
     ]
     if self.goodSamples:
         smi = find_nearest([a.age for a in self.goodSamples], 0.5)
         data += [(self.goodSamples[smi]).height,
                  (self.goodSamples[smi]).weight]
         if smi > 0 and self.goodSamples[-1] != self.goodSamples[smi]:
             data += [((self.goodSamples[smi - 1]).height +
                       (self.goodSamples[smi]).height +
                       (self.goodSamples[smi + 1]).height) / 3,
                      ((self.goodSamples[smi - 1]).weight +
                       (self.goodSamples[smi]).weight +
                       (self.goodSamples[smi + 1]).weight) / 3]
         else:
             data += [
                 self.goodSamples[smi].height, self.goodSamples[smi].weight
             ]
     for age in common_ages:
         features += [
             "Height at %s" % str(age),
             "Weight at %s" % str(age),
             "BMI at %s" % str(age)
         ]
         i = find_nearest([a.age for a in self.goodSamples], age)
         if abs(self.goodSamples[i].age - age) > 2 / MONTHS:
             data += [np.nan, np.nan, np.nan]
         else:
             data += [
                 self.goodSamples[i].height, self.goodSamples[i].weight,
                 self.goodSamples[i].BMI
             ]
     features, data = self.generateWHOparameters(common_ages, features,
                                                 data)
     if self.autoICT == NA:
         return features, data, 0
     return features, data, self.autoICT
Beispiel #8
0
    def generateParametersForRegressionDecisionTree(self,
                                                    common_ages,
                                                    first=True):
        features, data, c = super(
            IsraeliChild, self).generateParametersForRegressionDecisionTree(
                common_ages, first)
        for age in common_ages:
            features += ["HC at %s" % str(age)]
            i = find_nearest([a.age for a in self.goodSamplesWithHC], age)
            if abs(self.goodSamples[i].age - age) > 2 / MONTHS:
                data += [np.nan]
            else:
                data += [self.goodSamplesWithHC[i].HC]

        features += [
            "birthPosition", "birthYear", "HC at 6 months",
            "HC at 6 months Avg'd"
        ]
        data += [self.position, self.birthYear]
        if self.goodSamplesWithHC:
            smi_HC = find_nearest([a.age for a in self.goodSamplesWithHC], 0.5)
            data += [(self.goodSamplesWithHC[smi_HC]).HC]
            if len(self.goodSamplesWithHC) > smi_HC + 1:
                data += [((self.goodSamplesWithHC[smi_HC - 1]).HC +
                          (self.goodSamplesWithHC[smi_HC]).HC +
                          (self.goodSamplesWithHC[smi_HC + 1]).HC) / 3]
            else:
                data += [(self.goodSamplesWithHC[smi_HC]).HC]

        features += ["Avg brothers HC at 6 months (m)"]
        b_smi_HC = [
            find_nearest([a.age for a in x.goodSamplesWithHC], 0.5)
            if len(x.goodSamplesWithHC) else NA for x in self.brothers
        ]  #when refactoring stayes here
        if NA not in b_smi_HC and len(b_smi_HC) > 0:
            data += [
                np.mean([
                    list(self.brothers)[i].goodSamplesWithHC[b_smi_HC[i]].HC
                    for i in range(0, len(b_smi_HC))
                ])
            ]
        else:
            data += [np.nan]
        features += [
            "Avg brothers Height at 6 months (m)",
            "Avg brothers Weight at 6 months (m)"
        ]
        b_smi = [
            find_nearest([a.age for a in x.goodSamples], 0.5)
            if len(x.goodSamples) else NA for x in self.brothers
        ]
        if NA not in b_smi and len(b_smi) > 0:
            data += [
                np.mean([
                    list(self.brothers)[i].goodSamples[b_smi[i]].height
                    for i in range(0, len(b_smi))
                ]),
                np.mean([
                    list(self.brothers)[i].goodSamples[b_smi[i]].weight
                    for i in range(0, len(b_smi))
                ])
            ]
        else:
            data += [np.nan, np.nan]

        features += [
            "avg of HCToAgeLevel1", "max of HCToAgeLevel1",
            "min of HCToAgeLevel1", "avg of HCToAgeLevel2",
            "max of HCToAgeLevel2", "min of HCToAgeLevel2",
            "avg of HCdivHeightLevel1", "max of HCdivHeightLevel1",
            "min of HCdivHeightLevel1", "avg of HCdivHeightLevel2",
            "max of HCdivHeightLevel2", "min of HCdivHeightLevel2",
            "avg of HCdivHeightSqLevel1", "max of HCdivHeightSqLevel1",
            "min of HCdivHeightSqLevel1", "avg of HCdivHeightSqLevel2",
            "max of HCdivHeightSqLevel2", "min of HCdivHeightSqLevel2",
            "avg of HCdivWeightLevel1", "max of HCdivWeightLevel1",
            "min of HCdivWeightLevel1", "avg of HCdivWeightLevel2",
            "max of HCdivWeightLevel2", "min of HCdivWeightLevel2",
            "avg of HCdivWeightSqLevel1", "max of HCdivWeightSqLevel1",
            "min of HCdivWeightSqLevel1", "avg of HCdivWeightSqLevel2",
            "max of HCdivWeightSqLevel2", "min of HCdivWeightSqLevel2"
        ]

        data += [
            self.avg_HCToAgeLevel1, self.max_HCToAgeLevel1,
            self.min_HCToAgeLevel1, self.avg_HCToAgeLevel2,
            self.max_HCToAgeLevel2, self.min_HCToAgeLevel2,
            self.avg_HCdivHeightLevel1, self.max_HCdivHeightLevel1,
            self.min_HCdivHeightLevel1, self.avg_HCdivHeightLevel2,
            self.max_HCdivHeightLevel2, self.min_HCdivHeightLevel2,
            self.avg_HCdivHeightSqLevel1, self.max_HCdivHeightSqLevel1,
            self.min_HCdivHeightSqLevel1, self.avg_HCdivHeightSqLevel2,
            self.max_HCdivHeightSqLevel2, self.min_HCdivHeightSqLevel2,
            self.avg_HCdivWeightLevel1, self.max_HCdivWeightLevel1,
            self.min_HCdivWeightLevel1, self.avg_HCdivWeightLevel2,
            self.max_HCdivWeightLevel2, self.min_HCdivWeightLevel2,
            self.avg_HCdivWeightSqLevel1, self.max_HCdivWeightSqLevel1,
            self.min_HCdivWeightSqLevel1, self.avg_HCdivWeightSqLevel2,
            self.max_HCdivWeightSqLevel2, self.min_HCdivWeightSqLevel2
        ]

        features += ["nation"]
        data += [Nationality.ISR.value]

        if first:
            features += [
                "fatherAge (Years)", "motherWeight (KG)", "motherHeight (M)"
            ]
            data += [
                self.fatherAge, self.motherWeight, self.motherHeight / METER
            ]

        if self.autoICT == NA:
            return features, data, 0

        return features, data, self.autoICT