<commit_before>#!/usr/bin/env python
"""
Created on Wed Dec 30 16:20:38 2015

@author: <NAME>
"""

import os, glob
import scipy as sp
import matplotlib
import pdb
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from RadarDataSim.IonoContainer import IonoContainer
from GeoData.GeoData import GeoData
from GeoData.utilityfuncs import readIono
from GeoData.plotting import insertinfo


#%% For sorting
def ke(item):
    if item[0].isdigit():
        return int(item.partition(' ')[0])
    else:
        return float('inf')
#%% Plot input data
def plotinputdata(testdir,imgdir):
    """This will plot all of the input data with each time step as a pcolor images of
    electron density and ion tempreture.
    Inputs
    testdir - The directory with the input data in h5 files formated for the ionocontainer structure.
    imgdir - The directory that holds the images."""

    if os.path.exists(imgdir):
        imgfiles = glob.glob(os.path.join(imgdir,'*.png'))
        for imgf in imgfiles:
            os.remove(imgf)
    else:
        os.mkdir(imgdir)

    filelist = glob.glob(os.path.join(testdir,'Origparams','*.h5'))
    numlist = [os.path.splitext(os.path.split(x)[-1])[0] for x in filelist]
    numdict = {numlist[i]:filelist[i] for i in range(len(filelist))}
    slist = sorted(numlist,key=ke)
    slist=[slist[0]]
    imcount = 0
    filetemplate = 'outputdata'
    dsetname = os.path.split(os.path.dirname(testdir))[-1]
    print "Plotting input data for "+dsetname

    if 'perryplane' in testdir.lower():
        xlim = [-100.,600.]
    else:
        xlim = [0.,350.]
    ylim = [125.,475]
    for inumn, inum in enumerate(slist):
        print "{0} Input for {1} of {2}".format(dsetname,inumn,len(slist))
        ifile = numdict[inum]
        iono = IonoContainer.readh5(ifile)
        Iono1 = GeoData(readIono,[iono])
        nt = Iono1.times.shape[0]
        rng = sp.sqrt(Iono1.dataloc[:,0]**2+Iono1.dataloc[:,1]**2)*sp.sign(Iono1.dataloc[:,1])
        z = Iono1.dataloc[:,2]
        rngvec = sp.unique(rng)
        zvec = sp.unique(z)
        rngmat = rng.reshape(len(zvec),len(rngvec))
        zmat = z.reshape(len(zvec),len(rngvec))
        Ne = Iono1.data['Ne'].reshape(len(zvec),len(rngvec),nt)
        Ti = Iono1.data['Ti'].reshape(len(zvec),len(rngvec),nt)
        Te = Iono1.data['Te'].reshape(len(zvec),len(rngvec),nt)
        for itimen,itime in enumerate(Iono1.times):
            fig ,axmat= plt.subplots(nrows=1,ncols=3,facecolor='w',figsize=(15,7 ),sharey=True)
            avec = axmat.flatten()


            avec[0].set_xlabel('Range in km')
            avec[0].set_ylabel('Alt in km')
            pc1 = avec[0].pcolor(rngmat,zmat,Ne[:,:,itimen],cmap = 'plasma')
            avec[0].set_xlim(xlim)
            avec[0].set_ylim(ylim)
            avec[0].set_title('Electron Density')
            
            pc1.set_norm(colors.LogNorm(vmin=1e8,vmax=5e11))
            cb1 = plt.colorbar(pc1, ax=avec[0],format='%.0e')
            
            avec[1].set_xlabel('Range in km')
            pc2 = avec[1].pcolor(rngmat,zmat,Te[:,:,itimen],cmap = 'plasma',vmin=500,vmax=3e3)
            avec[1].set_xlim(xlim)
            avec[1].set_ylim(ylim)
            avec[1].set_title('Electron Tempreture')

            cb2 = plt.colorbar(pc2, ax=avec[1],format='%.0d')
            
            avec[2].set_xlabel('Range in km')
            pc3 = avec[2].pcolor(rngmat,zmat,Ti[:,:,itimen],cmap = 'plasma',vmin=500,vmax=3e3)
            avec[2].set_xlim(xlim)
            avec[2].set_ylim(ylim)
            avec[2].set_title('Ion Tempreture')
            
            cb3 = plt.colorbar(pc3, ax=avec[2],format='%.0d')
#            ax2=fig.add_subplot(1,2,2)
#            ax2.set_title('Ti')
#            ax2.set_xlabel('Range in km')
#            ax2.set_ylabel('Alt in km')
#            pc2 = ax2.pcolor(rngmat,zmat,Ti[:,:,itimen],cmap = 'jet',vmin=3000,vmax=6000)

#            ax2.set_ylim([zmat.min(),zmat.max()])

#            cb2 = plt.colorbar(pc2, ax=ax2,format='%.0e')
            plt.tight_layout()
            plt.subplots_adjust(top=0.85)
            spti = fig.suptitle('Parameters at {0} seconds'.format(int(itime[0])),fontsize=24)
            fname= '{0:0>3}_'.format(imcount)+filetemplate+'.png'
            plt.savefig(os.path.join(imgdir,fname))
            imcount=imcount+1
            plt.close(fig)
#%%Plot output data
def plotoutput(testdir,imgdir):
    """This will plot all of the fitted data with each time step as a pcolor images of
    electron density and electron density from power mesurements.
    Inputs
    testdir - The directory with the input data in h5 files formated for the ionocontainer structure.
    imgdir - The directory that holds the images."""<commit_msg>Updated input data plotting for higher dpi<commit_after>#!/usr/bin/env python
