Example #1
0
 def test_tool_reorder_featureinput3(self):
     '''Verify missing keys are added if few args given.'''
     for value in self.converted_FI.values():
         reordered_FI = ut.reorder_featureinput(self.FI, ['Model', 'Geometry'])
         actual = set(reordered_FI.keys())
         expected = set(
             ['Model', 'Geometry', 'Materials', 'Parameters', 'Globals', 'Properties']
         )
         nt.assert_equals(actual, expected)
Example #2
0
 def test_tool_reorder_featureinput1(self):
     '''Verify default list order if no args given.'''
     for value in self.converted_FI.values():
         reordered_FI = ut.reorder_featureinput(self.FI)
         actual = list(reordered_FI.keys())
         expected = [
             'Geometry', 'Model', 'Materials', 'Parameters', 'Globals',
             'Properties'
         ]
         nt.assert_equals(actual, expected)
Example #3
0
 def test_tool_reorder_featureinput2(self):
     '''Verify reorder dict keys if keys given.'''
     for value in self.converted_FI.values():
         rev_keys = reversed(
             ['Geometry', 'Model', 'Materials', 'Parameters', 'Globals',
              'Properties']
         )
         reordered_FI = ut.reorder_featureinput(self.FI, keys=rev_keys)
         actual = list(reordered_FI.keys())
         expected = [
             'Properties', 'Globals', 'Parameters', 'Materials', 'Model',
             'Geometry'
         ]
         nt.assert_equals(actual, expected)
Example #4
0
    def to_xlsx(self, filename=None, offset=3, temp=False, overwrite=False,
                prefix=None, keepname=True, order=None, delete=False):
        '''Write all LaminateModels and FeatureInput dashboards as one file.

        Returns
        -------
        str
            Path name of the written file.

        See Also
        --------
        - `utils.tools.export`: for comparable kwargs and docstring.
        - `utils.tools.reorder_featureinput`: for order of dashboard data

        Notes
        -----
        All files for a given case are written to one file.

        This is a reimplementation of the pandas `to_excel` method.  This is
        separated from `export` due to how sheets are added in the ExcelWriter.

        '''
        if filename is None:
            filename = 'case_LaminateModels'
        if prefix is None:
            prefix = ''
        suffix = '.xlsx'

        if temp:
            data_des, workbook_filepath = tempfile.mkstemp(suffix=suffix)
        else:
            workbook_filepath = ut.get_path(filename, suffix=suffix, overwrite=overwrite)

        try:
            # Excel code block ----------------------------------------------------
            writer = pd.ExcelWriter(workbook_filepath)
            for LM in self.LMs:
                # Parse LaminateModel variables
                ##nplies = LM.nplies
                ##p = LM.p
                # TODO: Fix units
                ##t_total = LM.total * 1e3                   # (in mm)
                geo_string = LM.Geometry.string
                FI = LM.FeatureInput
                data_df = LM.LMFrame
                converted_FI = ut.convert_featureinput(FI)
                reordered_FI = ut.reorder_featureinput(converted_FI, order)

                # Data sheet
                sheetname = geo_string.replace('[', '|').replace(']', '|')
                data_sheetname = ' '.join(['Data', sheetname])
                data_df.to_excel(writer, data_sheetname)

                # Dashboard sheet
                dash_sheetname = ' '.join(['Dash', sheetname])
                for i, dict_df in enumerate(reordered_FI.values()):
                    if dict_df.size == 1:                      # assumes string strs are ordered first
                        dict_df.to_excel(writer, dash_sheetname, startrow=4**i)
                    else:
                        dict_df.to_excel(writer, dash_sheetname, startcol=(i-1)*offset)

            writer.save()

            if temp:
                os.close(data_des)

            if temp and keepname:
                workbook_filepath = ut.rename_tempfile(
                    workbook_filepath, ''.join(['t_', filename, suffix]))
                logging.info('Data and dashboard written as {} file in: {}'.format(
                    suffix, workbook_filepath))
        finally:
            if delete:
                os.remove(workbook_filepath)
                logging.info('File has been deleted: {}'.format(workbook_filepath))
            pass

        return workbook_filepath