<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_DIR(self, WD=None):
 """ open dialog box for choosing a working directory """


        if "-WD" in sys.argv and FIRST_RUN:
            ind = sys.argv.index('-WD')
            self.WD = sys.argv[ind + 1]
        elif not WD:  # if no arg was passed in for WD, make a dialog to choose one
            dialog = wx.DirDialog(None, "Choose a directory:", defaultPath=self.currentDirectory,
                                  style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON | wx.DD_CHANGE_DIR)
            ok = self.show_dlg(dialog)
            if ok == wx.ID_OK:
                self.WD = dialog.GetPath()
            else:
                self.WD = os.getcwd()
            dialog.Destroy()
        self.WD = os.path.realpath(self.WD)
        # name measurement file
        if self.data_model == 3:
            meas_file = 'measurements.txt'
        else:
            meas_file = 'magic_measurements.txt'
        self.magic_file = os.path.join(self.WD, meas_file)
        # intialize GUI_log
        self.GUI_log = open(os.path.join(self.WD, "thellier_GUI.log"), 'w+')
        self.GUI_log.write("starting...\n")
        self.GUI_log.close()
        self.GUI_log = open(os.path.join(self.WD, "thellier_GUI.log"), 'a')
        os.chdir(self.WD)
        self.WD = os.getcwd()