예제 #1
0
def check(name):
    run(name)

    with open(name + '.tex', 'r') as f:
        # can't use display.Latex here, it would result in CSS comparisons in the output.
        # using `display` forces this to be a separate output to any stdout from above.
        display_pretty(f.read(), raw=True)
예제 #2
0
def CAOSpy_rundx_noise(tstart,tstop,mc,pdyn,cinf,precTS,particles,leftover,drained,dt_max=1.,splitfac=10,prec_2D=False,maccoat=10.,exfilt_method='Ediss',saveDT=True,vertcalfac=1.,latcalfac=1.,clogswitch=False,infilt_method='MDA',film=True,dynamic_pedo=True,ksnoise=1.):
    if run_from_ipython():
        from IPython import display

    timenow=tstart
    prec_part=0. #precipitation which is less than one particle to accumulate
    acc_mxinf=0. #matrix infiltration may become very small - this shall handle that some particles accumulate to infiltrate
    exfilt_p=0. #exfiltration from the macropores
    s_red=0.
    #loop through time
    while timenow < tstop:
        [thS,npart]=pdyn.gridupdate_thS(particles.lat,particles.z,mc)
        if saveDT==True:
            #define dt as Courant/Neumann criterion
            dt_D=(mc.mgrid.vertfac.values[0])**2 / (6*np.nanmax(mc.D[np.amax(thS),:]))
            dt_ku=-mc.mgrid.vertfac.values[0]/np.nanmax(mc.ku[np.amax(thS),:])
            dt=np.amin([dt_D,dt_ku,dt_max,tstop-timenow])
        else:
            if type(saveDT)==float:
                #define dt as pre-defined
                dt=np.amin([saveDT,tstop-timenow])
            elif type(saveDT)==int:
                #define dt as modified  Corant/Neumann criterion
                dt_D=(mc.mgrid.vertfac.values[0])**2 / (6*np.nanmax(mc.D[np.amax(thS),:]))*saveDT
                dt_ku=-mc.mgrid.vertfac.values[0]/np.nanmax(mc.ku[np.amax(thS),:])*saveDT
                dt=np.amin([dt_D,dt_ku,dt_max,tstop-timenow])
        #INFILTRATION
        [p_inf,prec_part,acc_mxinf]=cinf.pmx_infilt(timenow,precTS,prec_part,acc_mxinf,thS,mc,pdyn,dt,0.,prec_2D,particles.index[-1],infilt_method) #drain all ponding // leftover <-> 0.
        particles=pd.concat([particles,p_inf])
        
        #DIFFUSION
        [particles,thS,npart,phi_mx]=pdyn.part_diffusion_split(particles,npart,thS,mc,dt,False,splitfac,vertcalfac,latcalfac,dynamic_pedo=True,ksnoise=ksnoise)
        #ADVECTION
        if not particles.loc[(particles.flag>0) & (particles.flag<len(mc.maccols)+1)].empty:
            [particles,s_red,exfilt_p]=pdyn.mac_advection(particles,mc,thS,dt,clogswitch,maccoat,exfilt_method,film=film,dynamic_pedo=True,ksnoise=ksnoise)
        #INTERACT
        particles=pdyn.mx_mp_interact_nobulk(particles,npart,thS,mc,dt,dynamic_pedo=True,ksnoise=ksnoise)

        if run_from_ipython():
            display.clear_output()
            display.display_pretty(''.join(['time: ',str(timenow),'s  |  precip: ',str(len(p_inf)),' particles  |  mean v(adv): ',str(particles.loc[particles.flag>0,'advect'].mean()),' m/s  |  exfilt: ',str(int(exfilt_p)),' particles']))
        else:
            print 'time: ',timenow,'s'

        #CLEAN UP DATAFRAME
        drained=drained.append(particles[particles.flag==len(mc.maccols)+1])
        particles=particles[particles.flag!=len(mc.maccols)+1]
        pondparts=(particles.z<0.)
        leftover=np.count_nonzero(-pondparts)
        particles.cell[particles.cell<0]=mc.mgrid.cells.values
        particles=particles[pondparts]
        timenow=timenow+dt

    return(particles,npart,thS,leftover,drained,timenow)
