Exemple #1
0
    def test_remove_end_entries_by_pred(self):
        converter = MaccorToBiologicMb()
        fp = os.path.join(TEST_FILE_DIR, "diagnosticV4.000")
        maccor_ast = converter.load_maccor_ast(fp)

        def pred(end_entry, step_num):
            goto_step = int(end_entry["Step"])
            # filter all goto step 70s, except when that is Next Step
            return goto_step != 70 or step_num == 69

        filtered_ast = converter.remove_end_entries_by_pred(maccor_ast, pred)
        filtered_steps = filtered_ast["MaccorTestProcedure"]["ProcSteps"][
            "TestStep"]

        step_1_filtered_end_entry = filtered_steps[0]["Ends"]["EndEntry"]
        self.assertEqual(
            OrderedDict,
            type(step_1_filtered_end_entry),
        )
        self.assertEqual(step_1_filtered_end_entry["Step"], "002")

        step_68_filtered_end_entry = filtered_steps[68]["Ends"]["EndEntry"]
        self.assertEqual(
            OrderedDict,
            type(step_68_filtered_end_entry),
        )
        self.assertEqual(step_68_filtered_end_entry["Step"], "070")
        pass
Exemple #2
0
    def proc_step_to_seq_test(self, test_step_xml, diff_dict):
        """
        test utility for testing proc_step_to_seq
         """
        proc = xmltodict.parse(test_step_xml)
        test_step = proc["MaccorTestProcedure"]["ProcSteps"]["TestStep"]
        converter = MaccorToBiologicMb()

        expected = converter.blank_seq.copy()
        expected["Ns"] = 0
        expected["lim1_seq"] = 1
        expected["lim2_seq"] = 1
        expected["lim3_seq"] = 1
        expected.update(diff_dict)

        seq_num_by_step_num = {
            1: 0,
            2: 1,
        }

        result = converter._proc_step_to_seq(test_step, 1, seq_num_by_step_num,
                                             0, 2)
        for key, value in expected.items():
            self.assertEqual(
                value,
                result[key],
                msg="Expected {0}: {1} got {0}: {2}".format(
                    key, value, result[key]),
            )
Exemple #3
0
    def test_apply_step_mappings_global_voltage(self):
        xml = (step_with_bounds_template).format(
            voltage_v_lowerbound=2.2,
            voltage_v_upperbound=4.2,
            current_a_lowerbound=0.1,
            current_a_upperbound=1.0,
        )
        step = get(
            xmltodict.parse(xml,
                            process_namespaces=False,
                            strip_whitespace=True),
            'TestStep',
        )
        converter = MaccorToBiologicMb()

        converter.max_voltage_v = 3.9
        converter.min_voltage_v = 3.1
        step_without_voltage_end_entries = converter._apply_step_mappings(
            [step])[0]

        end_entries = get(step_without_voltage_end_entries, "Ends.EndEntry")
        self.assertEqual(2, len(end_entries))
        self.assertEqual("Current", get(end_entries[0], "EndType"))
        self.assertEqual("Current", get(end_entries[1], "EndType"))

        # check there was not mutation
        original_end_entries = get(step, 'Ends.EndEntry')
        self.assertEqual(4, len(original_end_entries))
Exemple #4
0
    def test_apply_step_mappings_global_noop(self):
        xml = (step_with_bounds_template).format(
            voltage_v_lowerbound=2.2,
            voltage_v_upperbound=4.2,
            current_a_lowerbound=0.1,
            current_a_upperbound=1.0,
        )
        step = get(
            xmltodict.parse(xml,
                            process_namespaces=False,
                            strip_whitespace=True),
            'TestStep',
        )
        converter = MaccorToBiologicMb()

        # no limits no mappings
        unmapped_step = converter._apply_step_mappings([step])[0]
        self.assertEqual(step, unmapped_step)

        # limits outside of bounds, don't
        converter.max_voltage_v = 10.0
        converter.min_voltage_v = -10.0
        converter.max_current_a = 10.0
        converter.min_current_a = -10.0
        unmapped_step = converter._apply_step_mappings([step])[0]
        self.assertEqual(step, unmapped_step)
