예제 #1
0
 def on_upload_file(self, event):
     wait = wx.BusyInfo('Validating data, please wait...')
     wx.Yield()
     res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(dir_path=self.WD,
                                                                               vocab=self.contribution.vocab)
     self.failing_items = all_failing_items
     if has_problems:
         self.validation_mode = set(has_problems)
         # highlighting doesn't work with Windows
         if sys.platform in ['win32', 'win62']:
             self.message.SetLabel('The following grid(s) have incorrect or incomplete data:\n{}'.format(', '.join(self.validation_mode)))
         # highlighting does work with OSX
         else:
             for dtype in ["specimens", "samples", "sites", "locations", "ages"]:
                 wind = self.FindWindowByName(dtype + '_btn')
                 if dtype not in has_problems:
                     wind.Unbind(wx.EVT_PAINT, handler=self.highlight_button)
                 else:
                     wind.Bind(wx.EVT_PAINT, self.highlight_button)
             self.Refresh()
             self.message.SetLabel('Highlighted grids have incorrect or incomplete data')
         self.bSizer_msg.ShowItems(True)
         self.hbox.Fit(self)
     if not has_problems:
         self.validation_mode = set()
         self.message.SetLabel('')
         self.bSizer_msg.ShowItems(False)
         self.hbox.Fit(self)
     del wait
예제 #2
0
    def on_btn_upload(self, event):
        outstring = "upload_magic.py"
        print "-I- running python script:\n %s" % (outstring)
        wait = wx.BusyInfo("Please wait, working...")
        wx.Yield()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(
                dir_path=self.WD, vocab=self.contribution.vocab)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(
                dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload.\n Your file: {}  was generated in MagIC Project Directory.\nDrag and drop this file in the MagIC database.".format(
                os.path.split(res)[1])
            dlg = wx.MessageDialog(self,
                                   caption="Saved",
                                   message=text,
                                   style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/Command Prompt for details".format(
                error_message)
            dlg = wx.MessageDialog(self,
                                   caption="Error",
                                   message=text,
                                   style=wx.OK)

        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()
예제 #3
0
 def on_upload_file(self, event):
     wait = wx.BusyInfo('Validating data, please wait...')
     wx.Yield()
     res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(dir_path=self.WD,
                                                                               vocab=self.contribution.vocab)
     self.failing_items = all_failing_items
     if has_problems:
         self.validation_mode = set(has_problems)
         # highlighting doesn't work with Windows
         if sys.platform in ['win32', 'win62']:
             self.message.SetLabel('The following grid(s) have incorrect or incomplete data:\n{}'.format(', '.join(self.validation_mode)))
         # highlighting does work with OSX
         else:
             for dtype in ["specimens", "samples", "sites", "locations", "ages"]:
                 wind = self.FindWindowByName(dtype + '_btn')
                 if dtype not in has_problems:
                     wind.Unbind(wx.EVT_PAINT, handler=self.highlight_button)
                 else:
                     wind.Bind(wx.EVT_PAINT, self.highlight_button)
             self.Refresh()
             self.message.SetLabel('Highlighted grids have incorrect or incomplete data')
         self.bSizer_msg.ShowItems(True)
         self.hbox.Fit(self)
     if not has_problems:
         self.validation_mode = set()
         self.message.SetLabel('')
         self.bSizer_msg.ShowItems(False)
         self.hbox.Fit(self)
     del wait
예제 #4
0
    def on_btn_upload(self, event):
        outstring = "upload_magic.py"
        print("-I- running python script:\n %s" % (outstring))
        wait = wx.BusyInfo("Please wait, working...")
        wx.Yield()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(
                dir_path=self.WD,
                vocab=self.contribution.vocab,
                contribution=self.contribution)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(
                dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload.\n Your file: {}  was generated in MagIC Project Directory.\nDrag and drop this file in the MagIC database.".format(
                os.path.split(res)[1])
            dlg = wx.MessageDialog(self,
                                   caption="Saved",
                                   message=text,
                                   style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/message window for details".format(
                error_message)
            dlg = wx.MessageDialog(self,
                                   caption="Error",
                                   message=text,
                                   style=wx.OK)

        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()

        if self.data_model_num == 3:
            from programs import magic_gui
            self.Disable()
            self.Hide()
            self.magic_gui_frame = magic_gui.MainFrame(
                self.WD,
                dmodel=self.data_model,
                title="Validations",
                contribution=self.contribution)

            self.magic_gui_frame.validation_mode = ['specimens']
            self.magic_gui_frame.failing_items = all_failing_items
            self.magic_gui_frame.change_dir_button.Disable()
            self.magic_gui_frame.Centre()
            self.magic_gui_frame.Show()
            self.magic_gui_frame.highlight_problems(has_problems)
            #
            # change name of upload button to 'exit validation mode'
            self.magic_gui_frame.bSizer2.GetStaticBox().SetLabel(
                'return to main GUI')
            self.magic_gui_frame.btn_upload.SetLabel("exit validation mode")
            # bind that button to quitting magic gui and re-enabling Pmag GUI
            self.magic_gui_frame.Bind(wx.EVT_BUTTON, self.on_end_validation,
                                      self.magic_gui_frame.btn_upload)
