def make_grid_frame(self, event): """ Create a GridFrame for data type of the button that was clicked """ if self.grid_frame: print '-I- You already have a grid frame open' pw.simple_warning("You already have a grid open") return try: grid_type = event.GetButtonObj().Name[:-4] # remove '_btn' except AttributeError: grid_type = self.FindWindowById(event.Id).Name[:-4] # remove ('_btn') wait = wx.BusyInfo('Making {} grid, please wait...'.format(grid_type)) self.on_open_grid_frame() self.grid_frame = grid_frame.GridFrame(self.er_magic, self.WD, grid_type, grid_type, self.panel) if self.validation_mode: if grid_type in self.validation_mode: self.grid_frame.grid.paint_invalid_cells(self.warn_dict[grid_type]) #self.grid_frame.msg_boxsizer current_label = self.grid_frame.msg_text.GetLabel() add_text = """\n\nColumns and rows with problem data have been highlighted in blue. Cells with problem data are highlighted with different colors according to the type of problem. Red: missing required data Green: missing or invalid parent Blue: non-numeric data provided in a numeric field Gray: unrecognized column Purple: invalid result child """ self.grid_frame.msg_text.SetLabel(current_label + add_text) #self.on_finish_change_dir(self.change_dir_dialog) del wait
def onImport(self, event): openFileDialog = wx.FileDialog(self, "Open MagIC-format file", self.WD, "", "MagIC file|*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) result = openFileDialog.ShowModal() if result == wx.ID_OK: if self.grid_type == 'age': import_type = 'age' parent_type = None filename = openFileDialog.GetPath() file_type = self.er_magic.get_age_info(filename) import_type = file_type.split('_')[1][:-1] elif self.grid_type == 'result': import_type = 'result' parent_type = None try: filename = openFileDialog.GetPath() self.er_magic.get_results_info(filename) except Exception as ex: print '-W- ', ex print '-W- Could not read file:\n{}\nFile may be corrupted, or may not be a results format file.'.format(filename) pw.simple_warning('Could not read file:\n{}\nFile may be corrupted, or may not be a results format file.'.format(filename)) return else: parent_ind = self.er_magic.ancestry.index(self.grid_type) parent_type = self.er_magic.ancestry[parent_ind+1] # get filename and file data filename = openFileDialog.GetPath() import_type = self.er_magic.get_magic_info(self.grid_type, parent_type, filename=filename, sort_by_file_type=True) # add any additional headers to the grid, while preserving all old headers current_headers = self.grid_headers[self.grid_type]['er'][0] self.er_magic.init_actual_headers() er_headers = list(set(self.er_magic.headers[self.grid_type]['er'][0]).union(current_headers)) self.er_magic.headers[self.grid_type]['er'][0] = er_headers #include_pmag = self.pmag_checkbox.cb.IsChecked() include_pmag = True if include_pmag: pmag_headers = self.er_magic.headers[self.grid_type]['pmag'][0] headers = set(er_headers).union(pmag_headers) else: headers = er_headers for head in sorted(list(headers)): if head not in self.grid.col_labels: self.grid.add_col(head) # add age data if import_type == 'age' and self.grid_type == 'age': self.grid_builder.add_age_data_to_grid() self.grid.size_grid() self.main_sizer.Fit(self) elif import_type == self.grid_type: self.grid_builder.add_data_to_grid(self.grid, import_type) self.grid.size_grid() self.main_sizer.Fit(self) # if imported data will not show up in current grid, # warn user else: pw.simple_warning('You have imported a {} type file.\nYou\'ll need to open up your {} grid to see this data'.format(import_type, import_type))
def onDeleteRow(self, event, data_type): """ On button click, remove relevant object from both the data model and the grid. """ ancestry = self.er_magic_data.ancestry child_type = ancestry[ancestry.index(data_type) - 1] names = [self.grid.GetCellValue(row, 0) for row in self.selected_rows] if data_type == 'site': how_to_fix = 'Make sure to select a new site for each orphaned sample in the next step' else: how_to_fix = 'Go back a step and select a new {} for each orphaned {}'.format(data_type, child_type) orphans = [] for name in names: row = self.grid.row_labels.index(name) orphan = self.er_magic_data.delete_methods[data_type](name) if orphan: orphans.extend(orphan) self.grid.remove_row(row) if orphans: orphan_names = self.er_magic_data.make_name_list(orphans) pw.simple_warning('You have deleted:\n\n {}\n\nthe parent(s) of {}(s):\n\n {}\n\n{}'.format(', '.join(names), child_type, ', '.join(orphan_names), how_to_fix)) self.selected_rows = set() # update grid and data model self.update_grid(self.grid)#, grids[grid_name]) self.grid.Refresh()
def on_er_data(self, event): if not os.path.isfile(os.path.join(self.WD, 'magic_measurements.txt')): import pmag_widgets as pw pw.simple_warning("Your working directory must have a magic_measurements.txt file to run this step. Make sure you have fully completed step 1 (import magnetometer file), by combining all imported magnetometer files into one magic_measurements file.") return False #self.ErMagic_frame = ErMagicBuilder.MagIC_model_builder(self.WD, self, self.ErMagic_data)#,self.Data,self.Data_hierarchy) self.ErMagic_frame = ErMagicBuilder.MagIC_model_builder(self.WD, self, self.er_magic)#,self.Data,self.Data_hierarchy) self.ErMagic_frame.Show() self.ErMagic_frame.Center() size = wx.DisplaySize() size = (size[0] - 0.3 * size[0], size[1] - 0.3 * size[1]) # gets total available screen space - 10% self.ErMagic_frame.Raise()
def on_add_cols(self, event): """ Show simple dialog that allows user to add a new column name """ col_labels = self.grid.col_labels dia = pw.ChooseOne(self, yes="Add single columns", no="Add groups") result1 = dia.ShowModal() if result1 == wx.ID_YES: items = [ col_name for col_name in self.dm.index if col_name not in col_labels ] dia = pw.HeaderDialog(self, 'columns to add', list(items), []) dia.Centre() result2 = dia.ShowModal() else: groups = self.dm['group'].unique() dia = pw.HeaderDialog(self, 'groups to add', list(groups), True) dia.Centre() result2 = dia.ShowModal() new_headers = [] if result2 == 5100: new_headers = dia.text_list # if there is nothing to add, quit if not new_headers: return if result1 == wx.ID_YES: # add individual headers errors = self.add_new_grid_headers(new_headers) else: # add header groups errors = self.add_new_header_groups(new_headers) if errors: errors_str = ', '.join(errors) pw.simple_warning( 'You are already using the following headers: {}\nSo they will not be added' .format(errors_str)) # problem: if widgets above the grid are too wide, # the grid does not re-size when adding columns # awkward solution (causes flashing): if self.grid.GetWindowStyle() != wx.DOUBLE_BORDER: self.grid.SetWindowStyle(wx.DOUBLE_BORDER) self.main_sizer.Fit(self) self.grid.SetWindowStyle(wx.NO_BORDER) self.Centre() self.main_sizer.Fit(self) # self.grid.changes = set(range(self.grid.GetNumberRows())) dia.Destroy()
def on_add_cols(self, event): """ Show simple dialog that allows user to add a new column name """ col_labels = self.grid.col_labels er_items = [head for head in self.grid_headers[self.grid_type]['er'][2] if head not in col_labels] er_items = builder.remove_list_headers(er_items) #include_pmag = self.pmag_checkbox.cb.IsChecked() include_pmag = True if include_pmag or self.grid_type == 'result': pmag_headers = sorted(list(set(self.grid_headers[self.grid_type]['pmag'][2]).union(self.grid_headers[self.grid_type]['pmag'][1]))) pmag_items = [head for head in pmag_headers if head not in er_items and head not in col_labels] #pmag_items = [head for head in self.grid_headers[self.grid_type]['pmag'][2] if head not in er_items and head not in col_labels] pmag_items = builder.remove_list_headers(pmag_items) else: pmag_items = [] dia = pw.HeaderDialog(self, 'columns to add', er_items, pmag_items) result = dia.ShowModal() new_headers = [] if result == 5100: new_headers = dia.text_list if not new_headers: return for name in new_headers: if name: if name not in self.grid.col_labels: col_number = self.grid.add_col(name) # add to appropriate headers list if name in er_items: self.grid_headers[self.grid_type]['er'][0].append(str(name)) if name in pmag_items: self.grid_headers[self.grid_type]['pmag'][0].append(str(name)) import controlled_vocabularies as vocabulary from controlled_vocabularies import vocabularies as vocab if name in vocabulary.possible_vocabularies: self.drop_down_menu.add_drop_down(col_number, name) else: pw.simple_warning('You are already using column header: {}'.format(name)) # problem: if widgets above the grid are too wide, # the grid does not re-size when adding columns # awkward solution (causes flashing): if self.grid.GetWindowStyle() != wx.DOUBLE_BORDER: self.grid.SetWindowStyle(wx.DOUBLE_BORDER) self.main_sizer.Fit(self) self.grid.SetWindowStyle(wx.NO_BORDER) self.main_sizer.Fit(self) # self.grid.changes = set(range(self.grid.GetNumberRows()))
def on_add_cols(self, event): """ Show simple dialog that allows user to add a new column name """ col_labels = self.grid.col_labels dia = pw.ChooseOne(self, yes="Add single columns", no="Add groups") result1 = dia.ShowModal() if result1 == wx.ID_YES: items = [col_name for col_name in self.dm.index if col_name not in col_labels] dia = pw.HeaderDialog(self, 'columns to add', list(items), []) dia.Centre() result2 = dia.ShowModal() else: groups = self.dm['group'].unique() dia = pw.HeaderDialog(self, 'groups to add', list(groups), True) dia.Centre() result2 = dia.ShowModal() new_headers = [] if result2 == 5100: new_headers = dia.text_list # if there is nothing to add, quit if not new_headers: return if result1 == wx.ID_YES: # add individual headers errors = self.add_new_grid_headers(new_headers) else: # add header groups errors = self.add_new_header_groups(new_headers) if errors: errors_str = ', '.join(errors) pw.simple_warning('You are already using the following headers: {}\nSo they will not be added'.format(errors_str)) # problem: if widgets above the grid are too wide, # the grid does not re-size when adding columns # awkward solution (causes flashing): if self.grid.GetWindowStyle() != wx.DOUBLE_BORDER: self.grid.SetWindowStyle(wx.DOUBLE_BORDER) self.main_sizer.Fit(self) self.grid.SetWindowStyle(wx.NO_BORDER) self.Centre() self.main_sizer.Fit(self) # self.grid.changes = set(range(self.grid.GetNumberRows())) dia.Destroy()
def remove_col_label(self, event): """ check to see if column is required if it is not, delete it from grid """ col = event.GetCol() label = self.grid.GetColLabelValue(col) if '**' in label: label = label.strip('**') if label in self.reqd_headers: pw.simple_warning("That header is required, and cannot be removed") return False else: print 'That header is not required:', label self.grid.remove_col(col) del self.contribution.tables[self.grid_type].df[label] # causes resize on each column header delete # can leave this out if we want..... self.main_sizer.Fit(self)
def on_add_cols(self, event): """ Show simple dialog that allows user to add a new column name """ col_labels = self.grid.col_labels # do not list headers that are already column labels in the grid er_items = [head for head in self.grid_headers[self.grid_type]['er'][2] if head not in col_labels] # remove unneeded headers er_items = builder.remove_list_headers(er_items) pmag_headers = sorted(list(set(self.grid_headers[self.grid_type]['pmag'][2]).union(self.grid_headers[self.grid_type]['pmag'][1]))) # do not list headers that are already column labels in the grid # make sure that pmag_specific columns are marked with '++' to_add = [i + '++' for i in self.er_magic.double if i in pmag_headers and i + '++' not in col_labels] pmag_headers.extend(to_add) pmag_items = [head for head in pmag_headers if head not in er_items and head not in col_labels] # remove unneeded headers pmag_items = sorted(builder.remove_list_headers(pmag_items)) dia = pw.HeaderDialog(self, 'columns to add', er_items, pmag_items) dia.Centre() result = dia.ShowModal() new_headers = [] if result == 5100: new_headers = dia.text_list if not new_headers: return errors = self.add_new_grid_headers(new_headers, er_items, pmag_items) if errors: errors_str = ', '.join(errors) pw.simple_warning('You are already using the following headers: {}\nSo they will not be added'.format(errors_str)) # problem: if widgets above the grid are too wide, # the grid does not re-size when adding columns # awkward solution (causes flashing): if self.grid.GetWindowStyle() != wx.DOUBLE_BORDER: self.grid.SetWindowStyle(wx.DOUBLE_BORDER) self.main_sizer.Fit(self) self.grid.SetWindowStyle(wx.NO_BORDER) self.Centre() self.main_sizer.Fit(self) # self.grid.changes = set(range(self.grid.GetNumberRows())) dia.Destroy()
def remove_col_label(self, event): """ check to see if column is required if it is not, delete it from grid """ col = event.GetCol() label = self.grid.GetColLabelValue(col) if '**' in label: label = label.strip('**') elif '^^' in label: label = label.strip('^^') if label in self.reqd_headers: pw.simple_warning("That header is required, and cannot be removed") return False else: print 'That header is not required:', label self.grid.remove_col(col) del self.contribution.tables[self.grid_type].df[label] # causes resize on each column header delete # can leave this out if we want..... self.main_sizer.Fit(self)
def remove_col_label(self, event):#, include_pmag=True): """ check to see if column is required if it is not, delete it from grid """ er_possible_headers = self.grid_headers[self.grid_type]['er'][2] pmag_possible_headers = self.grid_headers[self.grid_type]['pmag'][2] er_actual_headers = self.grid_headers[self.grid_type]['er'][0] pmag_actual_headers = self.grid_headers[self.grid_type]['pmag'][0] col = event.GetCol() label = self.grid.GetColLabelValue(col) if '**' in label: label = label.strip('**') if label in self.grid_headers[self.grid_type]['er'][1]: pw.simple_warning("That header is required, and cannot be removed") return False #elif include_pmag and label in self.grid_headers[self.grid_type]['pmag'][1]: # pw.simple_warning("That header is required, and cannot be removed") # return False else: print 'That header is not required:', label self.grid.remove_col(col) #if label in er_possible_headers: try: print 'removing {} from er_actual_headers'.format(label) er_actual_headers.remove(label) except ValueError: pass #if label in pmag_possible_headers: try: pmag_actual_headers.remove(label) except ValueError: pass # causes resize on each column header delete # can leave this out if we want..... self.main_sizer.Fit(self)
def main(): """ NAME ani_depthplot.py DESCRIPTION plots tau, V3_inc, V1_dec, P and chi versus core_depth SYNTAX ani_depthplot.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input rmag_anisotropy format file from magic -fb FILE: specify input magic_measurements format file from magic -fsa FILE: specify input er_samples format file from magic -fsum FILE : specify input LIMS database (IODP) core summary csv file to print the core names, set lab to 1 -fa FILE: specify input er_ages format file from magic -d min max [in m] depth range to plot -ds [mcd,mbsf], specify depth scale, default is mbsf -sav save plot without review -fmt specfiy format for figures - default is svg DEFAULTS: Anisotropy file: rmag_anisotropy.txt Bulk susceptibility file: magic_measurements.txt Samples file: er_samples.txt """ args = sys.argv if '-h' in args: print main.__doc__ sys.exit() dataframe = extractor.command_line_dataframe([['f', False, 'rmag_anisotropy.txt'], ['fb', False, 'magic_measurements.txt'], ['fsa', False, 'er_samples.txt'], ['fa', False, None], ['fsum', False, None], ['fmt', False, 'svg'], ['ds', False, 'mbsf'], ['d', False, '-1 -1'], ['sav', False, False], ['WD', False, '.' ]]) #args = sys.argv checked_args = extractor.extract_and_check_args(args, dataframe) ani_file, meas_file, samp_file, age_file, sum_file, fmt, depth_scale, depth, save_quietly, dir_path = extractor.get_vars(['f', 'fb', 'fsa', 'fa', 'fsum', 'fmt', 'ds', 'd', 'sav', 'WD'], checked_args) # format min/max depth try: dmin, dmax = depth.split() dmin, dmax = float(dmin), float(dmax) except: print 'you must provide depth in this format: -d dmin dmax' print 'could not parse "{}", defaulting to plotting all depths'.format('-d ' + str(depth)) dmin, dmax = -1, -1 if depth_scale: if age_file: depth_scale = 'age' elif 'mbsf' in depth_scale: depth_scale = 'sample_core_depth' elif 'mcd' in depth_scale: depth_scale = 'sample_composite_depth' else: print 'Warning: Unrecognized option "{}" provided for depth scale.\nOptions for depth scale are mbsf -- meters below sea floor -- or mcd -- meters composite depth.\nAlternatively, if you provide an age file the depth scale will be automatically set to plot by age instead.\nUsing default "mbsf"'.format(depth_scale) depth_scale = 'sample_composite_depth' fig, figname = ipmag.aniso_depthplot(ani_file, meas_file, samp_file, age_file, sum_file, fmt, dmin, dmax, depth_scale, dir_path) if save_quietly: if dir_path == '.': dir_path = os.getcwd() print 'Saved file: {} in folder: {}'.format(figname, dir_path) return False app = wx.App(redirect=False) if not fig: pw.simple_warning('No plot was able to be created with the data you provided.\nMake sure you have given all the required information and try again') return False dpi = fig.get_dpi() pixel_width = dpi * fig.get_figwidth() pixel_height = dpi * fig.get_figheight() figname = os.path.join(dir_path, figname) plot_frame = pmag_menu_dialogs.PlotFrame((int(pixel_width), int(pixel_height + 50)), fig, figname) app.MainLoop()
def onImport(self, event): """ Import a MagIC-format file """ if self.grid.changes: print "-W- Your changes will be overwritten..." wind = pw.ChooseOne(self, "Import file anyway", "Save grid first", "-W- Your grid has unsaved changes which will be overwritten if you import a file now...") wind.Centre() res = wind.ShowModal() # save grid first: if res == wx.ID_NO: self.onSave(None, alert=True, destroy=False) # reset self.changes self.grid.changes = set() openFileDialog = wx.FileDialog(self, "Open MagIC-format file", self.WD, "", "MagIC file|*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) result = openFileDialog.ShowModal() if result == wx.ID_OK: # get filename filename = openFileDialog.GetPath() # make sure the dtype is correct f = open(filename) line = f.readline() if line.startswith("tab"): delim, dtype = line.split("\t") else: delim, dtype = line.split("") f.close() dtype = dtype.strip() if (dtype != self.grid_type) and (dtype + "s" != self.grid_type): text = "You are currently editing the {} grid, but you are trying to import a {} file.\nPlease open the {} grid and then re-try this import.".format(self.grid_type, dtype, dtype) pw.simple_warning(text) return # grab old data for concatenation if self.grid_type in self.contribution.tables: old_df_container = self.contribution.tables[self.grid_type] else: old_df_container = None old_col_names = self.grid.col_labels # read in new file and update contribution df_container = nb.MagicDataFrame(filename, dmodel=self.dm, columns=old_col_names) # concatenate if possible if not isinstance(old_df_container, type(None)): df_container.df = pd.concat([old_df_container.df, df_container.df], axis=0) self.contribution.tables[df_container.dtype] = df_container self.grid_builder = GridBuilder(self.contribution, self.grid_type, self.panel, parent_type=self.parent_type, reqd_headers=self.reqd_headers) # delete old grid self.grid_box.Hide(0) self.grid_box.Remove(0) # create new, updated grid self.grid = self.grid_builder.make_grid() self.grid.InitUI() # add data to new grid self.grid_builder.add_data_to_grid(self.grid, self.grid_type) # add new grid to sizer and fit everything self.grid_box.Add(self.grid, flag=wx.ALL, border=5) self.main_sizer.Fit(self) self.Centre() # add any needed drop-down-menus self.drop_down_menu = drop_down_menus.Menus(self.grid_type, self.contribution, self.grid) # done! return
def main(): """ NAME core_depthplot.py DESCRIPTION plots various measurements versus core_depth or age. plots data flagged as 'FS-SS-C' as discrete samples. SYNTAX core_depthplot.py [command line optins] OPTIONS -h prints help message and quits -f FILE: specify input magic_measurments format file from magi -fsum FILE: specify input LIMS database (IODP) core summary csv file -fwig FILE: specify input depth,wiggle to plot, in magic format with sample_core_depth key for depth -fsa FILE: specify input er_samples format file from magic for depth -fa FILE: specify input er_ages format file from magic for age NB: must have either -fsa OR -fa (not both) -fsp FILE sym size: specify input zeq_specimen format file from magic, sym and size NB: PCAs will have specified color, while fisher means will be white with specified color as the edgecolor -fres FILE specify input pmag_results file from magic, sym and size -LP [AF,T,ARM,IRM, X] step [in mT,C,mT,mT, mass/vol] to plot -S do not plot blanket treatment data (if this is set, you don't need the -LP) -sym SYM SIZE, symbol, size for continuous points (e.g., ro 5, bs 10, g^ 10 for red dot, blue square, green triangle), default is blue dot at 5 pt -D do not plot declination -M do not plot magnetization -log plot magnetization on a log scale -L do not connect dots with a line -I do not plot inclination -d min max [in m] depth range to plot -n normalize by weight in er_specimen table -Iex: plot the expected inc at lat - only available for results with lat info in file -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma) TS: [ck95, gts04, gts12] -ds [mbsf,mcd] specify depth scale, mbsf default -fmt [svg, eps, pdf, png] specify output format for plot (default: svg) -sav save plot silently DEFAULTS: Measurements file: magic_measurements.txt Samples file: er_samples.txt NRM step Summary file: none """ args = sys.argv if '-h' in args: print main.__doc__ sys.exit() dataframe = extractor.command_line_dataframe([ ['f', False, ''], ['fsum', False, ''], ['fwig', False, ''], ['fsa', False, ''], ['fa', False, ''], ['fsp', False, ''], ['fres', False, '' ], ['fmt', False, 'svg'], ['LP', False, ''], ['n', False, False], ['d', False, '-1 -1'], ['ts', False, ''], ['WD', False, '.'], ['L', False, True], ['S', False, True], ['D', False, True], ['I', False, True], ['M', False, True], ['log', False, 0], ['ds', False, 'sample_core_depth'], ['sym', False, 'bo 5'], ['ID', False, '.']]) checked_args = extractor.extract_and_check_args(args, dataframe) meas_file, sum_file, wig_file, samp_file, age_file, spc_file, res_file, fmt, meth, norm, depth, timescale, dir_path, pltLine, pltSus, pltDec, pltInc, pltMag, logit, depth_scale, symbol, input_dir = extractor.get_vars(['f', 'fsum', 'fwig', 'fsa', 'fa', 'fsp', 'fres', 'fmt', 'LP', 'n', 'd', 'ts', 'WD', 'L', 'S', 'D', 'I', 'M', 'log', 'ds', 'sym', 'ID'], checked_args) # format some variables # format symbol/size try: sym, size = symbol.split() size = int(size) except: print 'you should provide -sym in this format: ro 5' print 'using defaults instead' sym, size = 'ro', 5 # format result file, symbol, size if res_file: try: res_file, res_sym, res_size = res_file.split() except: print 'you must provide -fres in this format: -fres filename symbol size' print 'could not parse {}, defaulting to using no result file'.format(res_file) res_file, res_sym, res_size = '', '', 0 else: res_file, res_sym, res_size = '', '', 0 # format specimen file, symbol, size if spc_file: try: spc_file, spc_sym, spc_size = spc_file.split() except: print 'you must provide -fsp in this format: -fsp filename symbol size' print 'could not parse {}, defaulting to using no specimen file'.format(spc_file) spc_file, spc_sym, spc_size = '', '', 0 else: spc_file, spc_sym, spc_size = '', '', 0 # format min/max depth try: dmin, dmax = depth.split() except: print 'you must provide -d in this format: -d dmin dmax' print 'could not parse {}, defaulting to plotting all depths'.format(depth) dmin, dmax = -1, -1 # format timescale, min/max time if timescale: try: timescale, amin, amax = timescale.split() pltTime = True except: print 'you must provide -ts in this format: -ts timescale minimum_age maximum_age' print 'could not parse {}, defaulting to using no timescale'.format(timescale) timescale, amin, amax = None, -1, -1 pltTime = False else: timescale, amin, amax = None, -1, -1 pltTime = False # format norm and wt_file if norm and not isinstance(norm, bool): wt_file = norm norm = True else: norm = False wt_file = '' # format list of protcols and step try: method, step = meth.split() except: print 'To use the -LP flag you must provide both the protocol and the step in this format:\n-LP [AF,T,ARM,IRM, X] step [in mT,C,mT,mT, mass/vol] to plot' print 'Defaulting to using no protocol' method, step = 'LT-NO', 0 # list of varnames #['f', 'fsum', 'fwig', 'fsa', 'fa', 'fsp', 'fres', 'fmt', 'LP', 'n', 'd', 'ts', 'WD', 'L', 'S', 'D', 'I', 'M', 'log', 'ds', 'sym' ] #meas_file, sum_file, wig_file, samp_file, age_file, spc_file, res_file, fmt, meth, norm, depth, timescale, dir_path, pltLine, pltSus, pltDec, pltInc, pltMag, logit, depth_scale, symbol fig, figname = ipmag.core_depthplot(input_dir, meas_file, spc_file, samp_file, age_file, sum_file, wt_file, depth_scale, dmin, dmax, sym, size, spc_sym, spc_size, method, step, fmt, pltDec, pltInc, pltMag, pltLine, pltSus, logit, pltTime, timescale, amin, amax, norm) app = wx.App(redirect=False) if not fig: pw.simple_warning('No plot was able to be created with the data you provided.\nMake sure you have given all the required information and try again') return False dpi = fig.get_dpi() pixel_width = dpi * fig.get_figwidth() pixel_height = dpi * fig.get_figheight() figname = os.path.join(dir_path, figname) plot_frame = pmag_menu_dialogs.PlotFrame((int(pixel_width), int(pixel_height + 50)), fig, figname) app.MainLoop()
def onImport(self, event): """ Import a MagIC-format file """ if self.grid.changes: print "-W- Your changes will be overwritten..." wind = pw.ChooseOne( self, "Import file anyway", "Save grid first", "-W- Your grid has unsaved changes which will be overwritten if you import a file now..." ) wind.Centre() res = wind.ShowModal() # save grid first: if res == wx.ID_NO: self.onSave(None, alert=True, destroy=False) # reset self.changes self.grid.changes = set() openFileDialog = wx.FileDialog(self, "Open MagIC-format file", self.WD, "", "MagIC file|*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) result = openFileDialog.ShowModal() if result == wx.ID_OK: # get filename filename = openFileDialog.GetPath() # make sure the dtype is correct f = open(filename) line = f.readline() if line.startswith("tab"): delim, dtype = line.split("\t") else: delim, dtype = line.split("") f.close() dtype = dtype.strip() if (dtype != self.grid_type) and (dtype + "s" != self.grid_type): text = "You are currently editing the {} grid, but you are trying to import a {} file.\nPlease open the {} grid and then re-try this import.".format( self.grid_type, dtype, dtype) pw.simple_warning(text) return # grab old data for concatenation if self.grid_type in self.contribution.tables: old_df_container = self.contribution.tables[self.grid_type] else: old_df_container = None old_col_names = self.grid.col_labels # read in new file and update contribution df_container = nb.MagicDataFrame(filename, dmodel=self.dm, columns=old_col_names) # concatenate if possible if not isinstance(old_df_container, type(None)): df_container.df = pd.concat( [old_df_container.df, df_container.df], axis=0) self.contribution.tables[df_container.dtype] = df_container self.grid_builder = GridBuilder(self.contribution, self.grid_type, self.panel, parent_type=self.parent_type, reqd_headers=self.reqd_headers) # delete old grid self.grid_box.Hide(0) self.grid_box.Remove(0) # create new, updated grid self.grid = self.grid_builder.make_grid() self.grid.InitUI() # add data to new grid self.grid_builder.add_data_to_grid(self.grid, self.grid_type) # add new grid to sizer and fit everything self.grid_box.Add(self.grid, flag=wx.ALL, border=5) self.main_sizer.Fit(self) self.Centre() # add any needed drop-down-menus self.drop_down_menu = drop_down_menus.Menus( self.grid_type, self.contribution, self.grid) # done! return