def overlayFov(mapObj, codes=None, ids=None, names=None, dateTime=None, plot_all=False, maxGate=None, rangeLimits=None, beamLimits=None, model='IS', fov_dir='front', fovColor=None, fovAlpha=0.2, beams=None, beamsColors=None, hemi=None, fovObj=None, zorder=2, lineColor='k', lineWidth=1): """ Overlay FoV position(s) on map Parameters ---------- mapObj : mapObj or Basemap object Object on which to overplot the radar position(s) codes : Optional[list] List of radar 3-letter codes to plot ids : Optional[list] List of radar IDs to plot names : Optional[list] List of radar names to plot dateTime : Optional[datetime.datetime] Object to use for the FOV. Default: uses mapObj.dateTime plot_all : Optional[boolean] Set to true to plot all the radars (active ones) maxGate : Optional[int] Maximum number of gates to be plotted. Defaults to hdw.dat information. rangeLimits : Optional[list, int] Plot only between the range gates specified. beamLimits : Optional[2-element list] Plot only between the beams specified. model : Optional[str] IS : standard ionospheric scatter projection model (default) GS : standard ground scatter projection model S : standard projection model E1 : for Chisham E-region 1/2-hop ionospheric projection model F1 : for Chisham F-region 1/2-hop ionospheric projection model F3 : for Chisham F-region 1 1/2-hop ionospheric projection model C : Chisham projection model None : if you trust your elevation or altitude values fov_dir : Optional[str] Field of view direction ('front' or 'back'). Value in fov object will overwrite this choice. Default='front' zorder : Optional[int] The overlay order number lineColor : Optional[str] FoV contour line color. Default is 'k' for black. lineWidth : Optional[int] FoV contour line width fovColor : Optional[str] Field of view fill color fovAlpha : Optional[str] Field of view fill color transparency fovObj : Optional[fov object] See pydarn.radar.radFov.fov hemi : Optional[str] 'north' or 'south', ignore radars from the other hemisphere beams : Optional[int] hightlight specified beams beamsColors : Optional[str] colors of the hightlighted beams Returns ------- None Example ------- import pydarn, utils # Width and height give the window size in meters width = 111e3*40 m=utils.plotUtils.mapObj(width=width,height=width,lat_0=50.,lon_0=-95.) # Plot radar position and code pydarn.plot.overlayRadar(m, fontSize=12, codes='bks') # Plot radar fov pydarn.plot.overlayFov(m, codes='bks', maxGate=75, beams=[0,4,7,8,23]) written by Sebastien, 2012-09 """ from davitpy.pydarn.radar import network from davitpy.pydarn.radar.radFov import fov from datetime import datetime as dt from datetime import timedelta import matplotlib.cm as cm from numpy import transpose, ones, concatenate, vstack, shape import numpy as np from matplotlib.patches import Polygon from pylab import gca # Set dateTime. if dateTime is not None: if hasattr(mapObj, 'dateTime') and dateTime != mapObj.dateTime: logging.warning("dateTime is " + str(dateTime) + ", not mapObj.dateTime " + str(mapObj.dateTime)) else: dateTime = mapObj.dateTime # Load radar structure network_obj = network() # If all radars are to be plotted, create the list if plot_all: codes = network_obj.getAllCodes(datetime=dateTime, hemi=hemi) # Define how the radars to be plotted are identified (code, id or name) if codes: rad_input = {'meth': 'code', 'vals': codes} elif ids: rad_input = {'meth': 'id', 'vals': ids} elif names: rad_input = {'meth': 'name', 'vals': names} else: logging.error('No radars to plot') return # Check if radars is given as a list if not isinstance(rad_input['vals'], list): rad_input['vals'] = [rad_input['vals']] nradars = len(rad_input['vals']) # Initialize the line color for the field of view lcolor = lineColor # iterates through radars to be plotted for ir in xrange(nradars): # Get field of view coordinates if fovObj is None: rad = network_obj.getRadarBy(rad_input['vals'][ir], rad_input['meth']) if not rad: continue site = rad.getSiteByDate(dateTime) if not site: continue # Set number of gates to be plotted egate = site.maxgate - 1 if not maxGate else maxGate ebeam = site.maxbeam if not hasattr(mapObj, 'coords'): rad_fov = fov(site=site, ngates=egate + 1, model=model, fov_dir=fov_dir) else: rad_fov = fov(site=site, ngates=egate + 1, coords=mapObj.coords, model=model, date_time=dateTime, fov_dir=fov_dir) else: rad_fov = fovObj egate = len(fovObj.gates) ebeam = len(fovObj.beams) model = fovObj.model fov_dir = fovObj.fov_dir if rangeLimits is not None: sgate = rangeLimits[0] egate = rangeLimits[1] else: sgate = 0 if beamLimits is not None: sbeam = beamLimits[0] ebeam = beamLimits[1] else: sbeam = 0 if model == 'GS': # Ground scatter model is not defined for close in rangegates. # np.nan will be returned for these gates. # Set sGate >= to the first rangegate that has real values. not_finite = np.logical_not(np.isfinite(rad_fov.lonFull)) grid = np.tile(np.arange(rad_fov.lonFull.shape[1]), (rad_fov.lonFull.shape[0], 1)) grid[not_finite] = 999999 tmp_sGate = (np.min(grid, axis=1)).max() if tmp_sGate > sgate: sgate = tmp_sGate # Get radar coordinates in map projection if hasattr(mapObj, 'coords'): x, y = mapObj(rad_fov.lonFull, rad_fov.latFull, coords=rad_fov.coords) else: x, y = mapObj(rad_fov.lonFull, rad_fov.latFull) # Plot field of view # Create contour contour_x = concatenate((x[sbeam, sgate:egate], x[sbeam:ebeam, egate], x[ebeam, egate:sgate:-1], x[ebeam:sbeam:-1, sgate])) contour_y = concatenate((y[sbeam, sgate:egate], y[sbeam:ebeam, egate], y[ebeam, egate:sgate:-1], y[ebeam:sbeam:-1, sgate])) # Set the color if a different color has been specified for each radar if isinstance(lineColor, list) and len(lineColor) > ir: lcolor = lineColor[ir] # Plot contour mapObj.plot(contour_x, contour_y, color=lcolor, zorder=zorder, linewidth=lineWidth) # Field of view fill if fovColor: contour = transpose(vstack((contour_x, contour_y))) patch = Polygon(contour, color=fovColor, alpha=fovAlpha, zorder=zorder) mapObj.ax.add_patch(patch) # Beams fill if beams: try: [b for b in beams] except: beams = [beams] for ib in beams: if not (0 <= ib <= x.shape[0]): continue if not beamsColors: bcol_rgb = ib / float(x.shape[0]) bcol = (bcol_rgb / 2., bcol_rgb, 1) else: bcol = beamsColors[beams.index(ib)] contour_x = concatenate((x[ib, sgate:egate + 1], x[ib:ib + 2, egate], x[ib + 1, egate:sgate:-1], x[ib + 1:ib - 1:-1, sgate])) contour_y = concatenate((y[ib, sgate:egate + 1], y[ib:ib + 2, egate], y[ib + 1, egate:sgate:-1], y[ib + 1:ib - 1:-1, sgate])) contour = transpose(vstack((contour_x, contour_y))) patch = Polygon(contour, color=bcol, alpha=.4, zorder=zorder) mapObj.ax.add_patch(patch) return
def radDataOpen(sTime,radcode,eTime=None,channel=None,bmnum=None,cp=None,\ fileType='fitex',filtered=False, src=None,fileName=None, \ noCache=False,verbose=False,local_dirfmt=None, \ local_fnamefmt=None,local_dict=None,remote_dirfmt=None, \ remote_fnamefmt=None,remote_dict=None,remote_site=None, \ username=None,password=None, port=None,tmpdir=None): """A function to establish a pipeline through which we can read radar data. first it tries the mongodb, then it tries to find local files, and lastly it sftp's over to the VT data server. **Args**: * **sTime** (`datetime <http://tinyurl.com/bl352yx>`_): the beginning time for which you want data * **radcode** (str): the 3-letter radar code with optional channel extension for which you want data * **[eTime]** (`datetime <http://tinyurl.com/bl352yx>`_): the last time that you want data for. if this is set to None, it will be set to 1 day after sTime. default = None * **[channel]** (str): the 1-letter code for what channel you want data from, eg 'a','b',... if this is set to None, data from ALL channels will be read. default = None * **[bmnum]** (int): the beam number which you want data for. If this is set to None, data from all beams will be read. default = None * **[cp]** (int): the control program which you want data for. If this is set to None, data from all cp's will be read. default = None * **[fileType]** (str): The type of data you want to read. valid inputs are: 'fitex','fitacf','lmfit','rawacf','iqdat'. if you choose a fit file format and the specified one isn't found, we will search for one of the others. Beware: if you ask for rawacf/iq data, these files are large and the data transfer might take a long time. default = 'fitex' * **[filtered]** (boolean): a boolean specifying whether you want the fit data to be boxcar filtered. ONLY VALID FOR FIT. default = False * **[src]** (str): the source of the data. valid inputs are 'local' 'sftp'. if this is set to None, it will try all possibilites sequentially. default = None * **[fileName]** (str): the name of a specific file which you want to open. default=None * **[noCache]** (boolean): flag to indicate that you do not want to check first for cached files. default = False. * **[verbose]** (boolean): Be very verbose about file fetching and reading. default=False * **[remote_site]** (str): The remote data server's address. * **[port]** (str): The port number to use for remote_site. * **[username]** (str): Username for remote_site. * **[password]** (str/bool): Password for remote_site. If password is set to True, the user is prompted for the remote_site password. * **[remote_dirfmt]** (str): The remote_site directory structure. Can include keywords to be replaced by dictionary keys in remote_dict. ex) remote_dirfmt='/{year}/{month}' * **[remote_fnamefmt]** (str/list): The remote_site file naming format. Can include keywords to be replaced by dictionary keys in remote_dict. ex) remote_fnamefmt=['{date}.{radar}.{ftype}','{date}.{channel}.{radar}.{ftype}'] * **[local_dirfmt]** (str): The local directory structure. Can include keywords to be replaced by dictionary keys in remote_dict. ex) remote_dirfmt='/{year}/{month}' * **[local_fnamefmt]** (str/list): The local file naming format. Can include keywords to be replaced by dictionary keys in remote_dict. ex) remote_fnamefmt=['{date}.{radar}.{ftype}','{date}.{channel}.{radar}.{ftype}'] * **[tmpdir]** (str): The directory in which to store temporary files. **Returns**: * **myPtr** (:class:`pydarn.sdio.radDataTypes.radDataPtr`): a radDataPtr object which contains a link to the data to be read. this can then be passed to radDataReadRec in order to actually read the data. **ENVIRONMENT Variables**: * DB : Used to specify the DB address (overridden by remote_site). * DB_PORT : Used to specify the DB port (overridden by port). * DBREADUSER : Used to specify the DB user username (overridden by username). * DBREADPASS : Used to specify the DB user password (overridden by password). * DAVIT_REMOTE_DIRFORMAT : Used to specify the remote data directory structure (overridden by remote_dirfmt). * DAVIT_REMOTE_FNAMEFMT : Used to specify the remote filename format (overridden by remote_fnamefmt). * DAVIT_LOCAL_DIRFORMAT : Used to specify the local data directory structure (overridden by local_dirfmt). * DAVIT_LOCAL_FNAMEFMT : Used to specify the local filename format (overridden by local_fnamefmt). * DAVIT_TMPDIR : Directory used for davitpy temporary file cache (overridden by tmpdir). The evironment variables are python dictionary capable formatted strings appended encode radar name, channel, and/or date information. Currently supported dictionary keys which can be used are: "date" : datetime.datetime.strftime("%Y%m%d") "year" : 0 padded 4 digit year "month" : 0 padded 2 digit month "day" : 0 padded 2 digit day "hour" : 0 padded 2 digit day "ftype" : filetype string "radar" : 3-chr radarcode "channel" : single character string, ex) 'a' **Example**: :: import datetime as dt myPtr = pydarn.sdio.radDataOpen(dt.datetime(2011,1,1),'bks',eTime=dt.datetime(2011,1,1,2),channel=None, bmnum=7,cp=153,fileType='fitex',filtered=False, src=None): Written by AJ 20130110 """ from davitpy.pydarn.sdio import radDataPtr from davitpy.pydarn.radar import network myPtr = radDataPtr(sTime=sTime,radcode=radcode,eTime=eTime, \ channel=channel,bmnum=bmnum,cp=cp,fileType=fileType, \ filtered=filtered,src=src,fileName=fileName, \ noCache=noCache,verbose=verbose,local_dirfmt=local_dirfmt,\ local_fnamefmt=local_fnamefmt,local_dict=local_dict, \ remote_dirfmt=remote_dirfmt,remote_dict=remote_dict, \ remote_fnamefmt=remote_fnamefmt,remote_site=remote_site, \ username=username,port=port,password=password, \ stid=int(network().getRadarByCode(radcode).id), \ tmpdir=tmpdir) return myPtr
def overlayRadar(mapObj, codes=None, ids=None, names=None, dateTime=None, annotate=True, plot_all=False, hemi=None, zorder=2, markerColor='k', markerSize=10, fontSize=10, font_color='k', xOffset=None, yOffset=-5): """Overlay radar position(s) and name(s) on map Parameters ---------- mapObj : mapObj class object or Basemap map object codes : Optional[list] Radar 3-letter codes to plot ids : Optional[list] Radar IDs to plot names : Optional[list] Radar names to plot dateTime : Optional[datetime.datetime] Datetime object to use for the radar. Default: uses mapObj.dateTime annotate : Optional[boolean] Flag to show whether or not to show the radar(s) name(s) plot_all : Optional[boolean] Set to true to plot all the radars (active ones) hemi : Optional[str] 'north', 'south', or None. If a hemisphere is specified, limits radar calls to that hemisphere. Default: None zorder : Optional[int] The overlay order number. Default: 2 markerColor : Optional[str] Default: 'k' (black) markerSize : Optional[int] [point] Default: 10 fontSize : Optional[int] [point] Default: 10 xOffset : Optional[int] x-Offset of the annotation in points. Default: None yOffset : Optional[int] y-Offset of the annotation in points. Default: -5 Returns ------- None Example ------- import pydarn import utils m1 = utils.plotUtils.mapObj(boundinglat=30., gridLabels=True, \ coords='mag') pydarn.plot.overlayRadar(m1, fontSize=8, plot_all=True, markerSize=5) written by Sebastien, 2012-08 """ from davitpy.pydarn.radar import network from datetime import datetime as dt from datetime import timedelta from davitpy.utils.plotUtils import textHighlighted # List paired radars. Each member of a pair is placed in a different # sublist, with the more westward member in the first sublist nearby_rad = [['adw', 'kod', 'cve', 'fhe', 'wal', 'gbr', 'pyk', 'aze', 'sys'], ['ade', 'ksr', 'cvw', 'fhw', 'bks', 'sch', 'sto', 'azw', 'sye']] # Set dateTime. if dateTime is not None: if hasattr(mapObj, 'dateTime') and dateTime != mapObj.dateTime: estr = 'dateTime is {:}'.format(dateTime) estr += ' not mapObj.dateTime {:}'.format(mapObj.dateTime) logging.warning(estr) else: dateTime = mapObj.dateTime # Load radar structure NetworkObj = network() # If all radars are to be plotted, create the list if plot_all: codes = NetworkObj.getAllCodes(datetime=dateTime, hemi=hemi) # Define how the radars to be plotted are identified (code, id or name) if codes: rad_input = {'meth': 'code', 'vals': codes} elif ids: rad_input = {'meth': 'id', 'vals': ids} elif names: rad_input = {'meth': 'name', 'vals': names} else: logging.error('No radars to plot') return # Check if radars is given as a list if not isinstance(rad_input['vals'], list): rad_input['vals'] = [rad_input['vals']] # Check if the radar text colors were given as a list if isinstance(font_color, list): rad_input['fcolor'] = font_color else: rad_input['fcolor'] = [font_color for i in rad_input['vals']] # Check if the radar marker colors were given as a list if isinstance(markerColor, list): rad_input['mcolor'] = markerColor else: rad_input['mcolor'] = [markerColor for i in rad_input['vals']] # Map width and height width = mapObj.urcrnrx - mapObj.llcrnrx height = mapObj.urcrnry - mapObj.llcrnry if hemi is None: hemiInt = 0 else: hemiInt = 1 if hemi.lower()[0] == 'n' else -1 # iterates through radars to be plotted for ir, radN in enumerate(rad_input['vals']): rad = NetworkObj.getRadarBy(radN, rad_input['meth']) if not rad: continue site = rad.getSiteByDate(dateTime) if not site: continue # Check for hemisphere specification if site.geolat * hemiInt < 0: continue # Get radar coordinates in map projection if not hasattr(mapObj, 'coords'): x, y = mapObj(site.geolon, site.geolat) else: x, y = mapObj(site.geolon, site.geolat, coords='geo') if not mapObj.xmin <= x <= mapObj.xmax: continue if not mapObj.ymin <= y <= mapObj.ymax: continue # Plot radar position mapObj.scatter(x, y, s=markerSize, marker='o', color=rad_input['mcolor'][ir], zorder=zorder) # Now add radar name if annotate: # If any of the other radar is too close... if rad.code[0] in nearby_rad[0]: xOff = 5 if not xOffset else xOffset ha = 0 elif rad.code[0] in nearby_rad[1]: xOff = -5 if not xOffset else xOffset ha = 1 else: xOff = 0.0 ha = .5 # Plot radar name textHighlighted((x, y), rad.code[0].upper(), ax=mapObj.ax, xytext=(xOff, yOffset), text_alignment=(ha, 1), variant='small-caps', fontsize=fontSize, zorder=zorder, color=rad_input['fcolor'][ir]) return
def radDataOpen(sTime, radcode, eTime=None, channel=None, bmnum=None, cp=None, fileType='fitex', filtered=False, src=None, fileName=None, noCache=False, local_dirfmt=None, local_fnamefmt=None, local_dict=None, remote_dirfmt=None, remote_fnamefmt=None, remote_dict=None, remote_site=None, username=None, password=None, port=None, tmpdir=None, remove=False, try_file_types=True): """A function to establish a pipeline through which we can read radar data. first it tries the mongodb, then it tries to find local files, and lastly it sftp's over to the VT data server. Parameters ----------- sTime : (datetime) The beginning time for which you want data radcode : (str) The 3-letter radar code with optional channel extension for which you want data eTime : (datetime/NoneType) The last time that you want data for. If this is set to None, it will be set to 1 day after sTime. (default=None) channel : (str/NoneType) The 1-letter code for what channel you want data from, eg 'a','b',... if this is set to None, data from ALL channels will be read. (default=None) bmnum : (int/NoneType) The beam number which you want data for. If this is set to None, data from all beams will be read. (default=None) cp : (int) The control program which you want data for. If this is set to None, data from all cp's will be read. (default=None) fileType : (str) The type of data you want to read. valid inputs are: 'fitex','fitacf', 'lmfit','rawacf','iqdat'. If you choose a fit file format and the specified one isn't found, we will search for one of the others. Beware: if you ask for rawacf/iq data, these files are large and the data transfer might take a long time. (default='fitex') filtered : (boolean) A boolean specifying whether you want the fit data to be boxcar filtered. ONLY VALID FOR FIT. (default=False) src : (str/NoneType) The source of the data. Valid inputs are 'local' 'sftp'. If this is set to None, it will try all possibilites sequentially. (default=None) fileName : (str/NoneType) The name of a specific file which you want to open. (default=None) noCache : (boolean) Flag to indicate that you do not want to check first for cached files. (default=False) remote_site : (str/NoneType) The remote data server's address. If None, the rcParam value DB will be used. (default=None) port : (str/NoneType) The port number to use for remote_site. If None, the rcParam value DB_PORT will be used. (default=None) username : (str/NoneType) Username for remote_site. If None, the rcParam value DBREADUSER will be used. (default=None) password : (str/bool/NoneType) Password for remote_site. If password is set to True, the user is prompted for the remote_site password. If set to None, the rcParam value DBREADPASS will be used (default=None) remote_dirfmt : (str/NoneType) The remote_site directory structure. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_REMOTE_DIRFORMAT will be used. (default=None) Ex) remote_dirfmt='/{year}/{month}' remote_fnamefmt : (str/list/NoneType) The remote_site file naming format. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_REMOTE_FNAMEFMT will be used. (default=None) Ex) remote_fnamefmt=['{date}.{radar}.{ftype}', '{date}.{channel}.{radar}.{ftype}'] local_dirfmt : (str/None) The local directory structure. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_LOCAL_DIRFORMAT will be used. (default=None) Ex) local_dirfmt='/{year}/{month}' local_fnamefmt : (str/list/NoneType) The local file naming format. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_LOCAL_FNAMEFMT will be used. (default=None) Ex) local_fnamefmt=['{date}.{radar}.{ftype}', '{date}.{channel}.{radar}.{ftype}'] tmpdir : (str/NoneType) The directory in which to store temporary files. If None, the rcParam value DAVIT_TMPDIR will be used. (default=None) remove : (bool) Remove compressed file after uncompression (default=False) try_file_types : (bool) If desired file type could not be found, try to download others (default=True) Returns -------- myPtr : (pydarn.sdio.radDataTypes.radDataPtr) A radDataPtr object which contains a link to the data to be read. This can then be passed to radDataReadRec in order to actually read the data. Notes ------- The evironment variables are python dictionary capable formatted strings appended encode radar name, channel, and/or date information. Currently supported dictionary keys which can be used are: "date" : datetime.datetime.strftime("%Y%m%d") "year" : 0 padded 4 digit year "month" : 0 padded 2 digit month "day" : 0 padded 2 digit day "hour" : 0 padded 2 digit day "ftype" : filetype string "radar" : 3-chr radarcode "channel" : single character string, ex) 'a' Example ---------- :: import datetime as dt myPtr = pydarn.sdio.radDataOpen(dt.datetime(2011,1,1),'bks', \ eTime=dt.datetime(2011,1,1,2),channel=None, bmnum=7,cp=153, \ fileType='fitex',filtered=False, src=None) Written by AJ 20130110 """ from davitpy.pydarn.sdio import radDataPtr from davitpy.pydarn.radar import network myPtr = radDataPtr(sTime=sTime, radcode=radcode, eTime=eTime, channel=channel, bmnum=bmnum, cp=cp, fileType=fileType, filtered=filtered, src=src, fileName=fileName, noCache=noCache, local_dirfmt=local_dirfmt, local_fnamefmt=local_fnamefmt, local_dict=local_dict, remote_dirfmt=remote_dirfmt, remote_dict=remote_dict, remote_fnamefmt=remote_fnamefmt, remote_site=remote_site, username=username, port=port, password=password, stid=int(network().getRadarByCode(radcode).id), tmpdir=tmpdir, remove=remove, try_file_types=try_file_types) return myPtr
def overlayFov(mapObj, codes=None, ids=None, names=None, dateTime=None, plot_all=False, maxGate=None, rangeLimits=None, beamLimits=None, model='IS', fov_dir='front', fovColor=None, fovAlpha=0.2, beams=None, beamsColors=None, hemi=None, fovObj=None, zorder=2, lineColor='k', lineWidth=1): """ Overlay FoV position(s) on map Parameters ---------- mapObj : mapObj or Basemap object Object on which to overplot the radar position(s) codes : Optional[list] List of radar 3-letter codes to plot ids : Optional[list] List of radar IDs to plot names : Optional[list] List of radar names to plot dateTime : Optional[datetime.datetime] Object to use for the FOV. Default: uses mapObj.dateTime plot_all : Optional[boolean] Set to true to plot all the radars (active ones) maxGate : Optional[int] Maximum number of gates to be plotted. Defaults to hdw.dat information. rangeLimits : Optional[list, int] Plot only between the range gates specified. beamLimits : Optional[2-element list] Plot only between the beams specified. model : Optional[str] 'IS for ionopsheric scatter projection model (default), 'GS' for ground scatter projection model, None if you are really confident in your elevation or altitude values fov_dir : Optional[str] Field of view direction ('front' or 'back'). Default='front' zorder : Optional[int] The overlay order number lineColor : Optional[str] FoV contour line color. Default is 'k' for black. lineWidth : Optional[int] FoV contour line width fovColor : Optional[str] Field of view fill color fovAlpha : Optional[str] Field of view fill color transparency fovObj : Optional[fov object] See pydarn.radar.radFov.fov hemi : Optional[str] 'north' or 'south', ignore radars from the other hemisphere beams : Optional[int] hightlight specified beams beamsColors : Optional[str] colors of the hightlighted beams Returns ------- None Example ------- import pydarn, utils # Width and height give the window size in meters width = 111e3*40 m=utils.plotUtils.mapObj(width=width,height=width,lat_0=50.,lon_0=-95.) # Plot radar position and code pydarn.plot.overlayRadar(m, fontSize=12, codes='bks') # Plot radar fov pydarn.plot.overlayFov(m, codes='bks', maxGate=75, beams=[0,4,7,8,23]) written by Sebastien, 2012-09 """ from davitpy.pydarn.radar import network from davitpy.pydarn.radar.radFov import fov from datetime import datetime as dt from datetime import timedelta import matplotlib.cm as cm from numpy import transpose, ones, concatenate, vstack, shape import numpy as np from matplotlib.patches import Polygon from pylab import gca # Set dateTime. if dateTime is not None: if hasattr(mapObj, 'dateTime') and dateTime != mapObj.dateTime: logging.warning("dateTime is " + str(dateTime) + \ ", not mapObj.dateTime " + str(mapObj.dateTime)) else: dateTime = mapObj.dateTime # Load radar structure network_obj = network() # If all radars are to be plotted, create the list if plot_all: codes = network_obj.getAllCodes(datetime=dateTime, hemi=hemi) # Define how the radars to be plotted are identified (code, id or name) if codes: rad_input = {'meth': 'code', 'vals': codes} elif ids: rad_input = {'meth': 'id', 'vals': ids} elif names: rad_input = {'meth': 'name', 'vals': names} else: logging.error('No radars to plot') return # Check if radars is given as a list if not isinstance(rad_input['vals'], list): rad_input['vals'] = [rad_input['vals']] nradars = len(rad_input['vals']) # Initialize the line color for the field of view lcolor = lineColor # iterates through radars to be plotted for ir in xrange(nradars): # Get field of view coordinates if(fovObj is None): rad = network_obj.getRadarBy(rad_input['vals'][ir], rad_input['meth']) if not rad: continue site = rad.getSiteByDate(dateTime) if not site: continue # Set number of gates to be plotted egate = site.maxgate-1 if not maxGate else maxGate ebeam = site.maxbeam if not hasattr(mapObj, 'coords'): rad_fov = fov(site=site, ngates=egate+1, model=model, fov_dir=fov_dir) else: rad_fov = fov(site=site, ngates=egate+1, coords=mapObj.coords, model=model, date_time=dateTime, fov_dir=fov_dir) else: rad_fov = fovObj egate = len(fovObj.gates) ebeam = len(fovObj.beams) if rangeLimits is not None: sgate = rangeLimits[0] egate = rangeLimits[1] else: sgate = 0 if beamLimits is not None: sbeam = beamLimits[0] ebeam = beamLimits[1] else: sbeam = 0 if model == 'GS': # Ground scatter model is not defined for close in rangegates. # np.nan will be returned for these gates. # Set sGate >= to the first rangegate that has real values. not_finite = np.logical_not(np.isfinite(rad_fov.lonFull)) grid = np.tile(np.arange(rad_fov.lonFull.shape[1]), (rad_fov.lonFull.shape[0],1)) grid[not_finite] = 999999 tmp_sGate = (np.min(grid,axis=1)).max() if tmp_sGate > sgate: sgate = tmp_sGate # Get radar coordinates in map projection if hasattr(mapObj, 'coords'): x, y = mapObj(rad_fov.lonFull, rad_fov.latFull, coords=rad_fov.coords) else: x, y = mapObj(rad_fov.lonFull, rad_fov.latFull) # Plot field of view # Create contour contour_x = concatenate((x[sbeam,sgate:egate], x[sbeam:ebeam,egate], x[ebeam,egate:sgate:-1], x[ebeam:sbeam:-1,sgate])) contour_y = concatenate((y[sbeam,sgate:egate], y[sbeam:ebeam,egate], y[ebeam,egate:sgate:-1], y[ebeam:sbeam:-1,sgate])) # Set the color if a different color has been specified for each radar if isinstance(lineColor, list) and len(lineColor) > ir: lcolor=lineColor[ir] # Plot contour mapObj.plot(contour_x, contour_y, color=lcolor, zorder=zorder, linewidth=lineWidth) # Field of view fill if fovColor: contour = transpose(vstack((contour_x,contour_y))) patch = Polygon(contour, color=fovColor, alpha=fovAlpha, zorder=zorder) mapObj.ax.add_patch(patch) # Beams fill if beams: try: [b for b in beams] except: beams = [beams] for ib in beams: if not (0 <= ib <= x.shape[0]): continue if not beamsColors: bcol_rgb = ib/float(x.shape[0]) bcol = (bcol_rgb/2., bcol_rgb, 1) else: bcol = beamsColors[beams.index(ib)] contour_x = concatenate((x[ib,sgate:egate+1], x[ib:ib+2,egate], x[ib+1,egate:sgate:-1], x[ib+1:ib-1:-1,sgate])) contour_y = concatenate((y[ib,sgate:egate+1], y[ib:ib+2,egate], y[ib+1,egate:sgate:-1], y[ib+1:ib-1:-1,sgate])) contour = transpose(vstack((contour_x, contour_y))) patch = Polygon(contour, color=bcol, alpha=.4, zorder=zorder) mapObj.ax.add_patch(patch) return
def overlayRadar(mapObj, codes=None, ids=None, names=None, dateTime=None, annotate=True, plot_all=False, hemi=None, zorder=2, markerColor='k', markerSize=10, fontSize=10, font_color='k', xOffset=None,yOffset=-5): """Overlay radar position(s) and name(s) on map Parameters ---------- mapObj : mapObj class object or Basemap map object codes : Optional[list] Radar 3-letter codes to plot ids : Optional[list] Radar IDs to plot names : Optional[list] Radar names to plot dateTime : Optional[datetime.datetime] Datetime object to use for the radar. Default: uses mapObj.dateTime annotate : Optional[boolean] Flag to show whether or not to show the radar(s) name(s) plot_all : Optional[boolean] Set to true to plot all the radars (active ones) hemi : Optional[str] 'north', 'south', or None. If a hemisphere is specified, limits radar calls to that hemisphere. Default: None zorder : Optional[int] The overlay order number. Default: 2 markerColor : Optional[str] Default: 'k' (black) markerSize : Optional[int] [point] Default: 10 fontSize : Optional[int] [point] Default: 10 xOffset : Optional[int] x-Offset of the annotation in points. Default: None yOffset : Optional[int] y-Offset of the annotation in points. Default: -5 Returns ------- None Example ------- import pydarn import utils m1 = utils.plotUtils.mapObj(boundinglat=30., gridLabels=True, \ coords='mag') pydarn.plot.overlayRadar(m1, fontSize=8, plot_all=True, markerSize=5) written by Sebastien, 2012-08 """ from davitpy.pydarn.radar import network from datetime import datetime as dt from datetime import timedelta from davitpy.utils.plotUtils import textHighlighted # List paired radars. Each member of a pair is placed in a different # sublist, with the more westward member in the first sublist nearby_rad = [['adw','kod','cve','fhe','wal','gbr','pyk','aze','sys'], ['ade','ksr','cvw','fhw','bks','sch','sto','azw','sye']] # Set dateTime. if dateTime is not None: if hasattr(mapObj, 'dateTime') and dateTime != mapObj.dateTime: estr = 'dateTime is {:}'.format(dateTime) estr += ' not mapObj.dateTime {:}'.format(mapObj.dateTime) logging.warning(estr) else: dateTime = mapObj.dateTime # Load radar structure NetworkObj = network() # If all radars are to be plotted, create the list if plot_all: codes = NetworkObj.getAllCodes(datetime=dateTime, hemi=hemi) # Define how the radars to be plotted are identified (code, id or name) if codes: rad_input = {'meth': 'code', 'vals': codes} elif ids: rad_input = {'meth': 'id', 'vals': ids} elif names: rad_input = {'meth': 'name', 'vals': names} else: logging.error('No radars to plot') return # Check if radars is given as a list if not isinstance(rad_input['vals'], list): rad_input['vals'] = [rad_input['vals']] # Check if the radar text colors were given as a list if isinstance(font_color, list): rad_input['fcolor'] = font_color else: rad_input['fcolor'] = [font_color for i in rad_input['vals']] # Check if the radar marker colors were given as a list if isinstance(markerColor, list): rad_input['mcolor'] = markerColor else: rad_input['mcolor'] = [markerColor for i in rad_input['vals']] # Map width and height width = mapObj.urcrnrx - mapObj.llcrnrx height = mapObj.urcrnry - mapObj.llcrnry if hemi is None: hemiInt = 0 else: hemiInt = 1 if hemi.lower()[0]=='n' else -1 # iterates through radars to be plotted for ir,radN in enumerate(rad_input['vals']): rad = NetworkObj.getRadarBy(radN, rad_input['meth']) if not rad: continue site = rad.getSiteByDate(dateTime) if not site: continue # Check for hemisphere specification if site.geolat*hemiInt < 0: continue # Get radar coordinates in map projection if not hasattr(mapObj, 'coords'): x,y = mapObj(site.geolon, site.geolat) else: x,y = mapObj(site.geolon, site.geolat, coords='geo') if not mapObj.xmin <= x <= mapObj.xmax: continue if not mapObj.ymin <= y <= mapObj.ymax: continue # Plot radar position mapObj.scatter(x, y, s=markerSize, marker='o', color=rad_input['mcolor'][ir], zorder=zorder) # Now add radar name if annotate: # If any of the other radar is too close... if rad.code[0] in nearby_rad[0]: xOff = 5 if not xOffset else xOffset ha = 0 elif rad.code[0] in nearby_rad[1]: xOff = -5 if not xOffset else xOffset ha = 1 else: xOff = 0.0 ha = .5 # Plot radar name textHighlighted((x, y), rad.code[0].upper(), ax=mapObj.ax, xytext=(xOff, yOffset), text_alignment=(ha,1), variant='small-caps', fontsize=fontSize, zorder=zorder, color=rad_input['fcolor'][ir]) return
def radDataOpen(sTime, radcode, eTime=None, channel=None, bmnum=None, cp=None, fileType='fitex', filtered=False, src=None, fileName=None, noCache=False, local_dirfmt=None, local_fnamefmt=None, local_dict=None, remote_dirfmt=None, remote_fnamefmt=None, remote_dict=None, remote_site=None, username=None, password=None, port=None, tmpdir=None, remove=False, try_file_types=True): """A function to establish a pipeline through which we can read radar data. first it tries the mongodb, then it tries to find local files, and lastly it sftp's over to the VT data server. Parameters ----------- sTime : (datetime) The beginning time for which you want data radcode : (str) The 3-letter radar code with optional channel extension for which you want data eTime : (datetime/NoneType) The last time that you want data for. If this is set to None, it will be set to 1 day after sTime. (default=None) channel : (str/NoneType) The 1-letter code for what channel you want data from, eg 'a','b',... if this is set to None, data from ALL channels will be read. (default=None) bmnum : (int/NoneType) The beam number which you want data for. If this is set to None, data from all beams will be read. (default=None) cp : (int) The control program which you want data for. If this is set to None, data from all cp's will be read. (default=None) fileType : (str) The type of data you want to read. valid inputs are: 'fitex','fitacf', 'fitacf3','lmfit','rawacf','iqdat'. If you choose a fit file format and the specified one isn't found, we will search for one of the others. Beware: if you ask for rawacf/iq data, these files are large and the data transfer might take a long time. (default='fitex') filtered : (boolean) A boolean specifying whether you want the fit data to be boxcar filtered. ONLY VALID FOR FIT. (default=False) src : (str/NoneType) The source of the data. Valid inputs are 'local' 'sftp'. If this is set to None, it will try all possibilites sequentially. (default=None) fileName : (str/NoneType) The name of a specific file which you want to open. (default=None) noCache : (boolean) Flag to indicate that you do not want to check first for cached files. (default=False) remote_site : (str/NoneType) The remote data server's address. If None, the rcParam value DB will be used. (default=None) port : (str/NoneType) The port number to use for remote_site. If None, the rcParam value DB_PORT will be used. (default=None) username : (str/NoneType) Username for remote_site. If None, the rcParam value DBREADUSER will be used. (default=None) password : (str/bool/NoneType) Password for remote_site. If password is set to True, the user is prompted for the remote_site password. If set to None, the rcParam value DBREADPASS will be used (default=None) remote_dirfmt : (str/NoneType) The remote_site directory structure. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_REMOTE_DIRFORMAT will be used. (default=None) Ex) remote_dirfmt='/{year}/{month}' remote_fnamefmt : (str/list/NoneType) The remote_site file naming format. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_REMOTE_FNAMEFMT will be used. (default=None) Ex) remote_fnamefmt=['{date}.{radar}.{ftype}', '{date}.{channel}.{radar}.{ftype}'] local_dirfmt : (str/None) The local directory structure. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_LOCAL_DIRFORMAT will be used. (default=None) Ex) local_dirfmt='/{year}/{month}' local_fnamefmt : (str/list/NoneType) The local file naming format. Can include keywords to be replaced by dictionary keys in remote_dict. If None, the rcParam value DAVIT_LOCAL_FNAMEFMT will be used. (default=None) Ex) local_fnamefmt=['{date}.{radar}.{ftype}', '{date}.{channel}.{radar}.{ftype}'] tmpdir : (str/NoneType) The directory in which to store temporary files. If None, the rcParam value DAVIT_TMPDIR will be used. (default=None) remove : (bool) Remove compressed file after uncompression (default=False) try_file_types : (bool) If desired file type could not be found, try to download others (default=True) Returns -------- myPtr : (pydarn.sdio.radDataTypes.radDataPtr) A radDataPtr object which contains a link to the data to be read. This can then be passed to radDataReadRec in order to actually read the data. Notes ------- The evironment variables are python dictionary capable formatted strings appended encode radar name, channel, and/or date information. Currently supported dictionary keys which can be used are: "date" : datetime.datetime.strftime("%Y%m%d") "year" : 0 padded 4 digit year "month" : 0 padded 2 digit month "day" : 0 padded 2 digit day "hour" : 0 padded 2 digit day "ftype" : filetype string "radar" : 3-chr radarcode "channel" : single character string, ex) 'a' Example ---------- :: import datetime as dt myPtr = pydarn.sdio.radDataOpen(dt.datetime(2011,1,1),'bks', \ eTime=dt.datetime(2011,1,1,2),channel=None, bmnum=7,cp=153, \ fileType='fitex',filtered=False, src=None) Written by AJ 20130110 """ from davitpy.pydarn.sdio import radDataPtr from davitpy.pydarn.radar import network myPtr = radDataPtr(sTime=sTime, radcode=radcode, eTime=eTime, channel=channel, bmnum=bmnum, cp=cp, fileType=fileType, filtered=filtered, src=src, fileName=fileName, noCache=noCache, local_dirfmt=local_dirfmt, local_fnamefmt=local_fnamefmt, local_dict=local_dict, remote_dirfmt=remote_dirfmt, remote_dict=remote_dict, remote_fnamefmt=remote_fnamefmt, remote_site=remote_site, username=username, port=port, password=password, stid=int(network().getRadarByCode(radcode).id), tmpdir=tmpdir, remove=remove, try_file_types=try_file_types) return myPtr