예제 #1
0
    def check_num_radiation_transitions_other_source(
            self,
            column,
            other_radiation,
            num_diff_radiation_transitions_thresold,
            radiation_threshold=None,
            label_other='_other'):

        name_check_function = inspect.getframeinfo(
            inspect.currentframe()).function

        if radiation_threshold is None:
            radiation_threshold = DNI_RADIATION_THRESHOLD

        column_other = other_radiation.name + label_other

        other_radiation_filt = other_radiation.copy(
        )[lambda x: x > radiation_threshold]
        radiation_filt = self.df[column][lambda x: x > radiation_threshold]

        if len(radiation_filt) == 0:  # Avoids future errors
            return None

        num_radiation_transitions_value = mc_solar.num_radiation_transitions(
            radiation_filt)
        num_radiation_transitions_value_other = mc_solar.num_radiation_transitions(
            other_radiation_filt)

        condition_list = abs(num_radiation_transitions_value -
                             num_radiation_transitions_value_other
                             ) < num_diff_radiation_transitions_thresold

        buffer = None

        if not condition_list:
            plt.figure()
            radiation_filt.plot(style='.-')
            other_radiation_filt.plot(style='.-')
            plt.legend([column, column_other])
            plt.title(name_check_function + ':' + column)
            plt.suptitle(self.type_data_station, fontsize=18)

            buffer = io.BytesIO()
            plt.savefig(buffer)
            buffer.seek(0)

        self.assertion_base(
            condition=condition_list,
            error_message=
            'No coherence of cloudy moments between {} and {} radiation sources with {} and {} respectively. Maximum allowed difference: {}'
            .format(column, column_other, num_radiation_transitions_value,
                    num_radiation_transitions_value_other,
                    num_diff_radiation_transitions_thresold),
            check_type=name_check_function,
            figure=buffer)
예제 #2
0
    def check_same_magnitude_total_irradiation(self, column, column_other,
                                               threshold_pct):

        name_check_function = inspect.getframeinfo(
            inspect.currentframe()).function

        irradiation = mc_solar.daily_irradiation(
            self.df[column], samples_per_hour=self.samples_per_hour)
        irradiation_other = mc_solar.daily_irradiation(
            self.df[column_other], samples_per_hour=self.samples_per_hour)

        if irradiation < DAILY_IRRADIATION_THRESHOLD:  # Avoids future errors
            return None

        diff_radiation = abs(irradiation -
                             irradiation_other) / irradiation * 100

        condition_list = diff_radiation < threshold_pct

        buffer = None

        if not (condition_list):
            plt.figure()
            self.df[column].plot(style='k.')
            self.df[column_other].plot(style='r.')
            plt.legend([column, column_other])
            plt.title(name_check_function + ':' + column + '&' + column_other +
                      ' with thresold_pct=' + str(threshold_pct))
            plt.suptitle(self.type_data_station, fontsize=18)

            buffer = io.BytesIO()
            plt.savefig(buffer)
            buffer.seek(0)

        irrad_filt = self.df[column][lambda m: m > DNI_RADIATION_THRESHOLD]
        num_radiation_transitions_value = mc_solar.num_radiation_transitions(
            irrad_filt)

        if num_radiation_transitions_value < NUM_RADIATION_TRANSITIONS_THRESHOLD:
            self.assertion_base(
                condition=condition_list,
                error_message=
                'Total irradiation from {} is different to {} in more than {}%. It is {:.1f}% while DAILY_IRRADIATION_THRESHOLD is {:.2} kWh/(m2·day)'
                .format(column, column_other, threshold_pct, diff_radiation,
                        DAILY_IRRADIATION_THRESHOLD),
                check_type=name_check_function,
                figure=buffer)
        else:
            self.assertion_base(
                condition=False,
                error_message=
                'Comparison of total irradiations {} and {} not checked because the number of cloudy moments={} [with a DRADIATION_DT={}] is higher than threshold={}'
                .format(column, column_other, num_radiation_transitions_value,
                        DRADIATION_DT, NUM_RADIATION_TRANSITIONS_THRESHOLD),
                error_level='INFO',
                check_type=name_check_function,
                figure=buffer)
예제 #3
0
    def check_coherence_isotypes(self,
                                 dni,
                                 top,
                                 mid,
                                 bot,
                                 threshold_pct,
                                 radiation_threshold=None):
        #         Check radiation coherence between DNI and isotypes
        #         THRESHOLD is in percentage
        name_check_function = inspect.getframeinfo(
            inspect.currentframe()).function

        if radiation_threshold is None:
            radiation_threshold = DNI_RADIATION_THRESHOLD

        df_filt = self.df[self.df[dni] > DNI_RADIATION_THRESHOLD]

        if len(df_filt) == 0:  # Avoids future errors
            return None

        dni_model = (df_filt[top] * 0.51 + df_filt[mid] * 0.10 +
                     df_filt[bot] * 0.39)

        condition_list = (((df_filt[dni] - dni_model).abs()) / df_filt[dni] *
                          100 < threshold_pct)

        buffer = None
        if not condition_list.all():
            plt.figure()
            df_filt[dni].plot(style='k.')
            df_filt[top].plot(style='.')
            df_filt[mid].plot(style='.')
            df_filt[bot].plot(style='.')
            df_filt[dni][~condition_list].plot(marker='P',
                                               markersize=8,
                                               color='darkred',
                                               markeredgecolor='yellow',
                                               markeredgewidth=2)
            plt.legend([top, mid, bot])
            plt.title(name_check_function)
            plt.suptitle(self.type_data_station, fontsize=18)

            buffer = io.BytesIO()
            plt.savefig(buffer)
            buffer.seek(0)

        irrad_filt = self.df[dni][lambda m: m > DNI_RADIATION_THRESHOLD]
        num_radiation_transitions_value = mc_solar.num_radiation_transitions(
            irrad_filt)

        if num_radiation_transitions_value < NUM_RADIATION_TRANSITIONS_THRESHOLD:
            self.assertion_base(
                condition=condition_list.all(),
                error_message=
                'No coherence between DNI radiation and isotypes considering a percentage threshold of {} % in {}'
                .format(threshold_pct, df_filt[dni][~condition_list].index),
                check_type=name_check_function,
                figure=buffer)
        else:
            self.assertion_base(
                condition=False,
                error_message=
                'DNI vs isotypes comparison not checked because the number of cloudy moments={} [with a DRADIATION_DT={}] is higher than threshold={}'
                .format(num_radiation_transitions_value, DRADIATION_DT,
                        NUM_RADIATION_TRANSITIONS_THRESHOLD),
                error_level='INFO',
                check_type=name_check_function,
                figure=buffer)
