How to use the sunpy.Spatial function in sunpy

To help you get started, we’ve selected a few sunpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ofringer / suntanspy / SUNTANS / sunplotpy.py View on Github external
from matplotlib.collections import PolyCollection, LineCollection
from matplotlib.backends.backend_wxagg import \
    FigureCanvasWxAgg as FigCanvas, \
    NavigationToolbar2WxAgg as NavigationToolbar
import matplotlib.animation as animation

from sunpy import Spatial, Grid
from untrim_tools import untrim_gridvars, untrim_griddims, UNTRIMSpatial
from ptm_tools import PtmBin
from suntrack import PtmNC
from datetime import datetime
import numpy as np

import pdb

class SunPlotPy(wx.Frame, Spatial, Grid ):
    """ 
    The main frame of the application
    """
    title = 'sunplot(py)'

    # Plotting options
    autoclim=True
    showedges=False
    bgcolor='k'
    textcolor='w'
    cmap='jet'
    particlesize = 1.8
    particlecolor = 'm'

    # other flags
    collectiontype='cells'
github ofringer / suntanspy / UNTRIM / untrim_tools.py View on Github external
dtype = 'f8'		
untrim_ugrid.update({vname:{'dimensions':dimensions,'attributes':attributes,'dtype':dtype,'zlib':True,'complevel':1,'fill_value':fillval}})





class UNTRIMGrid(Grid):
    """
    UnTRIM grid class for loading from a netcdf file
    """ 
    def __init__(self,ncfile):
        self.ncfile=ncfile
        Grid.__init__(self,ncfile,gridvars=untrim_gridvars,griddims=untrim_griddims)

class UNTRIMSpatial(Spatial):
    """
    Class for handling UnTRIM netcdf hydrodynamic output
    """
    _FillValue = -9999
    def __init__(self,ncfile,**kwargs):
        Spatial.__init__(self,ncfile,gridvars=untrim_gridvars,griddims=untrim_griddims,**kwargs)

        # Make sure the number of faces array is correct
        self.nfaces = np.sum(self.cells.mask==False,axis=1)

        self.xy = self.cellxy()


    
    def loadDataRaw(self,variable=None):
        """ 
github ofringer / suntans / examples / heatflux / scripts / cell_budget.py View on Github external
import numpy as np
import matplotlib.pyplot as plt
from datetime import timedelta
from scipy.integrate import cumtrapz

import pdb

###
# Inputs
ncfile = 'data/Heatflux_AVG.0'
#cellindex=range(0,9)
cellindex=[4]
t0 = 0
###

sun = Spatial(ncfile,klayer=[-99])
sun.tstep = range(t0,sun.Nt)
time = sun.time[sun.tstep]

# Constants
dt = sun.globalatts['dt']*sun.globalatts['ntaverage']
RHO0 = 1000.0
Cp = 4186.0

fac = (RHO0*Cp)

area = sun.Ac[cellindex]
sumarea = np.sum(area)

depth = sun.dv[cellindex]
volume = area*depth # Cell volume
sumvolume = np.sum(volume)
github ofringer / suntanspy / SUNTANS / sunboundary.py View on Github external
def suntans2ic(self,hisfile,setUV=False,seth=False):
        """
        Uses data from another suntans file as initial conditions

        Data needs to be on the same grid

        """
        # Load the history file
        sunhis = Spatial(hisfile, tstep=-1, klayer=[-99])

        # Set the time step to grab from the history file
        #...
        tstep = sunhis.getTstep(self.time,self.time)
        sunhis.tstep = [tstep[0]]
        print 'Setting the intial condition with time step: %s\nfrom the file:%s'\
            %(datetime.strftime(sunhis.time[tstep[0]],\
            '%Y-%m-%d %H-%M-%S'),hisfile)

        # Npw grab each variable and save in the IC object
        if seth:
            self.h = sunhis.loadData(variable='eta').reshape((1,self.h.shape))

        if sunhis.hasVar('temp'):
            self.T = sunhis.loadData(variable='temp').reshape((1,)+self.T.shape)
        if sunhis.hasVar('salt'):
github ofringer / suntanspy / SUNTANS / sunslice.py View on Github external
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
import matplotlib.animation as animation
from sunpy import unsurf
from hybridgrid import Line
from hybridgrid import Point as GPoint

from gridsearch import GridSearch
from shapely.geometry import LineString, Point

import pdb


class Slice(Spatial):
    """
    Suntans vertical slice class
    """
    
    def __init__(self,ncfile,xpt=None,ypt=None,Npt=100):
        
        Spatial.__init__(self,ncfile,klayer=[-99])
        
        # Calculate the horizontal coordinates of the slice
        self.Npt = Npt
        if xpt == None or ypt == None:
            self._getXYgraphically()
        else:
            self.xpt=xpt
            self.ypt=ypt
            self._getSliceCoords()
github ofringer / suntanspy / SUNTANS / suntrack.py View on Github external
t = self.time[ts]

        if xlims == None:
            xlims = [x.min(), x.max()]
        if ylims == None:
            ylims = [y.min(), y.max()]

        self.p_handle.set_xdata(x)
        self.p_handle.set_ydata(y)
        self.title=ax.set_title('Particle positions at %s'%(datetime.strftime(t,'%Y-%m-%d %H:%M:%S')))
        ax.set_xlim(xlims)
        ax.set_ylim(ylims)
        ax.set_aspect('equal')


class SunTrack(Spatial):
    """
    Particle tracking class
    """
    
    verbose = True
    
    # Interpolation method
    interp_method = 'mesh' # 'idw' or 'nearest' or 'mesh'
    # IF interp_method == 'mesh'
    interp_meshmethod = 'nearest' # 'linear' or 'nearest'
    
    advect_method = 'rk2' # 'euler' or 'rk2'

    is3D = True
    
    #