예제 #5
0
 def on_upload_file(self, event):
     wait = wx.BusyInfo('Validating data, please wait...')
     wx.Yield()
     res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(
         dir_path=self.WD, vocab=self.contribution.vocab)
     self.failing_items = all_failing_items
     if has_problems:
         self.highlight_problems(has_problems)
     if not has_problems:
         self.validation_mode = set()
         self.message.SetLabel('')
         self.bSizer_msg.ShowItems(False)
         self.hbox.Fit(self)
     del wait
예제 #6
0
 def test3_with_invalid_files(self):
     dir_path = os.path.join(WD, 'data_files', '3_0', 'Megiddo')
     outfile, error_message, errors, all_errors = ipmag.upload_magic3(dir_path=dir_path)
     msg = "file validation has failed.  You may run into problems if you try to upload this file."
     self.assertEqual(error_message, msg)
     # delete any upload file that was partially created
     import re
     pattern = re.compile('\w*[.]\w*[.]\w*[20]\d{2}\w*.txt$')
     possible_files = os.listdir(dir_path)
     files = []
     for f in possible_files:
         if pattern.match(f):
             files.append(f)
     pmag.remove_files(files, dir_path)
예제 #7
0
 def test3_with_invalid_files(self):
     dir_path = os.path.join(WD, 'data_files', '3_0', 'Megiddo')
     outfile, error_message, errors, all_errors = ipmag.upload_magic3(
         dir_path=dir_path)
     msg = "file validation has failed.  You may run into problems if you try to upload this file."
     self.assertEqual(error_message, msg)
     # delete any upload file that was partially created
     import re
     pattern = re.compile('\w*[.]\w*[.]\w*[20]\d{2}\w*.txt$')
     possible_files = os.listdir(dir_path)
     files = []
     for f in possible_files:
         if pattern.match(f):
             files.append(f)
     pmag.remove_files(files, dir_path)
예제 #8
0
def main():
    """
    NAME
        upload_magic.py

    DESCRIPTION
        This program will prepare your MagIC text files created by the programs nfo_magic.py,
        zeq_magic.py, thellier_magic.py, mag_magic, specimens_results_magic.py and so on.
        it will check for all the MagIC text files and skip the missing ones

    SYNTAX
        upload_magic.py

    INPUT
        MagIC txt files

    OPTIONS
        -h prints help message and quits
        -all include all the measurement data, default is only those used in interpretations
        -DM specify which MagIC data model number to use (2 or 3).  Default is 3.

    OUTPUT
        upload file:  file for uploading to MagIC database
    """
    if '-h' in sys.argv:
        print(main.__doc__)
        sys.exit()
    else:
        data_model_num = pmag.get_named_arg("-DM", 3)
        dataframe = extractor.command_line_dataframe([['cat', False, 0], ['F', False, ''], ['f', False, '']])
        checked_args = extractor.extract_and_check_args(sys.argv, dataframe)
        dir_path, concat = extractor.get_vars(['WD', 'cat'], checked_args)
        if data_model_num == 2:
            ipmag.upload_magic(concat, dir_path)
        else:
            ipmag.upload_magic3(concat, dir_path)
예제 #9
0
 def test3_with_contribution(self):
     dir_path = os.path.join(WD, 'data_files', '3_0', 'Megiddo')
     con = nb.Contribution(directory=dir_path)
     outfile, error_message, errors, all_errors = ipmag.upload_magic3(contribution=con)
     msg = "file validation has failed.  You may run into problems if you try to upload this file."
     self.assertEqual(error_message, msg)
     # delete any upload file that was partially created
     import re
     pattern = re.compile('\A[^.]*\.[a-zA-Z]*\.\d{4}\_?\d*\.txt')
     possible_files = os.listdir(dir_path)
     files = []
     for f in possible_files:
         if pattern.match(f):
             files.append(f)
     pmag.remove_files(files, dir_path)
