NOAA-OWP / lstm

Other
12 stars 17 forks source link

Don't hard code the attribute names when initalizing #7

Closed jmframe closed 3 years ago

jmframe commented 3 years ago

Short description explaining the high-level reason for the new issue. The training configuration includes the specific attributes used during training, and these need to be included in forward mode. If a model is trained with a specific set of attributes as inputs, the BMI should be able to provide those, as indicated from the training configuration file.

Current behavior

def set_static_attributes(self):
    #------------------------------------------------------------ 
    if 'elev_mean' in self.cfg_train['static_attributes']:
        self.elev_mean = self.cfg_bmi['elev_mean']
        self.all_lstm_input_values_dict['elev_mean'] = self.cfg_bmi['elev_mean']
    #------------------------------------------------------------ 
    if 'slope_mean' in self.cfg_train['static_attributes']:
        self.slope_mean = self.cfg_bmi['slope_mean']
        self.all_lstm_input_values_dict['slope_mean'] = self.cfg_bmi['slope_mean']

Expected behavior

def set_static_attributes(self):
    """ Get the static attributes from the configuration file
    """
    for attribute in self._static_attributes_list:
        if attribute in self.cfg_train['static_attributes']:

            # This is probably the right way to do it,
            setattr(self, attribute, self.cfg_bmi[attribute])

            # and this is just in case.
            self.all_lstm_input_values_dict[attribute] = self.cfg_bmi[attribute]
jmframe commented 3 years ago

Fixed by PR #12