예제 #3
0
 def print_current_values(self, only_free=False, fancy=True):
     """Prints the current values of the component's parameters.
     Parameters
     ----------
     only_free : bool
         If True, only free parameters will be printed.
     fancy : bool
         If True, attempts to print using html rather than text in the notebook.
     """
     if fancy:
         display(current_component_values(self, only_free=only_free))
     else:
         display_pretty(current_component_values(self, only_free=only_free))
예제 #4
0
파일: client.py 프로젝트: fangohr/elogexpt
def ipy_summary(idrange=None):
    if idrange is None:
        data = get_recent()
    else:
        data = get_range(*idrange)

    id_range = data[0]['id'], data[-1]['id']
    display_pretty("Data for range {}-{}".format(*id_range),
                   raw=True,
                   metadata={'data_range': id_range})

    plotit(data)

    if idrange is None:
        print("To get this data again later, run:")
        print("    data = ipy_summary(({!r}, {!r}))".format(
            data[0]['id'], data[-1]['id']))

    return data
예제 #5
0
 def _to_altair(self, button):
     code = self.chart.to_altair()
     display_pretty(code, raw=True)
예제 #6
0
 def _print(t):
     display_pretty(t, raw=True)
예제 #7
0
def CAOSpy_rundx1(tstart,
                  tstop,
                  mc,
                  pdyn,
                  cinf,
                  precTS,
                  particles,
                  leftover=0,
                  drained=0.1,
                  dt_max=1.,
                  splitfac=10,
                  prec_2D=False,
                  maccoat=10.,
                  exfilt_method='Ediss',
                  saveDT=True,
                  vertcalfac=1.,
                  latcalfac=1.,
                  clogswitch=False,
                  infilt_method='MDA',
                  film=True,
                  infiltscale=False,
                  dynamic_pedo=False,
                  counteractpow=3):
    if run_from_ipython():
        from IPython import display

    timenow = tstart
    prec_part = 0.  #precipitation which is less than one particle to accumulate
    acc_mxinf = 0.  #matrix infiltration may become very small - this shall handle that some particles accumulate to infiltrate
    exfilt_p = 0.  #exfiltration from the macropores
    s_red = 0.
    mc.splitfac = splitfac
    mc.counteract_pow = counteractpow

    if type(drained) == float:
        drained = pd.DataFrame(np.array([]))
    #loop through time
    while timenow < tstop:
        [thS, npart] = pdyn.gridupdate_thS(particles.lat, particles.z, mc)
        if saveDT == True:
            #define dt as Courant/Neumann criterion
            dt_D = (mc.mgrid.vertfac.values[0])**2 / (
                6 * np.amax(mc.D[particles.LTEbin.max(), :]))
            dt_ku = -mc.mgrid.vertfac.values[0] / np.amax(
                mc.ku[particles.LTEbin.max(), :])
            dt = np.amin([dt_D, dt_ku, dt_max, tstop - timenow])
            dt = np.amax([dt, 0.5])
            mc.dt = dt
        else:
            if type(saveDT) == float:
                #define dt as pre-defined
                dt = np.amin([saveDT, tstop - timenow])
                mc.dt = dt
            elif type(saveDT) == int:
                #define dt as modified  Corant/Neumann criterion
                dt_D = (mc.mgrid.vertfac.values[0])**2 / (
                    6 * np.nanmax(mc.D[np.amax(thS), :])) * saveDT
                dt_ku = -mc.mgrid.vertfac.values[0] / np.nanmax(
                    mc.ku[np.amax(thS), :]) * saveDT
                dt = np.amin([dt_D, dt_ku, dt_max, tstop - timenow])
                mc.dt = dt

        pcount = len(particles)
        #INFILTRATION (new version with binned)
        [p_inf, prec_part, acc_mxinf
         ] = cinf.pmx_infilt(timenow, precTS, prec_part, acc_mxinf, thS, mc,
                             pdyn, mc.dt, leftover, prec_2D,
                             particles.index[-1], infilt_method, infiltscale,
                             npart)  #drain all ponding // leftover <-> 0.
        particles = pd.concat([particles, p_inf])

        #DEBUG:
        #if len(particles)<100000:
        #    particles.to_pickle('DEBUG_particlesX.pic')
        #    assert False
        #particles.to_pickle('DEBUG_particles.pic')
        #particles=particles.groupby('cell').apply(pdyn.binupdate_pd,mc)
        #particles.loc[particles.LTEbin>(len(mc.ku)-1),'LTEbin']=len(mc.ku)-1
        #plot_mac(particles,'./results/Mtest'+str(np.round(timenow,2)))

        #DIFFUSION
        #[particles,thS,npart,phi_mx]=pdyn.part_diffusion_split(particles,npart,thS,mc,dt,False,splitfac,vertcalfac,latcalfac)
        #[particles,thS,npart,phi_mx]=pdyn.part_diffusion_binned(particles,npart,thS,mc,dt)

        [particles, thS, npart,
         phi_mx] = pdyn.part_diffusion_binned_pd(particles, npart, thS, mc)

        #ADVECTION
        if not particles.loc[(particles.flag > 0)
                             & (particles.flag < len(mc.maccols) + 1)].empty:
            [particles, s_red, exfilt_p,
             mc] = pdyn.mac_advectionX(particles,
                                       mc,
                                       thS,
                                       mc.dt,
                                       clogswitch,
                                       maccoat,
                                       exfilt_method,
                                       film=film,
                                       dynamic_pedo=dynamic_pedo,
                                       npart=npart,
                                       fc_check=False)

        #INTERACT
        particles = pdyn.mx_mp_interact_nobulk(particles, npart, thS, mc,
                                               mc.dt, dynamic_pedo)

        #CLEAN UP DATAFRAME
        drained = drained.append(particles[particles.flag == len(mc.maccols) +
                                           1])
        particles = particles.loc[particles.flag != len(mc.maccols) + 1]
        #leftover+=np.intp((particles.z>=0.).sum())
        leftover = particles.z[particles.z >= 0.].count()
        particles = particles.loc[
            particles.z < 0.]  #drop all leftover back to infilt routine

        if run_from_ipython():
            display.clear_output()
            display.display_pretty(''.join([
                'time: ',
                str(timenow), 's  |  n_particles: ',
                str(pcount), '  |  precip: ',
                str(len(p_inf)), '  |  advect: ',
                str(
                    np.sum(((particles.flag > 0) &
                            (particles.flag <= len(mc.maccols))))),
                '  |  exfilt: ',
                str(int(exfilt_p)), '  |  mean v(adv): ',
                str(particles.loc[((particles.flag > 0) &
                                   (particles.flag <= len(mc.maccols))),
                                  'advect'].mean())[:7] +
                str(particles.loc[((particles.flag > 0) &
                                   (particles.flag <= len(mc.maccols))),
                                  'advect'].mean())[-4:], ' m/s'
            ]))
            display.display_pretty(''.join([
                'time: ',
                str(timenow), 's  |  n_particles now: ',
                str(len(particles)), '  |  leftover: ',
                str(leftover)
            ]))
        else:
            print('time: ', timenow, 's')

        #particles.loc[particles.cell<0,'cell']=mc.mgrid.cells.values
        #particles=particles[pondparts]
        timenow = timenow + mc.dt

    return (particles, npart, thS, leftover, drained, timenow)