예제 #10
0
def main():
    """
    NAME
        upload_magic.py

    DESCRIPTION
        This program will prepare your PMAG text files created by the programs nfo_magic.py,
        zeq_magic.py, thellier_magic.py, mag_magic, specimens_results_magic.py and so on.
        it will check for all the MagIC text files and skip the missing ones

    SYNTAX
        upload_magic.py

    INPUT
        MagIC txt files

    OPTIONS
        -h prints help message and quits
        -all include all the measurement data, default is only those used in interpretations
        -DM specify which MagIC data model number to use (2 or 3).  Default is 3.

    OUTPUT
        upload.txt:  file for uploading to MagIC database
    """
    if '-h' in sys.argv:
        print(main.__doc__)
        sys.exit()
    else:
        data_model_num = pmag.get_named_arg_from_sys("-DM", 3)
        dataframe = extractor.command_line_dataframe([['cat', False, 0], ['F', False, ''], ['f', False, '']])
        checked_args = extractor.extract_and_check_args(sys.argv, dataframe)
        dir_path, concat = extractor.get_vars(['WD', 'cat'], checked_args)
        if data_model_num == 2:
            ipmag.upload_magic(concat, dir_path)
        else:
            ipmag.upload_magic3(concat, dir_path)
예제 #11
0
 def test3_with_contribution(self):
     dir_path = os.path.join(WD, 'data_files', '3_0', 'Megiddo')
     con = cb.Contribution(directory=dir_path)
     outfile, error_message, errors, all_errors = ipmag.upload_magic3(
         contribution=con)
     msg = "file validation has failed.  You may run into problems if you try to upload this file."
     self.assertEqual(error_message, msg)
     # delete any upload file that was partially created
     import re
     pattern = re.compile('\A[^.]*\.[a-zA-Z]*\.\d{4}\_?\d*\.txt')
     possible_files = os.listdir(dir_path)
     files = []
     for f in possible_files:
         if pattern.match(f):
             files.append(f)
     pmag.remove_files(files, dir_path)