Exemple #5
0
 def test_convert_time(self):
     converter = MaccorToBiologicMb()
     tests = [("::.01", "10.000", "ms"), ("03::", "3.000", "h"),
              ("03:30:", "210.000", "mn"), ("00:00:50", "50.000", "s")]
     self.maccor_values_to_biologic_value_and_unit_test(
         converter._convert_time,
         tests,
     )
Exemple #6
0
 def test_convert_volts(self):
     converter = MaccorToBiologicMb()
     tests = [("0.1429", "142.900", "mV"), ("0.1429e3", "142.900", "V"),
              ("159.3624", "159362.400", "mV"), ("152.9", "152.900", "V")]
     self.maccor_values_to_biologic_value_and_unit_test(
         converter._convert_volts,
         tests,
     )
Exemple #7
0
    def test_convert_protocol_with_goto_end_step(self):
        path = os.path.join(TEST_FILE_DIR, "goto_end_example.000")
        converter = MaccorToBiologicMb()
        ast = converter.load_maccor_ast(path)
        test_steps = get(ast, "MaccorTestProcedure.ProcSteps.TestStep")
        assert isinstance(test_steps, list)

        first_step = test_steps[0]
        first_step_goto = int(get(first_step, "Ends.EndEntry.Step"))
        assert first_step_goto == len(test_steps)
        assert first_step_goto not in [1, 2]

        converted_fp, rule_fps = converter.convert(path, TEST_FILE_DIR,
                                                   "to_delete")
        os.remove(converted_fp)
        for rule_fp in rule_fps:
            os.remove(rule_fp)
Exemple #8
0
 def test_convert_ohms(self):
     converter = MaccorToBiologicMb()
     tests = [("0.1429", "142.900", "mOhms"),
              ("1.459e4", "14.590", "kOhms"), ("152.9", "152.900", "Ohms"),
              ("1.2e-4", "120.000", "\N{Micro Sign}Ohms")]
     self.maccor_values_to_biologic_value_and_unit_test(
         converter._convert_ohms,
         tests,
     )
Exemple #9
0
 def test_convert_watts(self):
     converter = MaccorToBiologicMb()
     tests = [("0.1429", "142.900", "mW"), ("1.23", "1.230", "W"),
              ("152.9", "152.900", "W"),
              ("1.2e-5", "12.000", "\N{Micro Sign}W")]
     self.maccor_values_to_biologic_value_and_unit_test(
         converter._convert_watts,
         tests,
     )
Exemple #10
0
    def test_partition_steps_into_techniques(self):
        converter = MaccorToBiologicMb()
        ast = converter.load_maccor_ast(
            os.path.join(PROCEDURE_TEMPLATE_DIR, "diagnosticV5.000"))
        steps = get(ast, "MaccorTestProcedure.ProcSteps.TestStep")
        self.assertEqual(True, len(steps) > 71)

        # existence of looped tech 2
        nested_loop_open_idx = 36
        nested_loop_open_type = get(steps[nested_loop_open_idx], 'StepType')
        self.assertEqual(nested_loop_open_type, "Do 1")
        nested_loop_close_idx = 68
        nested_loop_close_type = get(steps[nested_loop_close_idx], 'StepType')
        self.assertEqual(nested_loop_close_type, "Loop 1")

        technique_partitions = converter._partition_steps_into_techniques(
            steps)
        self.assertEqual(3, len(technique_partitions))
        partition1, partition2, partition3 = technique_partitions

        self.assertEqual(partition1.technique_num, 1)
        self.assertEqual(partition2.technique_num, 2)
        self.assertEqual(partition3.technique_num, 4)

        self.assertEqual(partition1.tech_does_loop, False)
        self.assertEqual(partition2.tech_does_loop, True)
        self.assertEqual(partition3.tech_does_loop, False)

        self.assertEqual(partition2.num_loops, 1000)

        self.assertEqual(partition1.step_num_offset, 0)
        self.assertEqual(partition2.step_num_offset, nested_loop_open_idx + 1)
        self.assertEqual(partition3.step_num_offset, nested_loop_close_idx + 1)

        self.assertEqual(len(partition1.steps), 36)
        # trim opening/closing loops
        self.assertEqual(len(partition2.steps),
                         nested_loop_close_idx - nested_loop_open_idx - 1)
        self.assertEqual(len(partition3.steps), 27)
    def proc_step_to_seq_test(self, test_step_xml, diff_dict):
        """
        test utility for testing proc_step_to_seq
         """
        proc = xmltodict.parse(test_step_xml)
        test_step = proc["MaccorTestProcedure"]["ProcSteps"]["TestStep"]
        converter = MaccorToBiologicMb()

        expected = {}
        expected.update(converter.blank_seq)
        expected.update(diff_dict)

        result = converter._proc_step_to_seq(
            test_step,
            "0",
        )
        for key, value in expected.items():
            self.assertEqual(
                value,
                result[key],
                msg="Expected {0}: {1} got {0}: {2}".format(
                    key, value, result[key]),
            )