예제 #8
0
def CAOSpy_rund_diffonly(tstart,
                         tstop,
                         mc,
                         pdyn,
                         cinf,
                         precTS,
                         particles,
                         leftover,
                         drained,
                         dt_max=1.,
                         splitfac=10,
                         prec_2D=False,
                         saveDT=True,
                         vertcalfac=1.,
                         latcalfac=1.):
    if run_from_ipython():
        from IPython import display

    timenow = tstart
    prec_part = 0.  #precipitation which is less than one particle to accumulate
    acc_mxinf = 0.  #matrix infiltration may become very small - this shall handle that some particles accumulate to infiltrate
    exfilt_p = 0.  #exfiltration from the macropores
    s_red = 0.
    #loop through time
    while timenow < tstop:
        [thS, npart] = pdyn.gridupdate_thS(particles.lat, particles.z, mc)
        if saveDT == True:
            #define dt as Courant/Neumann criterion
            dt_D = (mc.mgrid.vertfac.values[0])**2 / (
                6 * np.nanmax(mc.D[np.amax(thS), :]))
            dt_ku = -mc.mgrid.vertfac.values[0] / np.nanmax(
                mc.ku[np.amax(thS), :])
            dt = np.amin([dt_D, dt_ku, dt_max, tstop - timenow])
        else:
            if type(saveDT) == float:
                #define dt as pre-defined
                dt = np.amin([saveDT, tstop - timenow])
            elif type(saveDT) == int:
                #define dt as modified  Corant/Neumann criterion
                dt_D = (mc.mgrid.vertfac.values[0])**2 / (
                    6 * np.nanmax(mc.D[np.amax(thS), :])) * saveDT
                dt_ku = -mc.mgrid.vertfac.values[0] / np.nanmax(
                    mc.ku[np.amax(thS), :]) * saveDT
                dt = np.amin([dt_D, dt_ku, tstop - timenow])
        #INFILTRATION
        [p_inf, prec_part, acc_mxinf] = cinf.pmx_infilt(
            timenow, precTS, prec_part, acc_mxinf, thS, mc, pdyn, dt, 0.,
            prec_2D,
            particles.index[-1])  #drain all ponding // leftover <-> 0.
        p_inf.flag = 0
        particles = pd.concat([particles, p_inf])

        #DIFFUSION
        [particles, thS, npart,
         phi_mx] = pdyn.part_diffusion_split(particles, npart, thS, mc, dt,
                                             False, splitfac, vertcalfac,
                                             latcalfac)

        if run_from_ipython():
            display.clear_output()
            display.display_pretty(''.join([
                'time: ',
                str(timenow), 's  |  precip: ',
                str(len(p_inf)), ' particles'
            ]))
        else:
            print 'time: ', timenow, 's'

        #CLEAN UP DATAFRAME
        drained = drained.append(particles[particles.flag == len(mc.maccols) +
                                           1])
        particles = particles[particles.flag != len(mc.maccols) + 1]
        pondparts = (particles.z < 0.)
        leftover = np.count_nonzero(-pondparts)
        particles.cell[particles.cell < 0] = mc.mgrid.cells.values
        particles = particles[pondparts]
        timenow = timenow + dt

    return (particles, npart, thS, leftover, drained, timenow)
