diff --git a/Private2PublicSteps.md b/Private2PublicSteps.md new file mode 100644 index 0000000..6cce713 --- /dev/null +++ b/Private2PublicSteps.md @@ -0,0 +1,11 @@ +In order to push the private master branch over to the public master branch follow these steps. + +```bash +mkdir kaipy-promotion +cd kaipy-promotion +git clone git@bitbucket.org:aplkaiju/kaipy-private.git +cd kaipy-private +git remote add public git@bitbucket.org:aplkaiju/kaipy.git +git fetch +git push --force public master +``` \ No newline at end of file diff --git a/docs/source/intro.rst b/docs/source/intro.rst deleted file mode 100644 index 2b9cdb3..0000000 --- a/docs/source/intro.rst +++ /dev/null @@ -1,4 +0,0 @@ -Introduction -============ - -``kaipy`` is a Python package for supporting the running and analysis of the Mutliscale Atmosphere Geospace Environment (MAGE) Model developed by the Center for Geospace Storms. diff --git a/docs/source/scripts.rst b/docs/source/scripts.rst index 50a559e..64942e4 100644 --- a/docs/source/scripts.rst +++ b/docs/source/scripts.rst @@ -1,5 +1,67 @@ Kaipy scripts ================ +Quicklook +--------- +The quicklook directory has scripts that are used to quickly look at the data. The scripts are written in python and use the matplotlib library to plot the data. The scripts are: + +.. .. autoprogram:: dbpic:create_command_line_parser() +.. :prog: dbpic.py + +.. .. autoprogram:: dbVpic:create_command_line_parser() +.. :prog: dbVpic.py + +.. autoprogram:: dstpic:create_command_line_parser() + :prog: dstpic.py + +.. autoprogram:: gamerrpic:create_command_line_parser() + :prog: gamerrpic.py + +.. autoprogram:: gamerrVid:create_command_line_parser() + :prog: gamerrVid.py + +.. autoprogram:: gamsphVid:create_command_line_parser() + :prog: gamsphVid.py + +.. .. autoprogram:: heliomovie:create_command_line_parser() +.. :prog: heliomovie.py + +.. .. autoprogram:: heliopic:create_command_line_parser() +.. :prog: heliopic.py + +.. autoprogram:: mixpic:create_command_line_parser() + :prog: mixpic.py + .. autoprogram:: msphpic:create_command_line_parser() - :prog: msphpic.py \ No newline at end of file + :prog: msphpic.py + +.. autoprogram:: rcmDataProbe:create_command_line_parser() + :prog: rcmDataProbe.py + +.. autoprogram:: rcmpic:create_command_line_parser() + :prog: rcmpic.py + +.. autoprogram:: rcmDataProbe:create_command_line_parser() + :prog: rcmDataProbe.py + +.. autoprogram:: rcmPrecipSpecFlux:create_command_line_parser() + :prog: rcmPrecipSpecFlux.py + +.. autoprogram:: rcmPrecipSpecFlux:create_command_line_parser() + :prog: rcmPrecipSpecFlux.py + +.. autoprogram:: remixTimeSeries:create_command_line_parser() + :prog: remixTimeSeries.py + +.. autoprogram:: swpic:create_command_line_parser() + :prog: swpic.py + +.. autoprogram:: vizTrj:create_command_line_parser() + :prog: vizTrj.py + + + + + + + diff --git a/kaipy/scripts/quicklook/dbVid.py b/kaipy/scripts/quicklook/dbVid.py index 0129a48..38f33ad 100755 --- a/kaipy/scripts/quicklook/dbVid.py +++ b/kaipy/scripts/quicklook/dbVid.py @@ -15,14 +15,19 @@ import kaipy.cmaps.kaimaps as kmaps import kaipy.gamera.deltabViz as dbViz import sys import os +import errno import cartopy.crs as ccrs -if __name__ == "__main__": - rad2deg = 180.0/np.pi - bMag = dbViz.dbMag - bLin = dbViz.dbLin +def create_command_line_parser(): + """Create the command-line argument parser. + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ #Defaults + fdir = os.getcwd() ftag = "msphere" oDir = "vid2D" @@ -47,6 +52,16 @@ if __name__ == "__main__": parser.add_argument('-Nblk' ,type=int,metavar="Nblk",default=Nblk,help="Number of job blocks (default: %(default)s)") parser.add_argument('-nID' ,type=int,metavar="nID" ,default=nID,help="Block ID of this job [1-Nblk] (default: %(default)s)") + return parser + + +if __name__ == "__main__": + #Defaults + rad2deg = 180.0/np.pi + bMag = dbViz.dbMag + bLin = dbViz.dbLin + # Set up the command-line parser. + parser = create_command_line_parser() #Finalize parsing args = parser.parse_args() fdir = args.d diff --git a/kaipy/scripts/quicklook/dbpic.py b/kaipy/scripts/quicklook/dbpic.py index 9775211..650f29b 100755 --- a/kaipy/scripts/quicklook/dbpic.py +++ b/kaipy/scripts/quicklook/dbpic.py @@ -65,14 +65,8 @@ def create_command_line_parser(): Create the parser for command-line arguments. - Parameters - ---------- - None - - Returns - ------- - parser : argparse.ArgumentParser - Command-line argument parser for this script. + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. """ parser = argparse.ArgumentParser(description=description) parser.add_argument( diff --git a/kaipy/scripts/quicklook/dstpic.py b/kaipy/scripts/quicklook/dstpic.py index 279e8ea..30d6201 100755 --- a/kaipy/scripts/quicklook/dstpic.py +++ b/kaipy/scripts/quicklook/dstpic.py @@ -17,24 +17,42 @@ from astropy.time import Time import os import kaipy.kaiH5 as kaiH5 -if __name__ == "__main__": +def create_command_line_parser(): + """Create the command-line argument parser. + + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ #Defaults fdir = os.getcwd() ftag = "msphere" swfname = "bcwind.h5" tpad = 8 #Number of hours beyond MHD to plot - iMax = -1 + doDPS = False MainS = """Creates simple plot comparing SYM-H from OMNI dataset to Gamera-RCM. Need to run or point to directory that has the bcwind and msphere.gam files of interest """ - parser = argparse.ArgumentParser(description=MainS, formatter_class=RawTextHelpFormatter) parser.add_argument('-d',type=str,metavar="directory",default=fdir,help="Directory to read from (default: %(default)s)") parser.add_argument('-id',type=str,metavar="runid",default=ftag,help="RunID of data (default: %(default)s)") parser.add_argument('-tpad',type=float,metavar="time padding",default=tpad,help="Time beyond MHD data (in hours) to plot (default: %(default)s)") parser.add_argument('-swfile',type=str,metavar='filename',default=swfname,help="Solar wind file name (default: %(default)s)") parser.add_argument('--dps',action='store_true',help="Also plot the DPS Dst (default: %(default)s)") + + + return parser + +if __name__ == "__main__": + + #Defaults + iMax = -1 + + # Set up the command-line parser. + parser = create_command_line_parser() + #Finalizing parsing args = parser.parse_args() fdir = args.d diff --git a/kaipy/scripts/quicklook/gamerrVid.py b/kaipy/scripts/quicklook/gamerrVid.py index d4a3143..606ced8 100755 --- a/kaipy/scripts/quicklook/gamerrVid.py +++ b/kaipy/scripts/quicklook/gamerrVid.py @@ -21,25 +21,14 @@ import subprocess import shutil cLW = 0.25 +def create_command_line_parser(): + """Create the command-line argument parser. -def makeMovie(frame_dir,movie_name): - frame_pattern = frame_dir + "/vid.%04d.png" - movie_file = os.getcwd() + "/" + movie_name + ".mp4" - ffmpegExe = "ffmpeg" - if shutil.which(ffmpegExe) is None: - ffmpegExe = "ffmpeg4" - if shutil.which(ffmpegExe) is None: - print("Could not find any ffmpeg executable. Video will not be generated.") - return + Create the parser for command-line arguments. - cmd = [ - ffmpegExe, "-nostdin", "-i", frame_pattern, - "-vcodec", "libx264", "-crf", "14", "-profile:v", "high", "-pix_fmt", "yuv420p", - movie_file,"-y" - ] - subprocess.run(cmd, check=True) - -if __name__ == "__main__": + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ #Defaults fdir1 = os.getcwd() ftag1 = "msphere" @@ -51,7 +40,6 @@ if __name__ == "__main__": dt = 60.0 #[sec] Nblk = 1 #Number of blocks nID = 1 #Block ID of this job - noMPI = False # Don't add MPI tiling noLog = False fieldNames = "Bx, By, Bz" doVerb = False @@ -81,6 +69,30 @@ if __name__ == "__main__": mviz.AddSizeArgs(parser) + return parser + +def makeMovie(frame_dir,movie_name): + frame_pattern = frame_dir + "/vid.%04d.png" + movie_file = os.getcwd() + "/" + movie_name + ".mp4" + ffmpegExe = "ffmpeg" + if shutil.which(ffmpegExe) is None: + ffmpegExe = "ffmpeg4" + if shutil.which(ffmpegExe) is None: + print("Could not find any ffmpeg executable. Video will not be generated.") + return + + cmd = [ + ffmpegExe, "-nostdin", "-i", frame_pattern, + "-vcodec", "libx264", "-crf", "14", "-profile:v", "high", "-pix_fmt", "yuv420p", + movie_file,"-y" + ] + subprocess.run(cmd, check=True) + +if __name__ == "__main__": + #Defaults + noMPI = False # Don't add MPI tiling + # Set up the command-line parser. + parser = create_command_line_parser() #Finalize parsing args = parser.parse_args() fdir1 = args.d1 diff --git a/kaipy/scripts/quicklook/gamerrpic.py b/kaipy/scripts/quicklook/gamerrpic.py index b00ff36..81cd2a8 100755 --- a/kaipy/scripts/quicklook/gamerrpic.py +++ b/kaipy/scripts/quicklook/gamerrpic.py @@ -17,8 +17,14 @@ import os import errno cLW = 0.25 +def create_command_line_parser(): + """Create the command-line argument parser. -if __name__ == "__main__": + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ #Defaults fdir1 = os.getcwd() ftag1 = "msphere" @@ -26,8 +32,7 @@ if __name__ == "__main__": ftag2 = "msphere" nStp=1 fieldNames = "Bx, By, Bz" - doMPI = False #[Add MPI tiling] - noMPI = False + MainS = """Creates simple multi-panel figure for Gamera magnetosphere run Left Panel - Residual vertical magnetic field @@ -45,6 +50,14 @@ if __name__ == "__main__": mviz.AddSizeArgs(parser) + return parser + +if __name__ == "__main__": + #Defaults + doMPI = False #[Add MPI tiling] + noMPI = False + # Set up the command-line parser. + parser = create_command_line_parser() #Finalize parsing args = parser.parse_args() fdir1 = args.d1 diff --git a/kaipy/scripts/quicklook/gamsphVid.py b/kaipy/scripts/quicklook/gamsphVid.py index f6de088..22e6d17 100755 --- a/kaipy/scripts/quicklook/gamsphVid.py +++ b/kaipy/scripts/quicklook/gamsphVid.py @@ -19,23 +19,25 @@ import os import errno cLW = 0.25 +def create_command_line_parser(): + """Create the command-line argument parser. -if __name__ == "__main__": + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ #Defaults fdir = os.getcwd() ftag = "msphere" oDir = "vid2D" - doDen = False ts = 0 #[min] te = 200 #[min] dt = 60.0 #[sec] - doBig = False #[Use big window] noIon = False noRCM = False - doMPI = False #[Add MPI tiling] Nblk = 1 #Number of blocks nID = 1 #Block ID of this job - noMPI = False doJy = False doBz = False doBigRCM = False @@ -63,6 +65,16 @@ if __name__ == "__main__": mviz.AddSizeArgs(parser) + return parser + +if __name__ == "__main__": + #Defaults + doDen = False + doMPI = False #[Add MPI tiling] + doBig = False #[Use big window] + noMPI = False + # Set up the command-line parser. + parser = create_command_line_parser() #Finalize parsing args = parser.parse_args() fdir = args.d diff --git a/kaipy/scripts/quicklook/heliomovie.py b/kaipy/scripts/quicklook/heliomovie.py index b502383..8a77628 100755 --- a/kaipy/scripts/quicklook/heliomovie.py +++ b/kaipy/scripts/quicklook/heliomovie.py @@ -126,22 +126,11 @@ SPACECRAFT_COLORS = list(mpl.colors.TABLEAU_COLORS.keys()) def create_command_line_parser(): - """Create the command-line argument parser. + """ + Create the command-line argument parser. - Create the parser for command-line arguments. - - Parameters - ---------- - None - - Returns - ------- - parser : argparse.ArgumentParser - Command-line argument parser for this script. - - Raises - ------ - None + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. """ parser = argparse.ArgumentParser( description=description, diff --git a/kaipy/scripts/quicklook/heliopic.py b/kaipy/scripts/quicklook/heliopic.py index eb296e9..517d8dc 100755 --- a/kaipy/scripts/quicklook/heliopic.py +++ b/kaipy/scripts/quicklook/heliopic.py @@ -119,23 +119,6 @@ SPACECRAFT_COLORS = list(mpl.colors.TABLEAU_COLORS.keys()) def create_command_line_parser(): - """Create the command-line argument parser. - - Create the parser for command-line arguments. - - Parameters - ---------- - None - - Returns - ------- - parser : argparse.ArgumentParser - Command-line argument parser for this script. - - Raises - ------ - None - """ parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument( "--debug", action="store_true", diff --git a/kaipy/scripts/quicklook/mixpic.py b/kaipy/scripts/quicklook/mixpic.py index df137ba..f133c79 100755 --- a/kaipy/scripts/quicklook/mixpic.py +++ b/kaipy/scripts/quicklook/mixpic.py @@ -79,18 +79,11 @@ default_coord = 'SM' def create_command_line_parser(): - """Create the command-line argument parser. - - Create the parser for command-line arguments. + """ + Create the command-line argument parser. - Parameters - ---------- - None - - Returns - ------- - parser : argparse.ArgumentParser - Command-line argument parser for this script. + Returns: + parser (argparse.ArgumentParser): Command-line argument parser for this script. """ parser = argparse.ArgumentParser( description=description, diff --git a/kaipy/scripts/quicklook/msphpic.py b/kaipy/scripts/quicklook/msphpic.py index 197e6ba..276c2b1 100755 --- a/kaipy/scripts/quicklook/msphpic.py +++ b/kaipy/scripts/quicklook/msphpic.py @@ -61,17 +61,11 @@ SPACECRAFT_COLOR = 'red' def create_command_line_parser(): """Create the command-line argument parser. - + Create the parser for command-line arguments. - Parameters - ---------- - None - - Returns - ------- - parser : argparse.ArgumentParser - Command-line argument parser for this script. + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. """ parser = argparse.ArgumentParser( description=description, diff --git a/kaipy/scripts/quicklook/rcmDataProbe.py b/kaipy/scripts/quicklook/rcmDataProbe.py index 3b45601..fdb33ca 100755 --- a/kaipy/scripts/quicklook/rcmDataProbe.py +++ b/kaipy/scripts/quicklook/rcmDataProbe.py @@ -34,12 +34,17 @@ density_factor = nt/re specFlux_factor = 1/np.pi/np.sqrt(8)*np.sqrt(ev/massi)*nt/re/1.0e1 # [units/cm^2/keV/str] precipSpecFlux_factor = 1/nT2T/(m2cm**2)/(4*np.pi) -if __name__ == "__main__": +def create_command_line_parser(): + """Create the command-line argument parser. + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ varChoices = [VOPT_SF, VOPT_PSF, VOPT_D, VOPT_P] ftag = "msphere" - cmap = plt.cm.plasma timeStr = "" locStr = "-5,0,0" numSamples = 6 @@ -54,6 +59,14 @@ if __name__ == "__main__": parser.add_argument('-l',type=str,metavar="loc",default=locStr,help="Comma-separated x,y,z values for equatorial location (default: %(default)s)") parser.add_argument('-e',action='store_true',default=False,help="Flag to plot electrons instead of ions (default: %(default)s)") parser.add_argument('-v',choices=varChoices,default=varStr,help="Variable to plot (default: %(default)s)") + + return parser + +if __name__ == "__main__": + #Defaults + cmap = plt.cm.plasma + # Set up the command-line parser. + parser = create_command_line_parser() args = parser.parse_args() ftag = args.id numSamples = args.n diff --git a/kaipy/scripts/quicklook/rcmPrecipSpecFlux.py b/kaipy/scripts/quicklook/rcmPrecipSpecFlux.py index 70b2341..6721ba8 100755 --- a/kaipy/scripts/quicklook/rcmPrecipSpecFlux.py +++ b/kaipy/scripts/quicklook/rcmPrecipSpecFlux.py @@ -14,10 +14,16 @@ from matplotlib import rcParams, cycler import argparse from argparse import RawTextHelpFormatter +def create_command_line_parser(): + """Create the command-line argument parser. -if __name__ == "__main__": + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ + #Defaults ftag = "msphere" - cmap = plt.cm.plasma timeStr = "" locStr = "-5,0,0" numSamples = 6 @@ -30,7 +36,15 @@ if __name__ == "__main__": parser.add_argument('-t',type=str,metavar="times",default=timeStr,help="Comma-separated times (in hours) to plot (example: 1,2,4,6). Ignores numSamples") parser.add_argument('-l',type=str,metavar="loc",default=locStr,help="Comma-separated x,y,z values for equatorial location (default: %(default)s)") parser.add_argument('-i',action='store_true',default=False,help="Flag to plot ions instead of electrons (default: %(default)s)") - + + return parser + +if __name__ == "__main__": + #Defaults + cmap = plt.cm.plasma + # Set up the command-line parser. + parser = create_command_line_parser() + #Finalize parsing args = parser.parse_args() ftag = args.id numSamples = args.n diff --git a/kaipy/scripts/quicklook/rcmSpecFlux.py b/kaipy/scripts/quicklook/rcmSpecFlux.py index 6cdad8e..2b95c1e 100755 --- a/kaipy/scripts/quicklook/rcmSpecFlux.py +++ b/kaipy/scripts/quicklook/rcmSpecFlux.py @@ -15,9 +15,16 @@ from matplotlib import rcParams, cycler import argparse from argparse import RawTextHelpFormatter -if __name__ == "__main__": +def create_command_line_parser(): + """Create the command-line argument parser. + + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ + #Defaults ftag = "msphere" - cmap = plt.cm.plasma timeStr = "" locStr = "-5,0,0" numSamples = 6 @@ -30,7 +37,16 @@ if __name__ == "__main__": parser.add_argument('-t',type=str,metavar="times",default=timeStr,help="Comma-separated times (in hours) to plot (example: 1,2,4,6). Ignores numSamples") parser.add_argument('-l',type=str,metavar="loc",default=locStr,help="Comma-separated x,y,z values for equatorial location (default: %(default)s)") parser.add_argument('-e',action='store_true',default=False,help="Flag to plot electrons instead of ions (default: %(default)s)") - + + return parser + + +if __name__ == "__main__": + #Defaults + cmap = plt.cm.plasma + # Set up the command-line parser. + parser = create_command_line_parser() + #Finalize parsing args = parser.parse_args() ftag = args.id numSamples = args.n diff --git a/kaipy/scripts/quicklook/rcmpic.py b/kaipy/scripts/quicklook/rcmpic.py index 38325d4..5d9b7fd 100755 --- a/kaipy/scripts/quicklook/rcmpic.py +++ b/kaipy/scripts/quicklook/rcmpic.py @@ -54,17 +54,11 @@ default_step = -1 def create_command_line_parser(): """Create the command-line argument parser. - + Create the parser for command-line arguments. - Parameters - ---------- - None - - Returns - ------- - parser : argparse.ArgumentParser - Command-line argument parser for this script. + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. """ parser = argparse.ArgumentParser( description=description, diff --git a/kaipy/scripts/quicklook/remixTimeSeries.py b/kaipy/scripts/quicklook/remixTimeSeries.py index cf65d75..64f5cd2 100755 --- a/kaipy/scripts/quicklook/remixTimeSeries.py +++ b/kaipy/scripts/quicklook/remixTimeSeries.py @@ -21,109 +21,121 @@ import kaipy.kaiH5 as kaiH5 import kaipy.remix.remix as remix import kaipy.kaiViz as kv from kaipy.kaiTools import MJD2UT +def create_command_line_parser(): + """Create the command-line argument parser. -MainS = """Creates a summary plot of global ionospheric paramters including -CPCP, HP, FAC. Creates a PNG image file and python pickle file with the data. -""" + Create the parser for command-line arguments. -ftag = 'msphere' -ptag = '.' -parser = argparse.ArgumentParser(description=MainS, - formatter_class=RawTextHelpFormatter) -parser.add_argument('-id',type=str,metavar='runid',default=ftag, - help='RunID of data (default: %(default)s)') -parser.add_argument('-path',type=str,metavar='path',default=ptag, - help='Path to directory containing REMIX files (default: %(default)s)') + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ + #Defaults + MainS = """Creates a summary plot of global ionospheric paramters including + CPCP, HP, FAC. Creates a PNG image file, python pickle file as well as a HDF5 file with the data. + """ -args = parser.parse_args() -#Open the file and read the time information -remixFile = os.path.join(args.path,args.id+'.mix.h5') -assert(os.path.isfile(remixFile)) -nsteps,sIds=kaiH5.cntSteps(remixFile) -mjd = kaiH5.getTs(remixFile,sIds,aID='MJD') -utall = MJD2UT(mjd) + ftag = 'msphere' + ptag = '.' + parser = argparse.ArgumentParser(description=MainS, + formatter_class=RawTextHelpFormatter) + parser.add_argument('-id',type=str,metavar='runid',default=ftag, + help='RunID of data (default: %(default)s)') + parser.add_argument('-path',type=str,metavar='path',default=ptag, + help='Path to directory containing REMIX files (default: %(default)s)') + + return parser -#Setup the dictionary data structures to handle the timeseries information -hemispheres = ('NORTH','SOUTH') -cpcp = {'NORTH':[],'SOUTH':[]} -hp = {'NORTH':[],'SOUTH':[]} -ipfac = {'NORTH':[],'SOUTH':[]} +if __name__ == "__main__": + parser = create_command_line_parser() + args = parser.parse_args() + #Open the file and read the time information + remixFile = os.path.join(args.path,args.id+'.mix.h5') + assert(os.path.isfile(remixFile)) + nsteps,sIds=kaiH5.cntSteps(remixFile) + mjd = kaiH5.getTs(remixFile,sIds,aID='MJD') + utall = MJD2UT(mjd) -#Read the data and calculate the integrated quantities -ri = 6500.0e3 -for hemi in hemispheres: - ion = remix.remix(remixFile,sIds.min()) - ion.init_vars(hemi) - x = ion.ion['X'] - y = ion.ion['Y'] - areaMixGrid = ion.calcFaceAreas(x,y)*ri*ri - for Id in sorted(sIds): - ion = remix.remix(remixFile,Id) - ion.init_vars(hemi) - # Cross polar cap potential - cpcp[hemi].append(np.max(ion.variables['potential']['data'])- - np.min(ion.variables['potential']['data'])) - # Integrated Postive FAC - fac = ion.variables['current']['data'] - fac[fac < 0] = 0.0 - pfac = areaMixGrid*fac[:,:] - ipfac[hemi].append(pfac.sum()/1.0e12) - # Hemispheric Power - flux = ion.variables['flux']['data'] - energy = ion.variables['energy']['data'] - hpcalc = areaMixGrid*energy[:,:]*flux[:,:] - # Convert from keV/cm^2 to mW/m^2 to GW - hp[hemi].append(hpcalc.sum()*1.6e-21) + #Setup the dictionary data structures to handle the timeseries information + hemispheres = ('NORTH','SOUTH') + cpcp = {'NORTH':[],'SOUTH':[]} + hp = {'NORTH':[],'SOUTH':[]} + ipfac = {'NORTH':[],'SOUTH':[]} -cpcp['units']='kV' -cpcp['name']=r'$\Phi$' -hp['units']='GW' -hp['name']='HP' -ipfac['units']='MA' -ipfac['name']='FAC' - -#Plot the figure -figsize = (10,10) -fig = plt.figure(figsize=figsize) -gs = fig.add_gridspec(3,1) -Ax1 = fig.add_subplot(gs[0,0]) -Ax2 = fig.add_subplot(gs[1,0],sharex=Ax1) -Ax3 = fig.add_subplot(gs[2,0],sharex=Ax1) -Ax1.plot(utall[1:],cpcp['NORTH'][1:]) -Ax1.plot(utall[1:],cpcp['SOUTH'][1:]) -kv.SetAxLabs(Ax1,None,cpcp['name']+' ['+cpcp['units']+']') -Ax2.plot(utall[1:],ipfac['NORTH'][1:]) -Ax2.plot(utall[1:],ipfac['SOUTH'][1:]) -kv.SetAxLabs(Ax2,None,ipfac['name']+' ['+ipfac['units']+']',doLeft=False) -Ax3.plot(utall[1:],hp['NORTH'][1:]) -Ax3.plot(utall[1:],hp['SOUTH'][1:]) -kv.SetAxLabs(Ax3,"UT",hp['name']+' ['+hp['units']+']') -kv.SetAxDate(Ax3) -Ax1.legend(hemispheres,loc='best') -Ax1.set_title(remixFile) -plt.subplots_adjust(hspace=0) -fn = os.path.join(ptag,'remixTimeSeries.png') -kv.savePic(fn) - -#Save the results to python pickle file -fn = os.path.join(ptag,'remixTimeSeries.pkl') -fh = open(fn,'wb') -pickle.dump([cpcp,ipfac,hp,utall],fh) -fh.close() - -#As well as a HDF5 file -with h5py.File(os.path.join(ptag,'remixTimeSeries.h5'),'w') as f: - dset = f.create_dataset('MJD',data=mjd) + #Read the data and calculate the integrated quantities + ri = 6500.0e3 for hemi in hemispheres: - dset = f.create_dataset('cpcp'+hemi,data=cpcp[hemi]) - dset.attrs['units'] = cpcp['units'] - dset.attrs['name'] = cpcp['name'] - dset = f.create_dataset('hp'+hemi,data=hp[hemi]) - dset.attrs['units'] = hp['units'] - dset.attrs['name'] = hp['name'] - dset = f.create_dataset('ipfac'+hemi,data=ipfac[hemi]) - dset.attrs['units'] = ipfac['units'] - dset.attrs['name'] = ipfac['name'] + ion = remix.remix(remixFile,sIds.min()) + ion.init_vars(hemi) + x = ion.ion['X'] + y = ion.ion['Y'] + areaMixGrid = ion.calcFaceAreas(x,y)*ri*ri + for Id in sorted(sIds): + ion = remix.remix(remixFile,Id) + ion.init_vars(hemi) + # Cross polar cap potential + cpcp[hemi].append(np.max(ion.variables['potential']['data'])- + np.min(ion.variables['potential']['data'])) + # Integrated Postive FAC + fac = ion.variables['current']['data'] + fac[fac < 0] = 0.0 + pfac = areaMixGrid*fac[:,:] + ipfac[hemi].append(pfac.sum()/1.0e12) + # Hemispheric Power + flux = ion.variables['flux']['data'] + energy = ion.variables['energy']['data'] + hpcalc = areaMixGrid*energy[:,:]*flux[:,:] + # Convert from keV/cm^2 to mW/m^2 to GW + hp[hemi].append(hpcalc.sum()*1.6e-21) + + cpcp['units']='kV' + cpcp['name']=r'$\Phi$' + hp['units']='GW' + hp['name']='HP' + ipfac['units']='MA' + ipfac['name']='FAC' + + #Plot the figure + figsize = (10,10) + fig = plt.figure(figsize=figsize) + gs = fig.add_gridspec(3,1) + Ax1 = fig.add_subplot(gs[0,0]) + Ax2 = fig.add_subplot(gs[1,0],sharex=Ax1) + Ax3 = fig.add_subplot(gs[2,0],sharex=Ax1) + Ax1.plot(utall[1:],cpcp['NORTH'][1:]) + Ax1.plot(utall[1:],cpcp['SOUTH'][1:]) + kv.SetAxLabs(Ax1,None,cpcp['name']+' ['+cpcp['units']+']') + Ax2.plot(utall[1:],ipfac['NORTH'][1:]) + Ax2.plot(utall[1:],ipfac['SOUTH'][1:]) + kv.SetAxLabs(Ax2,None,ipfac['name']+' ['+ipfac['units']+']',doLeft=False) + Ax3.plot(utall[1:],hp['NORTH'][1:]) + Ax3.plot(utall[1:],hp['SOUTH'][1:]) + kv.SetAxLabs(Ax3,"UT",hp['name']+' ['+hp['units']+']') + kv.SetAxDate(Ax3) + Ax1.legend(hemispheres,loc='best') + Ax1.set_title(remixFile) + plt.subplots_adjust(hspace=0) + fn = os.path.join(args.path,'remixTimeSeries.png') + kv.savePic(fn) + + #Save the results to python pickle file + fn = os.path.join(args.path,'remixTimeSeries.pkl') + fh = open(fn,'wb') + pickle.dump([cpcp,ipfac,hp,utall],fh) + fh.close() + + #As well as a HDF5 file + with h5py.File(os.path.join(args.path,'remixTimeSeries.h5'),'w') as f: + dset = f.create_dataset('MJD',data=mjd) + for hemi in hemispheres: + dset = f.create_dataset('cpcp'+hemi,data=cpcp[hemi]) + dset.attrs['units'] = cpcp['units'] + dset.attrs['name'] = cpcp['name'] + dset = f.create_dataset('hp'+hemi,data=hp[hemi]) + dset.attrs['units'] = hp['units'] + dset.attrs['name'] = hp['name'] + dset = f.create_dataset('ipfac'+hemi,data=ipfac[hemi]) + dset.attrs['units'] = ipfac['units'] + dset.attrs['name'] = ipfac['name'] diff --git a/kaipy/scripts/quicklook/swpic.py b/kaipy/scripts/quicklook/swpic.py index 572af55..d063866 100755 --- a/kaipy/scripts/quicklook/swpic.py +++ b/kaipy/scripts/quicklook/swpic.py @@ -8,15 +8,21 @@ import os import datetime import sys +def create_command_line_parser(): + """Create the command-line argument parser. -if __name__ == "__main__": + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ #Defaults fdir = os.getcwd() swtag = "bcwind.h5" imgtype = 'png' MainS = """Creates simple multi-panel figure for the - solar wind conditions within the bcwind file and saves it as swBCplot.pdf + solar wind conditions with the bcwind file and saves it as swBCplot.imgtype """ parser = argparse.ArgumentParser(description=MainS, formatter_class=RawTextHelpFormatter) @@ -24,6 +30,13 @@ if __name__ == "__main__": parser.add_argument('-id',type=str,metavar="swid",default=swtag,help="Solar wind file used (default: %(default)s)") parser.add_argument('-type',type=str,metavar="type",default=imgtype,help="Image type (default: %(default)s)") + return parser + +if __name__ == "__main__": + #Defaults + + # Set up the command-line parser. + parser = create_command_line_parser() #Finalize parsing args = parser.parse_args() fdir = args.d diff --git a/kaipy/scripts/quicklook/vizTrj.py b/kaipy/scripts/quicklook/vizTrj.py index f216120..1909b65 100755 --- a/kaipy/scripts/quicklook/vizTrj.py +++ b/kaipy/scripts/quicklook/vizTrj.py @@ -42,9 +42,15 @@ def axEqual3d(ax): ax.set_ylim3d([y_mean - plot_radius, y_mean + plot_radius]) ax.set_zlim3d([z_mean - plot_radius, z_mean + plot_radius]) +def create_command_line_parser(): + """Create the command-line argument parser. -if __name__ == "__main__": - #Arg parsing + Create the parser for command-line arguments. + + Returns: + argparse.ArgumentParser: Command-line argument parser for this script. + """ + #Defaults id0 = 0 LW = 0.5 fs = 16 @@ -58,6 +64,15 @@ if __name__ == "__main__": parser.add_argument('h5p',metavar='input.h5part',help="Input H5Part file") parser.add_argument('-id',type=int,metavar="id",default=id0,help="Display particle trajectory w/ given ID (default: %(default)s)") + return parser + + +if __name__ == "__main__": + #Defaults + LW = 0.5 + fs = 16 + # Set up the command-line parser. + parser = create_command_line_parser() args = parser.parse_args() fIn = args.h5p id0 = args.id diff --git a/requirements.txt b/requirements.txt index 5575f2b..e8eaa69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,5 @@ pytest slack_sdk spacepy sphinx-rtd-theme +sphinxcontrib-autoprogram sunpy \ No newline at end of file