Exemple #12
0
    def single_step_to_single_seq_test(self, test_step_xml, diff_dict):
        """
        test utility for testing proc_step_to_seq
         """
        proc = xmltodict.parse(test_step_xml)
        test_step = proc["MaccorTestProcedure"]["ProcSteps"]["TestStep"]
        converter = MaccorToBiologicMb()

        expected = converter._blank_seq.copy()
        expected["Ns"] = 0
        expected["lim1_seq"] = 1
        expected["lim2_seq"] = 1
        expected["lim3_seq"] = 1
        expected.update(diff_dict)

        step_num = 1
        seq_nums_by_step_num = {
            step_num: [0],
            step_num + 1: [1],
        }

        result = converter._convert_step_parts(
            step_parts=[test_step],
            step_num=step_num,
            seq_nums_by_step_num=seq_nums_by_step_num,
            goto_lowerbound=0,
            goto_upperbound=3,
            end_step_num=4,
        )[0]

        for key, value in expected.items():
            self.assertEqual(
                value,
                result[key],
                msg="Expected {0}: {1} got {0}: {2}".format(
                    key, value, result[key]),
            )
Exemple #13
0
    def test_sample_conversion(self):
        # this test is super long but we want an E2E test that doesn't require us to inspect
        # a file and worry about things like encoding. Putting these strings in their own .py
        # file breaks our testing strategy so we're just keeping them here.

        maccor_ast = xmltodict.parse(
            ("<MaccorTestProcedure>"
             "  <header>"
             "    <BuildTestVersion>"
             "      <major>1</major>"
             "      <minor>5</minor>"
             "      <release>7006</release>"
             "      <build>32043</build>"
             "    </BuildTestVersion>"
             "    <FileFormatVersion>"
             "      <BTVersion>11</BTVersion>"
             "    </FileFormatVersion>"
             "    <ProcDesc>"
             "      <desc></desc>"
             "    </ProcDesc>"
             "  </header>"
             "  <ProcSteps>"
             "    <TestStep>"
             "      <StepType>  Rest  </StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends>"
             "        <EndEntry>"
             "          <EndType>StepTime</EndType>"
             "          <SpecialType> </SpecialType>"
             "          <Oper> = </Oper>"
             "          <Step>002</Step>"
             "          <Value>03:00:00</Value>"
             "        </EndEntry>"
             "      </Ends>"
             "      <Reports>"
             "        <ReportEntry>"
             "          <ReportType>StepTime</ReportType>"
             "          <Value>00:00:30</Value>"
             "        </ReportEntry>"
             "      </Reports>"
             "      <Range>4</Range>"
             "      <Option1>N</Option1>"
             "      <Option2>N</Option2>"
             "      <Option3>N</Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType> Charge </StepType>"
             "      <StepMode>Current </StepMode>"
             "      <StepValue>1.0</StepValue>"
             "      <Limits/>"
             "      <Ends>"
             "        <EndEntry>"
             "          <EndType>StepTime</EndType>"
             "          <SpecialType> </SpecialType>"
             "          <Oper> = </Oper>"
             "          <Step>003</Step>"
             "          <Value>00:00:01</Value>"
             "        </EndEntry>"
             "      </Ends>"
             "      <Reports>"
             "        <ReportEntry>"
             "          <ReportType>StepTime</ReportType>"
             "          <Value>::.01</Value>"
             "        </ReportEntry>"
             "      </Reports>"
             "      <Range>A</Range>"
             "      <Option1>N</Option1>"
             "      <Option2>N</Option2>"
             "      <Option3>N</Option3>"
             "      <StepNote>resistance check</StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType>  Do 1  </StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends/>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType> Charge </StepType>"
             "      <StepMode>Voltage </StepMode>"
             "      <StepValue>3.3</StepValue>"
             "      <Limits/>"
             "      <Ends>"
             "        <EndEntry>"
             "          <EndType>Current </EndType>"
             "          <SpecialType> </SpecialType>"
             "          <Oper>&lt;= </Oper>"
             "          <Step>005</Step>"
             "          <Value>0.0286</Value>"
             "        </EndEntry>"
             "      </Ends>"
             "      <Reports>"
             "        <ReportEntry>"
             "          <ReportType>Voltage </ReportType>"
             "          <Value>0.001</Value>"
             "        </ReportEntry>"
             "        <ReportEntry>"
             "          <ReportType>StepTime</ReportType>"
             "          <Value>00:02:00</Value>"
             "        </ReportEntry>"
             "      </Reports>"
             "      <Range>A</Range>"
             "      <Option1>N</Option1>"
             "      <Option2>N</Option2>"
             "      <Option3>N</Option3>"
             "      <StepNote>reset cycle C/20</StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType> Loop 1 </StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends>"
             "        <EndEntry>"
             "          <EndType>Loop Cnt</EndType>"
             "          <SpecialType> </SpecialType>"
             "          <Oper> = </Oper>"
             "          <Step>007</Step>"
             "          <Value>2</Value>"
             "        </EndEntry>"
             "      </Ends>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType>  Do 1  </StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends/>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType> Charge </StepType>"
             "      <StepMode>Current </StepMode>"
             "      <StepValue>0.1429</StepValue>"
             "      <Limits>"
             "        <Voltage>4.2</Voltage>"
             "      </Limits>"
             "      <Ends>"
             "        <EndEntry>"
             "          <EndType>Current </EndType>"
             "          <SpecialType> </SpecialType>"
             "          <Oper>&lt;= </Oper>"
             "          <Step>008</Step>"
             "          <Value>0.0286</Value>"
             "        </EndEntry>"
             "      </Ends>"
             "      <Reports>"
             "        <ReportEntry>"
             "          <ReportType>Voltage </ReportType>"
             "          <Value>0.001</Value>"
             "        </ReportEntry>"
             "        <ReportEntry>"
             "          <ReportType>StepTime</ReportType>"
             "          <Value>00:02:00</Value>"
             "        </ReportEntry>"
             "      </Reports>"
             "      <Range>A</Range>"
             "      <Option1>N</Option1>"
             "      <Option2>N</Option2>"
             "      <Option3>N</Option3>"
             "      <StepNote>reset cycle C/20</StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType>AdvCycle</StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends/>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType> Loop 1 </StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends>"
             "        <EndEntry>"
             "          <EndType>Loop Cnt</EndType>"
             "          <SpecialType> </SpecialType>"
             "          <Oper> = </Oper>"
             "          <Step>01</Step>"
             "          <Value>2</Value>"
             "        </EndEntry>"
             "      </Ends>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType>AdvCycle</StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends/>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "    <TestStep>"
             "      <StepType>  End   </StepType>"
             "      <StepMode>        </StepMode>"
             "      <StepValue></StepValue>"
             "      <Limits/>"
             "      <Ends/>"
             "      <Reports/>"
             "      <Range></Range>"
             "      <Option1></Option1>"
             "      <Option2></Option2>"
             "      <Option3></Option3>"
             "      <StepNote></StepNote>"
             "    </TestStep>"
             "  </ProcSteps>"
             "</MaccorTestProcedure>"))

        expected_output = (
            "BT-LAB SETTING FILE\r\n"
            "\r\n"
            "Number of linked techniques : 1\r\n"
            "\r\n"
            "Filename : C:\\Users\\User\\Documents\\BT-Lab\\Data\\Grace\\BASF\\BCS - 171.64.160.115_Ja9_cOver70_CE3.mps\r\n\r\n"  # noqa
            "Device : BCS-805\r\n"
            "Ecell ctrl range : min = 0.00 V, max = 10.00 V\r\n"
            "Electrode material : \r\n"
            "Initial state : \r\n"
            "Electrolyte : \r\n"
            "Comments : \r\n"
            "Mass of active material : 0.001 mg\r\n"
            " at x = 0.000\r\n"  # leading space intentional
            "Molecular weight of active material (at x = 0) : 0.001 g/mol\r\n"
            "Atomic weight of intercalated ion : 0.001 g/mol\r\n"
            "Acquisition started at : xo = 0.000\r\n"
            "Number of e- transfered per intercalated ion : 1\r\n"
            "for DX = 1, DQ = 26.802 mA.h\r\n"
            "Battery capacity : 1.000 A.h\r\n"
            "Electrode surface area : 0.001 cm\N{superscript two}\r\n"
            "Characteristic mass : 8.624 mg\r\n"
            "Cycle Definition : Charge/Discharge alternance\r\n"
            "Do not turn to OCV between techniques\r\n"
            "\r\n"
            "Technique : 1\r\n"
            "Modulo Bat\r\n"
            "Ns                  0                   1                   2                   3                   4                   5                   6                   7                   8                   9                   \r\n"
            "ctrl_type           Rest                CC                  CV                  CV                  CV                  CC                  CV                  Loop                Loop                Loop                \r\n"
            "Apply I/C           I                   I                   I                   I                   I                   I                   I                   I                   I                   I                   \r\n"
            "ctrl1_val                               1.000               3.300               3.300               3.300               142.900             4.200               100.000             100.000             100.000             \r\n"
            "ctrl1_val_unit                          A                   V                   V                   V                   mA                  V                                                                               \r\n"
            "ctrl1_val_vs                            <None>              Ref                 Ref                 Ref                 <None>              Ref                                                                             \r\n"
            "ctrl2_val                                                                                                                                                                                                                   \r\n"
            "ctrl2_val_unit                                                                                                                                                                                                              \r\n"
            "ctrl2_val_vs                                                                                                                                                                                                                \r\n"
            "ctrl3_val                                                                                                                                                                                                                   \r\n"
            "ctrl3_val_unit                                                                                                                                                                                                              \r\n"
            "ctrl3_val_vs                                                                                                                                                                                                                \r\n"
            "N                   1.00                15.00               15.00               15.00               15.00               15.00               15.00                                                                           \r\n"
            "charge/discharge    Charge              Charge              Charge              Charge              Charge              Charge              Charge                                                                          \r\n"
            "ctrl_seq            0                   0                   0                   0                   0                   0                   0                   5                   0                   8                   \r\n"
            "ctrl_repeat         0                   0                   0                   0                   0                   0                   0                   1                   0                   1                   \r\n"
            "ctrl_trigger        Falling Edge        Falling Edge        Falling Edge        Falling Edge        Falling Edge        Falling Edge        Falling Edge        Falling Edge        Falling Edge        Falling Edge        \r\n"
            "ctrl_TO_t           0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               \r\n"
            "ctrl_TO_t_unit      d                   d                   d                   d                   d                   d                   d                   d                   d                   d                   \r\n"
            "ctrl_Nd             6                   6                   6                   6                   6                   6                   6                   6                   6                   6                   \r\n"
            "ctrl_Na             1                   1                   1                   1                   1                   1                   1                   1                   1                   1                   \r\n"
            "ctrl_corr           1                   1                   1                   1                   1                   1                   1                   1                   1                   1                   \r\n"
            "lim_nb              1                   1                   1                   1                   1                   1                   1                   0                   0                   0                   \r\n"
            "lim1_type           Time                Time                |I|                 |I|                 |I|                 Ecell               |I|                 Time                Time                Time                \r\n"
            "lim1_comp           >                   >                   <                   <                   <                   >                   <                   <                   <                   <                   \r\n"
            "lim1_Q              Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             \r\n"
            "lim1_value          3.000               1.000               28.600              28.600              28.600              4.200               28.600              0.000               0.000               0.000               \r\n"
            "lim1_value_unit     h                   s                   mA                  mA                  mA                  V                   mA                  s                   s                   s                   \r\n"
            "lim1_action         Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       \r\n"
            "lim1_seq            1                   2                   3                   4                   5                   6                   7                   8                   9                   10                  \r\n"
            "lim2_type           Time                Time                Time                Time                Time                Time                Time                Time                Time                Time                \r\n"
            "lim2_comp           <                   <                   <                   <                   <                   <                   <                   <                   <                   <                   \r\n"
            "lim2_Q              Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             \r\n"
            "lim2_value          0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               \r\n"
            "lim2_value_unit     s                   s                   s                   s                   s                   s                   s                   s                   s                   s                   \r\n"
            "lim2_action         Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       \r\n"
            "lim2_seq            1                   2                   3                   4                   5                   6                   7                   8                   9                   10                  \r\n"
            "lim3_type           Time                Time                Time                Time                Time                Time                Time                Time                Time                Time                \r\n"
            "lim3_comp           <                   <                   <                   <                   <                   <                   <                   <                   <                   <                   \r\n"
            "lim3_Q              Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             Q limit             \r\n"
            "lim3_value          0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               \r\n"
            "lim3_value_unit     s                   s                   s                   s                   s                   s                   s                   s                   s                   s                   \r\n"
            "lim3_action         Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       Next sequence       \r\n"
            "lim3_seq            1                   2                   3                   4                   5                   6                   7                   8                   9                   10                  \r\n"
            "rec_nb              1                   1                   2                   2                   2                   2                   2                   0                   0                   0                   \r\n"
            "rec1_type           Time                Time                Ecell               Ecell               Ecell               Ecell               Ecell               Time                Time                Time                \r\n"
            "rec1_value          30.000              10.000              1.000               1.000               1.000               1.000               1.000               10.000              10.000              10.000              \r\n"
            "rec1_value_unit     s                   ms                  mV                  mV                  mV                  mV                  mV                  s                   s                   s                   \r\n"
            "rec2_type           Time                Time                Time                Time                Time                Time                Time                Time                Time                Time                \r\n"
            "rec2_value          10.000              10.000              2.000               2.000               2.000               2.000               2.000               10.000              10.000              10.000              \r\n"
            "rec2_value_unit     s                   s                   mn                  mn                  mn                  mn                  mn                  s                   s                   s                   \r\n"
            "rec3_type           Time                Time                Time                Time                Time                Time                Time                Time                Time                Time                \r\n"
            "rec3_value          10.000              10.000              10.000              10.000              10.000              10.000              10.000              10.000              10.000              10.000              \r\n"
            "rec3_value_unit     s                   s                   s                   s                   s                   s                   s                   s                   s                   s                   \r\n"
            "E range min (V)     0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               0.000               \r\n"
            "E range max (V)     10.000              10.000              10.000              10.000              10.000              10.000              10.000              10.000              10.000              10.000              \r\n"
            "I Range             10 A                10 A                10 A                10 A                10 A                10 A                10 A                1 mA                1 mA                1 mA                \r\n"
            "I Range min         Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               \r\n"
            "I Range max         Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               \r\n"
            "I Range init        Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               Unset               \r\n"
            "auto rest           0                   0                   0                   0                   0                   0                   0                   0                   0                   0                   \r\n"
            "Bandwidth           4                   4                   4                   4                   4                   4                   4                   4                   4                   4                   \r\n"
        )

        expected_lines = expected_output.split("\r\n")

        converter = MaccorToBiologicMb()
        actual_output = converter.maccor_ast_to_protocol_str(maccor_ast,
                                                             unroll=True,
                                                             col_width=20)
        actual_lines = actual_output.split("\r\n")

        self.assertEqual(
            len(expected_lines),
            len(actual_lines),
        )
        for i in range(0, len(expected_lines)):
            msg = "At line {} expected:\n\"{}\"\ngot:\n\"{}\"".format(
                i + 1, expected_lines[i], actual_lines[i])

            self.assertEqual(expected_lines[i], actual_lines[i], msg)
        pass