예제 #12
0
파일: pmag_gui.py 프로젝트: earthref/PmagPy
    def on_btn_upload(self, event):
        outstring="upload_magic.py"
        print("-I- running python script:\n %s"%(outstring))
        wait = wx.BusyInfo("Please wait, working...")
        wx.Yield()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(dir_path=self.WD,
                                                                                      vocab=self.contribution.vocab,
                                                                                      contribution=self.contribution)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload.\n Your file: {}  was generated in MagIC Project Directory.\nDrag and drop this file in the MagIC database.".format(os.path.split(res)[1])
            dlg = wx.MessageDialog(self, caption="Saved", message=text, style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/message window for details".format(error_message)
            dlg = wx.MessageDialog(self, caption="Error", message=text, style=wx.OK)

        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()

        if self.data_model_num == 3:
            from programs import magic_gui
            self.Disable()
            self.Hide()
            self.magic_gui_frame = magic_gui.MainFrame(self.WD,
                                                       dmodel=self.data_model,
                                                       title="Validations",
                                                       contribution=self.contribution)


            self.magic_gui_frame.validation_mode = ['specimens']
            self.magic_gui_frame.failing_items = all_failing_items
            self.magic_gui_frame.change_dir_button.Disable()
            self.magic_gui_frame.Centre()
            self.magic_gui_frame.Show()
            self.magic_gui_frame.highlight_problems(has_problems)
            #
            # change name of upload button to 'exit validation mode'
            self.magic_gui_frame.bSizer2.GetStaticBox().SetLabel('return to main GUI')
            self.magic_gui_frame.btn_upload.SetLabel("exit validation mode")
            # bind that button to quitting magic gui and re-enabling Pmag GUI
            self.magic_gui_frame.Bind(wx.EVT_BUTTON, self.on_end_validation, self.magic_gui_frame.btn_upload)
예제 #13
0
    def on_upload_file(self, event):
        wait = wx.BusyInfo('Validating data, please wait...')
        wx.Yield()
        res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(dir_path=self.WD,
                                                                                  vocab=self.contribution.vocab)
        self.failing_items = all_failing_items
        if has_problems:
            self.highlight_problems(has_problems)
        if not has_problems:
            self.validation_mode = set()
            self.message.SetLabel('Validated!')
            self.bSizer_msg.ShowItems(False)
            self.hbox.Fit(self)
            # do alert that your file passed
            dlg = wx.MessageDialog(self,caption="Message:", message="Your contribution has passed validations!\nGo to https://www.earthref.org/MagIC to upload:\n{}".format(res), style=wx.OK)
            dlg.ShowModal()

        del wait
예제 #14
0
 def test_depth_propagation(self):
     dir_path = os.path.join(WD, 'data_files', 'core_depthplot')
     #con = cb.Contribution(dir_path)
     #self.assertNotIn('core_depth', con.tables['sites'].df.index)
     #con.propagate_cols(['core_depth'], 'sites', 'samples', down=False)
     #self.assertIn('core_depth', con.tables['sites'].df.columns)
     #self.assertEqual(con.tables['sites'].df.loc['15-1-013', 'core_depth'], 55.23)
     #
     outfile, error_message, errors, all_errors = ipmag.upload_magic3(
         dir_path=dir_path)
     print('mv {} {}'.format(outfile, WD))
     os.system('mv {} {}'.format(outfile, WD))
     outfile = os.path.join(WD, os.path.split(outfile)[1])
     ipmag.download_magic(outfile)
     con = cb.Contribution(WD)
     self.assertIn('core_depth', con.tables['sites'].df.columns)
     self.assertEqual(con.tables['sites'].df.loc['15-1-013', 'core_depth'],
                      55.23)
예제 #15
0
    def on_btn_upload(self, event):
        outstring="upload_magic.py"
        print "-I- running python script:\n %s"%(outstring)
        wait = wx.BusyInfo("Please wait, working...")
        wx.Yield()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(dir_path=self.WD,
                                                                                      vocab=self.contribution.vocab)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload.\n Your file: {}  was generated in MagIC Project Directory.\nDrag and drop this file in the MagIC database.".format(os.path.split(res)[1])
            dlg = wx.MessageDialog(self, caption="Saved", message=text, style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/Command Prompt for details".format(error_message)
            dlg = wx.MessageDialog(self, caption="Error", message=text, style=wx.OK)

        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()
예제 #16
0
    def on_btn_upload(self, event):
        """
        Try to run upload_magic.
        Open validation mode if the upload file has problems.
        """
        if not self.check_for_uncombined_files():
            return
        outstring = "upload_magic.py"
        print("-I- running python script:\n %s" % (outstring))
        wait = wx.BusyInfo("Please wait, working...")
        wx.SafeYield()
        self.contribution.tables['measurements'].add_measurement_names()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(
                dir_path=self.WD,
                vocab=self.contribution.vocab,
                contribution=self.contribution)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(
                dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload!\n{} was generated in {}".format(
                os.path.split(res)[1],
                os.path.split(res)[0])
            dlg = pw.ChooseOne(self, "Go to MagIC for uploading",
                               "Not ready yet", text, "Saved")
            del wait
            #dlg = wx.MessageDialog(self, caption="Saved", message=text, style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/message window for details".format(
                error_message)
            dlg = wx.MessageDialog(self,
                                   caption="Error",
                                   message=text,
                                   style=wx.OK)

        dlg.Centre()
        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()
        if result == wx.ID_YES:
            pw.on_database_upload(None)

        if self.data_model_num == 3:
            if not res:
                from programs import magic_gui
                self.Disable()
                self.Hide()
                self.magic_gui_frame = magic_gui.MainFrame(
                    self.WD,
                    dmodel=self.data_model,
                    title="Validations",
                    contribution=self.contribution)

                self.magic_gui_frame.validation_mode = ['specimens']
                self.magic_gui_frame.failing_items = all_failing_items
                self.magic_gui_frame.change_dir_button.Disable()
                self.magic_gui_frame.Centre()
                self.magic_gui_frame.Show()
                self.magic_gui_frame.highlight_problems(has_problems)
                #
                # change name of upload button to 'exit validation mode'
                self.magic_gui_frame.bSizer2.GetStaticBox().SetLabel(
                    'return to main GUI')
                self.magic_gui_frame.btn_upload.SetLabel(
                    "exit validation mode")
                # bind that button to quitting magic gui and re-enabling Pmag GUI
                self.magic_gui_frame.Bind(wx.EVT_BUTTON,
                                          self.on_end_validation,
                                          self.magic_gui_frame.btn_upload)