def ex_gmag(): # Delete any existing pytplot variables pytplot.del_data() # Define a time rage as a list trange = ['2015-12-31', '2015-12-31'] # Get a list of EPO gmag stations sites = pyspedas.themis.ground.gmag.gmag_list('epo') # Download gmag files and load data into pytplot variables pyspedas.themis.gmag(sites=sites, trange=trange) # Get a list of loaded sites sites_loaded = pyspedas.tnames() # Subtract mean values pyspedas.subtract_average(sites_loaded, '') # Download AE index data # pyspedas.load_data('gmag', time_list, ['idx'], '', '') pyspedas.themis.gmag(sites='idx', trange=trange) # Plot sites_loaded = pyspedas.tplot_names() pytplot.tplot_options('title', 'EPO GMAG 2015-12-31') pytplot.tplot(sites_loaded) # Return 1 as indication that the example finished without problems. return 1
def tnames(pattern=None): """ Find pytplot names. Parameters ---------- pattern : str, optional Patern to search for. The default is None, which returns all names. Returns ------- name_list : list of str List of pytplot variables. """ name_list = list() all_names = pyspedas.tplot_names() if pattern is None: name_list.extend(all_names) else: if isinstance(pattern, str): name_list.extend(fnmatch.filter(all_names, pattern)) else: for p in pattern: name_list.extend(fnmatch.filter(all_names, p)) return name_list
def ex_gmag(): # Delete any existing pytplot variables pytplot.del_data() # Define list of dates time_list = ['2015-12-31'] # Get a list of EPO gmag stations sites = pyspedas.gmag_list(group='epo') # Download gmag files and load data into pytplot variables pyspedas.load_data('gmag', time_list, sites, '', '') # Get a list of loaded sites sites_loaded = pyspedas.tplot_names() # Subtact mean values pyspedas.subtract_average(sites_loaded, '') # Download AE index data pyspedas.load_data('gmag', time_list, ['idx'], '', '') # Plot sites_loaded = pyspedas.tplot_names() pytplot.tplot_options('title', 'EPO GMAG 2015-12-31') pytplot.tplot(sites_loaded)
def download_and_load(remote_files, local_dir, download_only=False, varformat=None, get_support_data=False, prefix='', suffix=''): """ Download cdf files. Load cdf files into pytplot variables. TODO: Loading files into pytplot has problems. """ result = [] """ # For debug only msg = local_dir + str(download_only) + " ... " + '==='.join(remote_files) title = 'Download Files' show_my_message(title, msg) print(msg) """ remotehttp = "https://cdaweb.sci.gsfc.nasa.gov/sp_phys/data" count = 0 dcount = 0 for remotef in remote_files: f = remotef.strip().replace(remotehttp, '', 1) localf = local_dir + os.path.sep + f resp, err, locafile = pyspedas.download_files(remotef, localf) count += 1 if resp: print(str(count) + '. File was downloaded. Location: ' + locafile) dcount += 1 result.append(localf) if not download_only: try: pytplot.cdf_to_tplot(locafile, varformat, get_support_data, prefix, suffix, False, True) except ValueError as err: msg = "cdf_to_tplot could not load " + locafile msg += "\n\n" msg += "Error from pytplot: " + str(err) print(msg) show_my_message("Error!", msg) else: print( str(count) + '. There was a problem. Could not download \ file: ' + remotef) print(err) print('Downloaded ' + str(dcount) + ' files.') print('tplot variables:') print(pyspedas.tplot_names()) return result
def tnames(pattern=None): name_list = list() all_names = pyspedas.tplot_names() if pattern is None: name_list.extend(all_names) else: if isinstance(pattern, str): name_list.extend(fnmatch.filter(all_names, pattern)) else: for p in pattern: name_list.extend(fnmatch.filter(all_names, p)) return name_list
def themis_load(dates, probes, instruments, level, downloadonly=False, varformat=None, get_support_data=False, prefix='', suffix=''): """Loads themis data into pytplot variables""" file_list = themis_filename(dates, probes, instruments, level) # print(file_list) count = 0 dcount = 0 for remotef, localf in file_list: count += 1 resp, err, localfile = pyspedas.download_files(remotef, localf) if resp: print(str(count) + '. File was downloaded. Location: ' + localfile) dcount += 1 if not downloadonly: try: cdfvars = pyspedas.cdf_to_tplot(localfile, varformat, get_support_data, prefix, suffix, False, True) except TypeError as e: msg = "cdf_to_tplot could not load " + localfile + "\nError:\n" + str(e) print(msg) else: print( str(count) + '. There was a problem. Could not download \ file: ' + remotef) print(err) if len(dates) == 2: pyspedas.time_clip(cdfvars, dates[0], dates[1], cdfvars) print('Downloaded ' + str(dcount) + ' files.') print('tplot variables:') print(pyspedas.tplot_names())
def gmag_load(dates, stations, group=None, downloadonly=False, varformat=None, get_support_data=False, prefix='', suffix=''): """Loads themis data into pytplot variables""" if group is not None: stations = gmag_list(group) file_list = gmag_filename(dates, stations) count = 0 dcount = 0 for remotef, localf in file_list: count += 1 resp, err, locafile = pyspedas.download_files(remotef, localf) if resp: print(str(count) + '. File was downloaded. Location: ' + locafile) dcount += 1 if not downloadonly: try: testcdf = pyspedas.cdf_to_tplot(locafile, varformat, get_support_data, prefix, suffix, False, True) print(testcdf) except TypeError as e: msg = "cdf_to_tplot could not load " + locafile + "\nError:\n" + str(e) print(msg) else: print( str(count) + '. There was a problem. Could not download \ file: ' + remotef) print(err) print('Downloaded ' + str(dcount) + ' files.') print('tplot variables:') print(pyspedas.tplot_names())