Exemple #14
0
    def test_conversion_with_updated(self):
        converter = MaccorToBiologicMb()

        with ScratchDir(".") as scratch_dir:
            # Generate a protocol that can be used with the existing cells for testing purposes
            reg_params = {
                'project_name': {
                    0: 'FormDegrade'
                },
                'seq_num': {
                    0: 0
                },
                'template': {
                    0: 'diagnosticV5.000'
                },
                'charge_constant_current_1': {
                    0: 2.0
                },
                'charge_percent_limit_1': {
                    0: 30
                },
                'charge_constant_current_2': {
                    0: 2.0
                },
                'charge_cutoff_voltage': {
                    0: 4.4
                },
                'charge_constant_voltage_time': {
                    0: 60
                },
                'charge_rest_time': {
                    0: 5
                },
                'discharge_constant_current': {
                    0: 1.0
                },
                'discharge_cutoff_voltage': {
                    0: 3.0
                },
                'discharge_rest_time': {
                    0: 15
                },
                'cell_temperature_nominal': {
                    0: 25
                },
                'cell_type': {
                    0: 'LiFun240'
                },
                'capacity_nominal': {
                    0: 0.240
                },
                'diagnostic_type': {
                    0: 'HPPC+RPT'
                },
                'diagnostic_parameter_set': {
                    0: 'LiFunForm'
                },
                'diagnostic_start_cycle': {
                    0: 30
                },
                'diagnostic_interval': {
                    0: 100
                }
            }

            protocol_params_df = pd.DataFrame.from_dict(reg_params)
            index = 0
            protocol_params = protocol_params_df.iloc[index]
            diag_params_df = pd.read_csv(
                os.path.join(PROCEDURE_TEMPLATE_DIR,
                             "PreDiag_parameters - DP.csv"))
            diagnostic_params = diag_params_df[
                diag_params_df["diagnostic_parameter_set"] ==
                protocol_params["diagnostic_parameter_set"]].squeeze()

            procedure = Procedure.generate_procedure_regcyclev3(
                index, protocol_params)
            procedure.generate_procedure_diagcyclev3(
                protocol_params["capacity_nominal"], diagnostic_params)
            procedure.set_skip_to_end_diagnostic(4.5,
                                                 2.0,
                                                 step_key="070",
                                                 new_step_key="095")
            procedure.to_file(os.path.join(scratch_dir, "BioTest_000001.000"))

            # Setup the converter and run it
            def set_i_range(tech_num, seq, idx):
                seq_copy = copy.deepcopy(seq)
                seq_copy["I Range"] = "1 A"
                return seq_copy

            converter.seq_mappers.append(set_i_range)
            converter.min_voltage_v = 2.0
            converter.max_voltage_v = 4.5

            converter.convert(os.path.join(scratch_dir, "BioTest_000001.000"),
                              TEST_FILE_DIR, "BioTest_000001")
            f = open(os.path.join(TEST_FILE_DIR, "BioTest_000001.mps"),
                     encoding="ISO-8859-1")
            file = f.readlines()
            control_list = [
                'ctrl_type', 'Rest', 'CC', 'Rest', 'CC', 'CV', 'CC', 'Loop',
                'CC', 'CV', 'Rest', 'CC', 'Rest', 'CC', 'CC', 'Loop', 'CV',
                'CC', 'CC', 'CV', 'CC', 'CC', 'CV', 'CC', 'CC', 'CV', 'CC',
                'CC', 'CC', 'CV', 'Rest', 'CC', 'Rest', 'Loop'
            ]
            self.assertListEqual(control_list, file[35].split())
            value_list = [
                'ctrl1_val', '240.000', '34.300', '4.400', '34.300', '100.000',
                '80.000', '4.400', '240.000', '180.000', '80.000', '100.000',
                '3.000', '80.000', '48.000', '4.400', '48.000', '48.000',
                '4.400', '240.000', '48.000', '4.400', '480.000', '480.000',
                '480.000', '4.400', '240.000', '100.000'
            ]
            self.assertListEqual(value_list, file[37].split())

            voltage_min = '\tEcell min = 2.00 V\n'
            self.assertEqual(voltage_min, file[9])
            voltage_max = '\tEcell max = 4.50 V\n'
            self.assertEqual(voltage_max, file[10])