MoonRaker / pvlib-python

A set of documented functions for simulating the performance of photovoltaic energy systems.
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

data_labels pattern #13

Closed wholmgren closed 8 years ago

wholmgren commented 9 years ago

I would like to find something better for the current data_labels pattern. Here's how it currently works:

The ForecastModel class defines the columns class attribute as:

    columns = np.array(['temperature',
                        'temperature_iso',
                        'wind_speed',
                        'wind_speed_gust',
                        'pressure',
                        'total_clouds',
                        'low_clouds',
                        'mid_clouds',
                        'high_clouds',
                        'boundary_clouds',
                        'convect_clouds',
                        'downward_shortwave_radflux',
                        'downward_shortwave_radflux_avg',])

Then, the subclasses define something like:

        variables = ['Temperature_isobaric',
                     'Wind_speed_gust_surface',
                     'Pressure_surface',
                     'Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average',
                     'Total_cloud_cover_low_cloud_Mixed_intervals_Average',
                     'Total_cloud_cover_middle_cloud_Mixed_intervals_Average',
                     'Total_cloud_cover_high_cloud_Mixed_intervals_Average',
                     'Total_cloud_cover_boundary_layer_cloud_Mixed_intervals_Average',
                     'Total_cloud_cover_convective_cloud',
                     'Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average',]
        cols = super(GFS, self).columns
        idx = [1,3,4,5,6,7,8,9,10]
        data_labels = dict(zip(cols[idx],variables))

This relies on idx and the ordering of columns, which seems fragile. How can we make this more robust? I might prefer manually creating the data_labels dict in the __init__ method of each class.

Also, data_labels or data_mapping?

If data_mapping, that implies that the values could be any kind of function, as in:

data_mapping['temperature'] = self.data['Temperature_isobaric']
data_mapping['wind_speed'] = self.wind_speed(self.data['u'], self.data['v'])

and that you'd need a separate request_variables or similar attribute/parameter.

MoonRaker commented 8 years ago

The data_labels dictionary has been replaced by the variables dictionary in init that doesn't use indexing. This resulted in a modelvariables and queryvariables attribute in the models along with a dataframe_variables attribute.