예제 #4
0
    def check_radiation_other_source(self,
                                     column,
                                     other_radiation,
                                     threshold_pct,
                                     radiation_threshold=None,
                                     label_other='_other'):

        name_check_function = inspect.getframeinfo(
            inspect.currentframe()).function

        if radiation_threshold is None:
            radiation_threshold = DNI_RADIATION_THRESHOLD

        other_radiation_copy = other_radiation.copy()

        other_radiation_copy.name += label_other
        column_other = other_radiation_copy.name

        df_joined = self.df.join(other_radiation_copy, how='inner')

        df_filt = df_joined[df_joined[column] > radiation_threshold]

        if len(df_filt) == 0:  # Avoids future errors
            return None

        condition_list = (df_filt[column] - df_filt[column_other]
                          ).abs() / df_filt[column_other] * 100 < threshold_pct

        buffer = None
        if not condition_list.all():
            plt.figure()
            df_filt[column].plot(style='.')
            df_filt[column_other].plot(style='.')
            df_filt[column][~condition_list].plot(style='rP')
            plt.legend([column, column_other])
            plt.title(name_check_function + ':' + column)
            plt.suptitle(self.type_data_station, fontsize=18)

            buffer = io.BytesIO()
            plt.savefig(buffer)
            buffer.seek(0)

        irrad_filt = self.df[column][lambda m: m > DNI_RADIATION_THRESHOLD]
        num_radiation_transitions_value = mc_solar.num_radiation_transitions(
            irrad_filt)

        if num_radiation_transitions_value < NUM_RADIATION_TRANSITIONS_THRESHOLD:
            self.assertion_base(
                condition=condition_list.all(),
                error_message=
                'No coherence between {} and {} radiation sources considering a percentage THRESHOLD of {} % in {}'
                .format(column, column_other, threshold_pct,
                        df_filt[column][~condition_list].index),
                check_type=name_check_function,
                figure=buffer)
        else:
            self.assertion_base(
                condition=False,
                error_message=
                'Comparison of radiation {} and {} from different sources not checked because the number of cloudy moments={} [with a DRADIATION_DT={}] is higher than threshold={}'
                .format(column, column_other, num_radiation_transitions_value,
                        DRADIATION_DT, NUM_RADIATION_TRANSITIONS_THRESHOLD),
                error_level='INFO',
                check_type=name_check_function,
                figure=buffer)
예제 #5
0
    def check_coherence_radiation(self,
                                  threshold_pct,
                                  dni,
                                  ghi,
                                  dhi,
                                  radiation_threshold=None):
        # Check radiation coherence between GHI and DNI&DHI
        # THRESHOLD is in percentage

        name_check_function = inspect.getframeinfo(
            inspect.currentframe()).function

        if radiation_threshold is None:
            radiation_threshold = GHI_RADIATION_THRESHOLD

        df_filt = self.df[self.df[ghi] > GHI_RADIATION_THRESHOLD]

        if len(df_filt) == 0:  # Avoids future errors
            return None

        _, Zz = mc_solar.solpos(df_filt.index)

        ghi_model = (df_filt[dhi] + df_filt[dni] * np.cos(Zz))

        condition_list = (((df_filt[ghi] - ghi_model).abs()) / df_filt[ghi] *
                          100 < threshold_pct)

        buffer = None
        if not condition_list.all():
            plt.figure()
            df_filt[ghi].plot(style='.')
            df_filt[ghi][~condition_list].plot(style='rP')
            #            plt.legend()
            plt.title(name_check_function)
            plt.suptitle(self.type_data_station, fontsize=18)

            buffer = io.BytesIO()
            plt.savefig(buffer)
            buffer.seek(0)

        num_radiation_transitions_value = mc_solar.num_radiation_transitions(
            self.df[ghi])

        if num_radiation_transitions_value < NUM_RADIATION_TRANSITIONS_THRESHOLD:
            self.assertion_base(
                condition=condition_list.all(),
                error_message=
                'No coherence between radiations considering a percentage threshold of GHI {}% in {}'
                .format(threshold_pct, df_filt[~condition_list].index),
                check_type=name_check_function,
                figure=buffer)
        else:
            self.assertion_base(
                condition=False,
                error_message=
                'Radiation coherence based on GHI not checked because the number of cloudy moments={} [with a DRADIATION_DT={}] is higher than threshold={}'
                .format(num_radiation_transitions_value, DRADIATION_DT,
                        NUM_RADIATION_TRANSITIONS_THRESHOLD),
                error_level='INFO',
                check_type=name_check_function,
                figure=buffer)