This function loads data from LSM and converts to GSSHA format

def _load_converted_gssha_data_from_lsm(self, gssha_var, lsm_var, load_type, time_step=None):
        """
        This function loads data from LSM and converts to GSSHA format
        """
        if 'radiation' in gssha_var:
            conversion_factor = self.netcdf_attributes[gssha_var]['conversion_factor'][load_type]
            if gssha_var.startswith('direct_radiation') and not isinstance(lsm_var, basestring):
                # direct_radiation = (1-DIFFUSIVE_FRACION)*global_radiation
                global_radiation_var, diffusive_fraction_var = lsm_var
                global_radiation = self._load_lsm_data(global_radiation_var, conversion_factor)
                diffusive_fraction = self._load_lsm_data(diffusive_fraction_var)
                if gssha_var.endswith("cc"):
                    diffusive_fraction /= 100.0

                self.data = ((1-diffusive_fraction)*global_radiation)

            elif gssha_var.startswith('diffusive_radiation') and not isinstance(lsm_var, basestring):
                # diffusive_radiation = DIFFUSIVE_FRACION*global_radiation
                global_radiation_var, diffusive_fraction_var = lsm_var
                global_radiation = self._load_lsm_data(global_radiation_var, conversion_factor)
                diffusive_fraction = self._load_lsm_data(diffusive_fraction_var)
                if gssha_var.endswith("cc"):
                    diffusive_fraction /= 100
                self.data = (diffusive_fraction*global_radiation)

            elif isinstance(lsm_var, basestring):
                self.data = self._load_lsm_data(lsm_var, self.netcdf_attributes[gssha_var]['conversion_factor'][load_type])
            else:
                raise ValueError("Invalid LSM variable ({0}) for GSSHA variable {1}".format(lsm_var, gssha_var))

        elif gssha_var == 'relative_humidity' and not isinstance(lsm_var, str):
            ##CONVERSION ASSUMPTIONS:
            ##1) These equations are for liquid water and are less accurate below 0 deg C
            ##2) Not adjusting the pressure for the fact that the temperature
            ##   and moisture measurements are given at 2 m AGL.

            ##Neither of these should have a significant impact on RH values
            ##given the uncertainty in the model values themselves.

            specific_humidity_var, pressure_var, temperature_var = lsm_var
            specific_humidity = self._load_lsm_data(specific_humidity_var)
            pressure = self._load_lsm_data(pressure_var)
            temperature = self._load_lsm_data(temperature_var)
            ##To compute the relative humidity at 2m,
            ##given T, Q (water vapor mixing ratio) at 2 m and PSFC (surface pressure):
            ##Es(saturation vapor pressure in Pa)
            ##Qs(saturation mixing ratio)=(0.622*es)/(PSFC-es)
            ##RH = 100*Q/Qs
            es = esat(temperature)
            self.data = 100 * specific_humidity/((0.622*es)/(pressure-es))

        elif gssha_var == 'relative_humidity_dew':
            # https://software.ecmwf.int/wiki/display/CKB/Do+ERA+datasets+contain+parameters+for+near-surface+humidity
            # temperature in Kelvin
            # RH = 100 * es(Td)/es(T)
            dew_point_temp_var, temperature_var = lsm_var
            dew_point_temp = self._load_lsm_data(dew_point_temp_var)
            temperature = self._load_lsm_data(temperature_var)
            self.data = 100 * esat(dew_point_temp)/esat(temperature)

        elif gssha_var == 'wind_speed' and not isinstance(lsm_var, str):
            # WRF:  http://www.meteo.unican.es/wiki/cordexwrf/OutputVariables
            u_vector_var, v_vector_var = lsm_var
            conversion_factor = self.netcdf_attributes[gssha_var]['conversion_factor'][load_type]
            u_vector = self._load_lsm_data(u_vector_var, conversion_factor)
            v_vector = self._load_lsm_data(v_vector_var, conversion_factor)
            self.data = (xu.sqrt(u_vector**2 + v_vector**2))

        elif 'precipitation' in gssha_var and not isinstance(lsm_var, str):
            # WRF:  http://www.meteo.unican.es/wiki/cordexwrf/OutputVariables
            rain_c_var, rain_nc_var = lsm_var
            conversion_factor = self.netcdf_attributes[gssha_var]['conversion_factor'][load_type]
            rain_c = self._load_lsm_data(rain_c_var, conversion_factor)
            rain_nc = self._load_lsm_data(rain_nc_var, conversion_factor)
            self.data = rain_c + rain_nc

        else:
            self.data = self._load_lsm_data(lsm_var,
                                            self.netcdf_attributes[gssha_var]['conversion_factor'][load_type],
                                            self.netcdf_attributes[gssha_var].get('calc_4d_method'),
                                            self.netcdf_attributes[gssha_var].get('calc_4d_dim'),
                                            time_step=time_step)
            conversion_function = self.netcdf_attributes[gssha_var].get('conversion_function')
            if conversion_function:
                self.data.values = self.netcdf_attributes[gssha_var]['conversion_function'][load_type](self.data.values)

        if 'precipitation' in gssha_var:
            # NOTE: Precipitation is converted from mm/s to mm/hr
            # with the conversion factor when it is a rate.
            if 'units' in self.data.attrs:
                if self.data.attrs['units'] == 'm':
                    # convert from m to mm
                    self.data.values *= 1000

            if load_type == 'ascii' or load_type == 'netcdf':
                # CONVERT TO INCREMENTAL
                if gssha_var == 'precipitation_acc':
                    self.data.values = np.lib.pad(self.data.diff(self.lsm_time_dim).values,
                                                  ((1, 0), (0, 0), (0, 0)),
                                                  'constant',
                                                  constant_values=0)

                # CONVERT PRECIP TO RADAR (mm/hr) IN FILE
                if gssha_var == 'precipitation_inc' or gssha_var == 'precipitation_acc':
                    # convert from mm to mm/hr
                    time_step_hours = np.diff(self.xd[self.lsm_time_var].values)[0]/np.timedelta64(1, 'h')
                    self.data.values /= time_step_hours

        # convert to dataset
        gssha_data_var_name = self.netcdf_attributes[gssha_var]['gssha_name']
        self.data = self.data.to_dataset(name=gssha_data_var_name)
        self.data.rename(
            {
                self.lsm_lon_dim: 'x',
                self.lsm_lat_dim: 'y',
                self.lsm_lon_var: 'lon',
                self.lsm_lat_var: 'lat'
            },
            inplace=True
        )
        self.data.attrs = {'proj4': self.xd.lsm.projection.ExportToProj4()}
        self.data[gssha_data_var_name].attrs = {
           'standard_name': self.netcdf_attributes[gssha_var]['standard_name'],
           'long_name': self.netcdf_attributes[gssha_var]['long_name'],
           'units': self.netcdf_attributes[gssha_var]['units'][load_type],
        }