"""
Created on Wed Dec 30 16:20:38 2015

@author: <NAME>
"""

import os, glob
import scipy as sp
import matplotlib
import pdb
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from RadarDataSim.IonoContainer import IonoContainer
from GeoData.GeoData import GeoData
from GeoData.utilityfuncs import readIono
from GeoData.plotting import insertinfo


#%% For sorting
def ke(item):
    if item[0].isdigit():
        return int(item.partition(' ')[0])
    else:
        return float('inf')
#%% Plot input data
def plotinputdata(testdir,imgdir):
    """This will plot all of the input data with each time step as a pcolor images of
    electron density and ion tempreture.
    Inputs
    testdir - The directory with the input data in h5 files formated for the ionocontainer structure.
    imgdir - The directory that holds the images."""

    if os.path.exists(imgdir):
        imgfiles = glob.glob(os.path.join(imgdir,'*.png'))
        for imgf in imgfiles:
            os.remove(imgf)
    else:
        os.mkdir(imgdir)

    filelist = glob.glob(os.path.join(testdir,'Origparams','*.h5'))
    numlist = [os.path.splitext(os.path.split(x)[-1])[0] for x in filelist]
    numdict = {numlist[i]:filelist[i] for i in range(len(filelist))}
    slist = sorted(numlist,key=ke)
    slist=[slist[0]]
    imcount = 0
    filetemplate = 'outputdata'
    dsetname = os.path.split(os.path.dirname(testdir))[-1]
    print "Plotting input data for "+dsetname

    if 'perryplane' in testdir.lower():
        xlim = [-100.,600.]
    else:
        xlim = [0.,350.]
    ylim = [125.,475]
    for inumn, inum in enumerate(slist):
        print "{0} Input for {1} of {2}".format(dsetname,inumn,len(slist))
        ifile = numdict[inum]
        iono = IonoContainer.readh5(ifile)
        Iono1 = GeoData(readIono,[iono])
        nt = Iono1.times.shape[0]
        rng = sp.sqrt(Iono1.dataloc[:,0]**2+Iono1.dataloc[:,1]**2)*sp.sign(Iono1.dataloc[:,1])
        z = Iono1.dataloc[:,2]
        rngvec = sp.unique(rng)
        zvec = sp.unique(z)
        rngmat = rng.reshape(len(zvec),len(rngvec))
        zmat = z.reshape(len(zvec),len(rngvec))
        Ne = Iono1.data['Ne'].reshape(len(zvec),len(rngvec),nt)
        Ti = Iono1.data['Ti'].reshape(len(zvec),len(rngvec),nt)
        Te = Iono1.data['Te'].reshape(len(zvec),len(rngvec),nt)
        for itimen,itime in enumerate(Iono1.times):
            fig ,axmat= plt.subplots(nrows=1,ncols=3,facecolor='w',figsize=(15,7 ),sharey=True)
            avec = axmat.flatten()


            avec[0].set_xlabel('Range in km')
            avec[0].set_ylabel('Alt in km')
            pc1 = avec[0].pcolor(rngmat,zmat,Ne[:,:,itimen],cmap = 'plasma')
            avec[0].set_xlim(xlim)
            avec[0].set_ylim(ylim)
            avec[0].set_title('Electron Density')
            
            pc1.set_norm(colors.LogNorm(vmin=1e8,vmax=5e11))
            cb1 = plt.colorbar(pc1, ax=avec[0],format='%.0e')
            
            avec[1].set_xlabel('Range in km')
            pc2 = avec[1].pcolor(rngmat,zmat,Te[:,:,itimen],cmap = 'plasma',vmin=500,vmax=3e3)
            avec[1].set_xlim(xlim)
            avec[1].set_ylim(ylim)
            avec[1].set_title('Electron Tempreture')

            cb2 = plt.colorbar(pc2, ax=avec[1],format='%.0d')
            
            avec[2].set_xlabel('Range in km')
            pc3 = avec[2].pcolor(rngmat,zmat,Ti[:,:,itimen],cmap = 'plasma',vmin=500,vmax=3e3)
            avec[2].set_xlim(xlim)
            avec[2].set_ylim(ylim)
            avec[2].set_title('Ion Tempreture')
            
            cb3 = plt.colorbar(pc3, ax=avec[2],format='%.0d')
#            ax2=fig.add_subplot(1,2,2)
#            ax2.set_title('Ti')
#            ax2.set_xlabel('Range in km')
#            ax2.set_ylabel('Alt in km')
#            pc2 = ax2.pcolor(rngmat,zmat,Ti[:,:,itimen],cmap = 'jet',vmin=3000,vmax=6000)

#            ax2.set_ylim([zmat.min(),zmat.max()])

#            cb2 = plt.colorbar(pc2, ax=ax2,format='%.0e')
            plt.tight_layout()
            plt.subplots_adjust(top=0.85)
            spti = fig.suptitle('Parameters at {0} seconds'.format(int(itime[0])),fontsize=24)
            fname= '{0:0>3}_'.format(imcount)+filetemplate+'.png'
            plt.savefig(os.path.join(imgdir,fname),dpi=300)
            imcount=imcount+1
            plt.close(fig)
#%%Plot output data
def plotoutput(testdir,imgdir):
    """This will plot all of the fitted data with each time step as a pcolor images of
    electron density and electron density from power mesurements.
    Inputs
    testdir - The directory with the input data in h5 files formated for the ionocontainer structure.
    imgdir - The directory that holds the images."""
{'fraction_non_alphanumeric': 0.14759067628305633, 'fraction_numerical': 0.03041705863907181, 'mean_word_length': 2.7070902750871757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '180682', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3506, 'n_words': 667}