Пример #1
0
 def test_all(self):
     """Loop and subtest."""
     for t in self.a:
         actual = t[0]()
         expected = _df.read_pickle(t[1])
         with self.subTest(msg=t[1]):
             _df.ensure_frame_equal_except_mrid(actual, expected)
Пример #2
0
    def test_sparql_manager_query_measurements_for_bus_not_empty(self):
        # Grab the substation source bus.
        sub = _df.read_pickle(_df.SUBSTATION_9500)
        bus_mrid = sub.iloc[0]['bus_mrid']

        # Query to get measurements.
        actual = self.sparql.query_measurements_for_bus(bus_mrid=bus_mrid)

        # Ensure we get 6 back (3 phases, current and voltage)
        self.assertEqual(actual.shape[0], 6)
Пример #3
0
    def test_integrated(self):
        """Use an actual switch manager."""
        switch_df = _df.read_pickle(_df.SWITCHES_9500)
        switches = equipment.initialize_switches(switch_df)
        switch_meas = _df.read_pickle(_df.SWITCH_MEAS_9500)
        switch_mgr = equipment.EquipmentManager(
            eq_dict=switches,
            eq_meas=switch_meas,
            eq_mrid_col=sparql.SWITCH_MEAS_SWITCH_MRID_COL,
            meas_mrid_col=sparql.SWITCH_MEAS_MEAS_MRID_COL)

        # Switch manager should have no callbacks.
        self.assertEqual(0, len(switch_mgr._callbacks))

        # Create a mock ga object.
        mock_ga = MagicMock(spec=ga.GA)

        # Create the stopper.
        stopper = app.GAStopper(ga_obj=mock_ga,
                                eq_mgr=switch_mgr,
                                eq_type='switch')

        # After creating the stopper, our switch manager should have a
        # callback.
        self.assertEqual(1, len(switch_mgr._callbacks))

        # stop should not have been called yet.
        self.assertEqual(mock_ga.stop.call_count, 0)

        # Load the switch message.
        with open(_df.SWITCH_MEAS_MSG_9500, 'r') as f:
            msg = json.load(f)

        # We need a datetime object.
        dt = datetime(2019, 10, 31, 18, 23)

        # When we call update state, our stopper callback should be hit,
        # thus triggering a log message.
        with self.assertLogs(logger=stopper.log):
            switch_mgr.update_state(msg=msg, sim_dt=dt)

        self.assertEqual(mock_ga.stop.call_count, 1)
Пример #4
0
    def test_9500(self):
        """Just ensure the method runs for the 9500 node model."""
        # Read inverter data.
        inverter_df = _df.read_pickle(_df.INVERTERS_9500)
        inverters = equipment.initialize_inverters(inverter_df)

        # Initialize a GLMManager.
        glm_mgr = glm.GLMManager(model=IEEE_9500, model_is_path=True)

        with self.assertLogs(app.LOG, 'INFO') as cm:
            app._update_inverter_state_in_glm(glm_mgr=glm_mgr,
                                              inverters=inverters)

        # Ensure no errors were logged.
        self.assertEqual(1, len(cm.output))
Пример #5
0
    def test_sparql_manager_query_capacitor_measurements_expected(self):
        """The 9500 node system has a weird capacitor setup:

        3 3 phase units, but each phase counted as an individual.
        1 uncontrollable 3 phase unit, counted as a group.
        """
        actual = self.sparql.query_capacitor_measurements()

        # Read expected value.
        expected = _df.read_pickle(_df.CAP_MEAS_9500)

        _df.ensure_frame_equal_except_mrid(actual, expected)

        # Ensure we get measurements associated with 10 capacitors.
        # (3 * 3) + 1, see docstring.
        caps = actual['cap_mrid'].unique()
        self.assertEqual(10, len(caps))

        # Ensure the measurements are unique.
        self.assertEqual(actual['state_meas_mrid'].unique().shape[0],
                         actual.shape[0])
Пример #6
0
    def setUpClass(cls):
        # Initialize inverters and switches.
        inverter_df = _df.read_pickle(_df.INVERTERS_9500)
        inverters = equipment.initialize_inverters(inverter_df)
        inverter_meas = _df.read_pickle(_df.INVERTER_MEAS_9500)
        inverter_mgr = equipment.PQEquipmentManager(
            eq_dict=inverters,
            eq_meas=inverter_meas,
            eq_mrid_col=sparql.INVERTER_MEAS_INV_MRID_COL,
            meas_mrid_col=sparql.INVERTER_MEAS_MEAS_MRID_COL)

        switch_df = _df.read_pickle(_df.SWITCHES_9500)
        switches = equipment.initialize_switches(switch_df)
        switch_meas = _df.read_pickle(_df.SWITCH_MEAS_9500)
        switch_mgr = equipment.EquipmentManager(
            eq_dict=switches,
            eq_meas=switch_meas,
            eq_mrid_col=sparql.SWITCH_MEAS_SWITCH_MRID_COL,
            meas_mrid_col=sparql.SWITCH_MEAS_MEAS_MRID_COL)

        machine_df = _df.read_pickle(_df.SYNCH_MACH_9500)
        machines = equipment.initialize_synchronous_machines(machine_df)
        machine_meas = _df.read_pickle(_df.SYNCH_MACH_MEAS_9500)
        machine_mgr = equipment.PQEquipmentManager(
            eq_dict=machines,
            eq_meas=machine_meas,
            eq_mrid_col=sparql.SYNCH_MACH_MEAS_MACH_COL,
            meas_mrid_col=sparql.SYNCH_MACH_MEAS_MEAS_COL)
        bogus_dt = datetime(2011, 8, 1, 12)

        # Update inverters, switches, and machines with measurements.
        with open(_df.INVERTER_MEAS_MSG_9500, 'r') as f:
            inverter_meas_msg = json.load(f)

        inverter_mgr.update_state(msg=inverter_meas_msg, sim_dt=bogus_dt)

        with open(_df.SWITCH_MEAS_MSG_9500, 'r') as f:
            switch_meas_msg = json.load(f)

        switch_mgr.update_state(msg=switch_meas_msg, sim_dt=bogus_dt)

        with open(_df.SYNCH_MACH_MEAS_MSG_9500, 'r') as f:
            mach_meas_msg = json.load(f)

        machine_mgr.update_state(msg=mach_meas_msg, sim_dt=bogus_dt)

        # Initialize GLM Manager.
        cls.glm_mgr = glm.GLMManager(IEEE_9500)

        # Prep and update the manager.
        app._prep_glm(cls.glm_mgr)
        app._update_glm_inverters_switches_machines(glm_mgr=cls.glm_mgr,
                                                    inverters=inverters,
                                                    switches=switches,
                                                    machines=machines)

        cls.starttime = datetime(2013, 4, 1, 12, 0)
        cls.stoptime = datetime(2013, 4, 1, 12, 1)
        cls.out_file = 'tmp.glm'

        # Prep the manager again via the GA's method.
        ga.prep_glm_mgr(cls.glm_mgr, cls.starttime, cls.stoptime)

        # Write file.
        cls.glm_mgr.write_model(cls.out_file)
Пример #7
0
 def setUpClass(cls) -> None:
     cls.mach_df = _df.read_pickle(_df.SYNCH_MACH_9500)
Пример #8
0
 def setUpClass(cls) -> None:
     cls.switch_df = _df.read_pickle(_df.SWITCHES_9500)