예제 #9
0
objects.head()

# ###### local cache of Furis echo data

# In[11]:
ipdb.set_trace()
import os
import shutil
from IPython.display import display_pretty

gdm_data_dir = r'\\NLAMFSRFL01.railinfra.local\GDM_RO$\Live\Data'
cache_dir = os.path.join(r'c:\DATA\GDM', system)
os.makedirs(cache_dir, exist_ok=True)

for run, row in runs_sel.iterrows():
    gdm_id = row.run_id
    fn = get_gdm_h5path(gdm_id, system)
    fnpath = os.path.join(gdm_data_dir, fn)
    fn_new = os.path.basename(fn)
    fnpath_new = os.path.join(cache_dir, fn_new)
    try:
        if os.path.isfile(fnpath_new):
            # TODO: check also file size
            raise ValueError
        shutil.copy(fnpath, cache_dir)
        display_pretty('{} copied.'.format(fnpath))
    except ValueError:
        display_pretty('File {} is already in cache directory.'.format(fn_new))
    except OSError:
        display_pretty('{} NOT copied.'.format(fnpath))
예제 #10
0
    print ""
    print series[['Instructor', 'Curriculum Manager', 'Course Number']]

'''
You can also use boolean operators to select specific items from the Series
'''
# Change False to True to see boolean indexing in action
if False:
    cuteness = pd.Series([1, 2, 3, 4, 5], index=['Cockroach', 'Fish', 'Mini Pig',
                                                 'Puppy', 'Kitten'])
    print cuteness > 4
    print ""
    ip.display(cuteness[cuteness > 3])


'''
Create a simple dataset of people
'''
if True:
    data = {
            'Name': ["John", "Anna", "Peter", "linda"],
            'Location': ["New York", "Paris", "Berlin", "London"],
            'Age': [24,13,53,33]
            }
    data_pandas = pd.DataFrame(data)
    ip.display(data_pandas)

    # Select all rolws that have an age column greater than 30
    ip.display_pretty(data_pandas[data_pandas.Age > 30])

예제 #11
0
def _raw_text(s):
    display_pretty(s, raw=True)