def test_local(self): dir1 = find_pmag_dir.get_pmag_dir() os.chdir('..') os.chdir('..') dir2 = find_pmag_dir.get_pmag_dir() os.chdir(dir2) dir3 = find_pmag_dir.get_pmag_dir() self.assertEqual(dir1, dir2) self.assertEqual(dir2, dir3) if WD != sys.prefix: self.assertIn('PmagPy', dir1)
def test_local(self): dir1 = find_pmag_dir.get_pmag_dir() os.chdir('..') os.chdir('..') dir2 = find_pmag_dir.get_pmag_dir() os.chdir(dir2) dir3 = find_pmag_dir.get_pmag_dir() self.assertEqual(dir1, dir2) self.assertEqual(dir2, dir3) if "-pip" not in sys.argv: self.assertIn('PmagPy', dir1)
def main(): try: from mpl_toolkits.basemap import basemap_datadir except: print "-E- Could not import the basemap module..." else: # allow user to specify what directory to find the data_files in custom_dir = pmag.get_named_arg_from_sys('-source-dir', default_val="") if os.path.isdir(custom_dir): data_dir = custom_dir # if user didn't specify a directory, find the etopo20 directory else: # if installed by pip, etopo20 is in sys.prefix pip_data_dir = os.path.join(sys.prefix, 'data_files', 'etopo20') if os.path.isdir(pip_data_dir): data_dir = pip_data_dir else: # if not installed by pip, etopo20 is in the local PmagPy directory from pmagpy import find_pmag_dir pmag_dir = find_pmag_dir.get_pmag_dir() data_dir = os.path.join(pmag_dir, 'data_files', 'etopo20') # if none of those options worked, warn the user: if not os.path.isdir(data_dir): print "-W- Could not find data_files to copy in {}".format( data_dir) print "-I- You can run this program with the command line flag -source-dir to specify the location of the etopo20 directory." print "-I- For example: 'install_etopo.py -source-dir ~/Python/PmagPy/data_files/etopo20'" return print "installing etopo20 files from ", path.join(data_dir, 'etopo20*') print "to the basemap data directory: ", basemap_datadir command = 'cp ' + path.join(data_dir, 'etopo20*') + " " + basemap_datadir os.system(command)
def get_dm_offline(self): """ Grab the 3.0 data model from the PmagPy/pmagpy directory """ print("-I- Using cached 3.0 data model") pmag_dir = find_pmag_dir.get_pmag_dir() if pmag_dir is None: pmag_dir = '.' model_file = os.path.join(pmag_dir, 'pmagpy', 'data_model', 'data_model.json') # for py2app: if not os.path.isfile(model_file): model_file = os.path.join(pmag_dir, 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join(os.path.split(os.path.dirname(__file__))[0],'pmagpy', 'data_model','data_model.json') if not os.path.isfile(model_file): model_file = os.path.join(os.path.split(os.path.dirname(__file__))[0], 'data_model','data_model.json') try: f = open(model_file, 'r', encoding='utf-8-sig') except TypeError: f = open(model_file, 'r') string = '\n'.join(f.readlines()) f.close() raw = json.loads(string) full = DataFrame(raw) return full
def get_dm_offline(self): """ Grab the 3.0 data model from the PmagPy/pmagpy directory """ print("-I- Using cached 3.0 data model") pmag_dir = find_pmag_dir.get_pmag_dir() if pmag_dir is None: pmag_dir = '.' model_file = os.path.join(pmag_dir, 'pmagpy', 'data_model', 'data_model.json') # for py2app: if not os.path.isfile(model_file): model_file = os.path.join(pmag_dir, 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join( os.path.split(os.path.dirname(__file__))[0], 'pmagpy', 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join( os.path.split(os.path.dirname(__file__))[0], 'data_model', 'data_model.json') try: f = open(model_file, 'r', encoding='utf-8-sig') except TypeError: f = open(model_file, 'r') string = '\n'.join(f.readlines()) f.close() raw = json.loads(string) full = DataFrame(raw) return full
def main(): try: from mpl_toolkits.basemap import basemap_datadir except: print("-E- Could not import the basemap module...") else: # allow user to specify what directory to find the data_files in custom_dir = pmag.get_named_arg_from_sys('-source-dir', default_val="") if os.path.isdir(custom_dir): data_dir = custom_dir # if user didn't specify a directory, find the etopo20 directory else: # if installed by pip, etopo20 is in sys.prefix pip_data_dir = os.path.join(sys.prefix, 'data_files', 'etopo20') if os.path.isdir(pip_data_dir): data_dir = pip_data_dir else: # if not installed by pip, etopo20 is in the local PmagPy directory from pmagpy import find_pmag_dir pmag_dir = find_pmag_dir.get_pmag_dir() data_dir = os.path.join(pmag_dir, 'data_files', 'etopo20') # if none of those options worked, warn the user: if not os.path.isdir(data_dir): print("-W- Could not find data_files to copy in {}".format(data_dir)) print("-I- You can run this program with the command line flag -source-dir to specify the location of the etopo20 directory.") print("-I- For example: 'install_etopo.py -source-dir ~/Python/PmagPy/data_files/etopo20'") return print("installing etopo20 files from ", path.join(data_dir, 'etopo20*')) print("to the basemap data directory: ",basemap_datadir) command = 'cp ' + path.join(data_dir, 'etopo20*') + " "+ basemap_datadir os.system(command)
def find_cached_dm(self): """ Find filename where cached data model json is stored. Returns --------- model_file : str data model json file location """ pmag_dir = find_pmag_dir.get_pmag_dir() if pmag_dir is None: pmag_dir = '.' model_file = os.path.join(pmag_dir, 'pmagpy', 'data_model', 'data_model.json') # for py2app: if not os.path.isfile(model_file): model_file = os.path.join(pmag_dir, 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join( os.path.split(os.path.dirname(__file__))[0], 'pmagpy', 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join( os.path.split(os.path.dirname(__file__))[0], 'data_model', 'data_model.json') return model_file
def main(): if '-h' in sys.argv: print( "Some mapping utilities use the Etopo package for topography and these data sets do not come standard with the Python installation of Basemap. To install these additional files, use: 'install_etopo.py'." ) print( "However, if you are using cartopy for plotting (recommended), you do not need to run install_etopo.py." ) return try: from mpl_toolkits.basemap import basemap_datadir except: print( "-I- Some mapping utilities use the Etopo package for topography and these data sets do not come standard with the Python installation of Basemap. However, if you are using cartopy for plotting (recommended), you do not need to run install_etopo.py." ) print( "-E- Basemap does not appear to be installed, aborting program...") else: # allow user to specify what directory to find the data_files in custom_dir = pmag.get_named_arg('-source-dir', default_val="") if os.path.isdir(custom_dir): data_dir = custom_dir # if user didn't specify a directory, find the etopo20 directory else: # if installed by pip, etopo20 is in sys.prefix pip_data_dir = os.path.join(sys.prefix, 'data_files', 'etopo20') if os.path.isdir(pip_data_dir): data_dir = pip_data_dir else: # if not installed by pip, etopo20 is in the local PmagPy directory from pmagpy import find_pmag_dir pmag_dir = find_pmag_dir.get_pmag_dir() data_dir = os.path.join(pmag_dir, 'data_files', 'etopo20') # if none of those options worked, warn the user: if not os.path.isdir(data_dir): print( "-W- Could not find data_files to copy in {}".format(data_dir)) print( "-I- You can run this program with the command line flag -source-dir to specify the location of the etopo20 directory." ) print( "-I- For example: 'install_etopo.py -source-dir ~/Python/PmagPy/data_files/etopo20'" ) return print("installing etopo20 files from ", path.join(data_dir, 'etopo20*')) print("to the basemap data directory: ", basemap_datadir) if sys.platform in ['win32', 'win64']: command = 'copy ' + path.join(data_dir, 'etopo20*') + " " + basemap_datadir else: command = 'cp ' + path.join(data_dir, 'etopo20*') + " " + basemap_datadir os.system(command)
def on_helpButton(self, event): #for use on the command line path = find_pmag_dir.get_pmag_dir() # for use with pyinstaller: #path = self.Parent.resource_dir help_page = os.path.join(path, 'dialogs', 'help_files', 'ErMagicBuilderHelp3.html') # if using with py2app, the directory structure is flat, # so check to see where the resource actually is if not os.path.exists(help_page): help_page = os.path.join(path, 'help_files', 'ErMagicBuilderHelp3.html') html_frame = pw.HtmlFrame(self, page=help_page) html_frame.Center() html_frame.Show()
def main(): if '-h' in sys.argv: print("Choose the folder where you want the PmagPy data files to be.") print( "Navigate to that folder, and use the command: 'move_data_files.py'" ) print( "Alternatively, you may use the full path to the directory of your choice from anywhere in the file system, using the '-d' flag: 'move_data_files.py -d /Users/***/Desktop' where *** is your username" ) sys.exit() # create PmagPy-data directory dest = pmag.get_named_arg('-d', '.', False) dest = path.realpath(dest) dest = path.join(dest, 'PmagPy-data') if not path.exists(dest): try: os.mkdir(dest) except FileNotFoundError: pass # get source of data_files source = pmag.get_named_arg('-s', sys.prefix, False) source = path.realpath(source) if source.endswith('data_files') or source.endswith('data_files/'): source = path.split(source)[0] # copy data_files to PmagPy-data directory data_files = path.join(source, 'data_files') copy_directory(data_files, dest) # now try to get notebooks pmagpy_dir = find_pmag_dir.get_pmag_dir() for notebook in ['PmagPy.ipynb', 'PmagPy-cli.ipynb']: # for pip install notebook_location = path.join(dest, 'data_files', notebook) if path.exists(notebook_location): shutil.copy(path.join(dest, 'data_files', notebook), path.join(dest, notebook)) # for developer install elif pmagpy_dir: if path.exists(path.join(pmagpy_dir, notebook)): shutil.copy(path.join(pmagpy_dir, notebook), path.join(dest, notebook))
def main(): if '-h' in sys.argv: print("Some mapping utilities use the Etopo package for topography and these data sets do not come standard with the Python installation of Basemap. To install these additional files, use: 'install_etopo.py'.") print("However, if you are using cartopy for plotting (recommended), you do not need to run install_etopo.py.") return try: from mpl_toolkits.basemap import basemap_datadir except: print("-I- Some mapping utilities use the Etopo package for topography and these data sets do not come standard with the Python installation of Basemap. However, if you are using cartopy for plotting (recommended), you do not need to run install_etopo.py.") print("-E- Basemap does not appear to be installed, aborting program...") else: # allow user to specify what directory to find the data_files in custom_dir = pmag.get_named_arg('-source-dir', default_val="") if os.path.isdir(custom_dir): data_dir = custom_dir # if user didn't specify a directory, find the etopo20 directory else: # if installed by pip, etopo20 is in sys.prefix pip_data_dir = os.path.join(sys.prefix, 'data_files', 'etopo20') if os.path.isdir(pip_data_dir): data_dir = pip_data_dir else: # if not installed by pip, etopo20 is in the local PmagPy directory from pmagpy import find_pmag_dir pmag_dir = find_pmag_dir.get_pmag_dir() data_dir = os.path.join(pmag_dir, 'data_files', 'etopo20') # if none of those options worked, warn the user: if not os.path.isdir(data_dir): print("-W- Could not find data_files to copy in {}".format(data_dir)) print("-I- You can run this program with the command line flag -source-dir to specify the location of the etopo20 directory.") print("-I- For example: 'install_etopo.py -source-dir ~/Python/PmagPy/data_files/etopo20'") return print("installing etopo20 files from ", path.join(data_dir, 'etopo20*')) print("to the basemap data directory: ",basemap_datadir) if sys.platform in ['win32', 'win64']: command = 'copy ' + path.join(data_dir, 'etopo20*') + " "+ basemap_datadir else: command = 'cp ' + path.join(data_dir, 'etopo20*') + " "+ basemap_datadir os.system(command)
def main(): if '-h' in sys.argv: print(" Help for move_data_files.py:") print( " Choose the folder where you want the PmagPy data files to be." ) print( " Navigate to that folder, and use the command: 'move_data_files.py'" ) print( " Alternatively, you may use the full path to the directory of your choice from anywhere in the file system, using the '-d' flag: 'move_data_files.py -d /Users/***/Desktop' where *** is your username" ) print( " **IMPORTANT** If you have a developer install, move_data_files.py won't work. Simply navigate to your PmagPy directory. You can find the data_files directory and all PmagPy notebooks there." ) sys.exit() # create PmagPy-data directory dest = pmag.get_named_arg('-d', '.', False) dest = path.realpath(dest) dest = path.join(dest, 'PmagPy-data') if not path.exists(dest): try: os.mkdir(dest) except FileNotFoundError: pass # get source of data_files source = pmag.get_named_arg('-s', sys.prefix, False) source = path.realpath(source) if source.endswith('data_files') or source.endswith('data_files/'): source = path.split(source)[0] # copy data_files to PmagPy-data directory data_files = path.join(source, 'data_files') copy_directory(data_files, dest) # now try to get notebooks pmagpy_dir = find_pmag_dir.get_pmag_dir() # needs all the notebooks for notebook_location in glob.glob( path.join(source, "data_files", "PmagPy*.ipynb")): notebook_name = os.path.split(notebook_location)[1] shutil.copy(notebook_location, path.join(dest, notebook_name))
def get_dm_offline(self): """ Grab the 3.0 data model from the PmagPy/pmagpy directory """ pmag_dir = find_pmag_dir.get_pmag_dir() if pmag_dir is None: pmag_dir = '.' model_file = os.path.join(pmag_dir, 'pmagpy', 'data_model', 'data_model.json') # for py2app: if not os.path.isfile(model_file): model_file = os.path.join(pmag_dir, 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join(os.path.split(os.path.dirname(__file__))[0],'pmagpy', 'data_model','data_model.json') if not os.path.isfile(model_file): model_file = os.path.join(os.path.split(os.path.dirname(__file__))[0], 'data_model','data_model.json') f = open(model_file, 'r') string = '\n'.join(f.readlines()) raw = json.loads(unicode(string, errors='ignore')) full = DataFrame(raw) return full
def find_cached_dm(self): """ Find filename where cached data model json is stored. Returns --------- model_file : str data model json file location """ pmag_dir = find_pmag_dir.get_pmag_dir() if pmag_dir is None: pmag_dir = '.' model_file = os.path.join(pmag_dir, 'pmagpy', 'data_model', 'data_model.json') # for py2app: if not os.path.isfile(model_file): model_file = os.path.join(pmag_dir, 'data_model', 'data_model.json') if not os.path.isfile(model_file): model_file = os.path.join(os.path.split(os.path.dirname(__file__))[0],'pmagpy', 'data_model','data_model.json') if not os.path.isfile(model_file): model_file = os.path.join(os.path.split(os.path.dirname(__file__))[0], 'data_model','data_model.json') return model_file
def main(): if '-h' in sys.argv: print(" Help for move_data_files.py:") print(" Choose the folder where you want the PmagPy data files to be.") print(" Navigate to that folder, and use the command: 'move_data_files.py'") print(" Alternatively, you may use the full path to the directory of your choice from anywhere in the file system, using the '-d' flag: 'move_data_files.py -d /Users/***/Desktop' where *** is your username") print(" **IMPORTANT** If you have a developer install, this won\'t work. Simply navigate to your PmagPy directory. You can find data_files, PmagPy.ipynb and PmagPy-cli.ipynb there.") sys.exit() # create PmagPy-data directory dest = pmag.get_named_arg('-d', '.', False) dest = path.realpath(dest) dest = path.join(dest, 'PmagPy-data') if not path.exists(dest): try: os.mkdir(dest) except FileNotFoundError: pass # get source of data_files source = pmag.get_named_arg('-s', sys.prefix, False) source = path.realpath(source) if source.endswith('data_files') or source.endswith('data_files/'): source = path.split(source)[0] # copy data_files to PmagPy-data directory data_files = path.join(source, 'data_files') copy_directory(data_files, dest) # now try to get notebooks pmagpy_dir = find_pmag_dir.get_pmag_dir() for notebook in ['PmagPy.ipynb', 'PmagPy-cli.ipynb']: # for pip install notebook_location = path.join(dest, 'data_files', notebook) if path.exists(notebook_location): shutil.copy(path.join(dest, 'data_files', notebook), path.join(dest, notebook)) # for developer install elif pmagpy_dir: if path.exists(path.join(pmagpy_dir, notebook)): shutil.copy(path.join(pmagpy_dir, notebook), path.join(dest, notebook))
from pmagpy import pmag from pmagpy import ipmag from pmagpy import builder2 as builder from pmagpy import contribution_builder as cb from dialogs import pmag_gui_dialogs as pgd3 from dialogs import pmag_gui_dialogs2 as pgd2 from dialogs import pmag_er_magic_dialogs from dialogs import pmag_gui_menu3 as pmag_gui_menu from dialogs import ErMagicBuilder from dialogs import demag_dialogs from dialogs import pmag_widgets as pw global PMAGPY_DIRECTORY import pmagpy.find_pmag_dir as find_pmag_dir PMAGPY_DIRECTORY = find_pmag_dir.get_pmag_dir() from programs import demag_gui from programs import thellier_gui class MagMainFrame(wx.Frame): """""" try: version = pmag.get_version() except: version = "" title = "Pmag GUI version: %s" % version def __init__(self, WD=None, DM=None, dmodel=None): """
import os import webbrowser from pmagpy import pmag from pmagpy import ipmag from pmagpy import builder2 as builder from pmagpy import contribution_builder as cb from dialogs import pmag_gui_dialogs as pgd3 from dialogs import pmag_gui_dialogs2 as pgd2 from dialogs import pmag_er_magic_dialogs from dialogs import pmag_gui_menu3 as pmag_gui_menu from dialogs import ErMagicBuilder from dialogs import pmag_widgets as pw import pmagpy.find_pmag_dir as find_pmag_dir PMAGPY_DIRECTORY = find_pmag_dir.get_pmag_dir() from programs import demag_gui from programs import thellier_gui class MagMainFrame(wx.Frame): """""" try: version = pmag.get_version() except: version = "" title = "Pmag GUI version: %s"%version def __init__(self, WD=None, DM=None, dmodel=None): """
def revert_from_backup(WD): print("reverting") backup_dir = os.path.join(WD,'.backup') #copy test files to backup src_files = os.listdir(backup_dir) for file_name in src_files: full_file_name = os.path.join(backup_dir, file_name) if (os.path.isfile(full_file_name)): shutil.copy(full_file_name, os.path.join(WD,file_name)) os.remove(full_file_name) if os.path.exists(backup_dir): os.rmdir(backup_dir) if __name__ == '__main__': WD = find_pmag_dir.get_pmag_dir() if '-d' in sys.argv: d_index = sys.argv.index('-d') project_WD = os.path.join(WD,sys.argv[d_index+1]) elif '--dir' in sys.argv: d_index = sys.argv.index('--dir') project_WD = os.path.join(WD,sys.argv[d_index+1]) else: project_WD = os.path.join(WD, 'pmagpy_tests', 'examples', 'demag_test_data') core_depthplot_WD = os.path.join(WD, 'data_files', 'core_depthplot') empty_WD = os.path.join(os.getcwd(), 'pmagpy_tests', 'examples', 'empty_dir') if '-e' in sys.argv: e_index = sys.argv.index('-e') allowable_float_error = float(sys.argv[e_index]) elif '--error' in sys.argv: e_index = sys.argv.index('--error')