vicelab / cen-sierra-pywr

Code base for modeling the central Sierra Nevada hydropower systems
3 stars 5 forks source link

IFR lookup performance improvements needed #72

Open drheinheimer opened 4 years ago

drheinheimer commented 4 years ago

Many IFRs with a lookup table in Stanislaus are currently very poorly coded. We need to identify ways to improve performance to be able to achive the modeling vision.

I've posted some initial tips in the Wiki.

The general plan is to refactor along these lines:

  1. Tighten up the core Python logic.
  2. Modify the actual csv lookup files (both daily and monthly)
  3. Modify the JSON file to read in the first column as an index (note that IFR schedules should at this point generally be read in via the "tables" section of the JSON file).
drheinheimer commented 4 years ago

Here's an example:

        if self.model.mode == 'scheduling':
            month = timestep.month
            day = timestep.day
            if (2, 10) <= (month, day) <= (5, 31):
                start_day = 10
            else:
                start_day = 1
            if 2 <= month <= 5 and day <= 9:
                start_month = month - 1
            else:
                start_month = month
            start_date = '{}-{}'.format(start_month, start_day)
            ifr_val = schedule.at[start_date, WYT_str]
        else:
            ifr_val = schedule.at[self.datetime.month, WYT_str]

In this example, the start_date is somewhat complex, but overall straightforward. Most IFR schedules are less complex.