Changeset 934 for trunk/UTIL


Ignore:
Timestamp:
Apr 22, 2013, 7:20:23 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. thanks to Thomas Navarro added the possibility to change time axis through attribute self.changetime; for now only mars_sol2ls is available, but easy to add one: put calculations in ppcompute, and add the option in the method performtimechange.

Location:
trunk/UTIL/PYTHON/planetoplot_v2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r933 r934  
    153153                      color=None,\
    154154                      label=None,\
     155                      changetime=None,\
    155156                      title=None):
    156157        self.request = None
     
    184185        self.folder = folder
    185186        self.includedate = includedate
     187        self.changetime = changetime
    186188        ## here are user-defined plot settings
    187189        ## -- if not None, valid on all plots in the pp() objects
     
    243245            self.title = other.title
    244246            self.includedate = other.includedate
     247            self.changetime = other.changetime
    245248        else:
    246249            print "!! ERROR !! argument must be a pp object." ; exit()
     
    541544              ### get x,y,z,t dimensions from file
    542545              obj.getdim()
     546              ### possible time axis change
     547              obj.changetime = self.changetime
     548              obj.performtimechange()
    543549              ### get methods
    544550              obj.method_x = mx ; obj.method_y = my
     
    10691075        self.swap_axes = False ; self.invert_axes = False
    10701076        self.compute = None
     1077        self.changetime = None
    10711078
    10721079    # open a file. for now it is netcdf. TBD for other formats.
     
    11811188          if self.dim_t > 1:
    11821189               if self.verbose: print "**** OK. t axis %4.0f values [%5.1f,%5.1f]" % (self.dim_t,self.field_t.min(),self.field_t.max())     
     1190
     1191    # change time axis
     1192    # ... add your options here!
     1193    # --------------------------
     1194    def performtimechange(self):
     1195        if self.changetime is not None \
     1196          and self.name_t != "t grid points":
     1197            if self.verbose: print "**** OK. Converting time axis:",self.changetime
     1198            if self.changetime == "mars_sol2ls":
     1199                self.field_t = ppcompute.mars_sol2ls(self.field_t)
     1200            else:
     1201                print "!! WARNING !! This time change is not implemented. Nothing is done."
    11831202
    11841203    # get list of index to be retrieved for time axis
  • trunk/UTIL/PYTHON/planetoplot_v2/ppcompute.py

    r910 r934  
    77# added librairies
    88import numpy as np
     9import math  as m
    910import scipy.signal as sp_signal
    1011###############################################
     
    173174    y=np.convolve(w/w.sum(),s,mode='valid')
    174175    return y
     176
     177########################
     178#### TIME CONVERTER ####
     179########################
     180
     181#  mars_sol2ls
     182#  author T. Navarro
     183#  -----------------
     184#  convert a given martian day number (sol)
     185#  into corresponding solar longitude, Ls (in degr.),
     186#  where sol=0=Ls=0 is the
     187#  northern hemisphere spring equinox.
     188#  -----------------
     189def mars_sol2ls(soltabin):
     190      year_day  = 668.6
     191      peri_day  = 485.35
     192      e_elips   = 0.09340
     193      radtodeg  = 57.2957795130823
     194      timeperi  = 1.90258341759902
     195      if type(soltabin).__name__ in ['int','float','float32','float64']:
     196        soltab=[soltabin]
     197        solout=np.zeros([1])
     198      else:
     199        soltab=soltabin
     200        solout=np.zeros([len(soltab)])
     201      i=0
     202      for sol in soltab:
     203         zz=(sol-peri_day)/year_day
     204         zanom=2.*np.pi*(zz-np.floor(zz))
     205         xref=np.abs(zanom)
     206#  The equation zx0 - e * sin (zx0) = xref, solved by Newton
     207         zx0=xref+e_elips*m.sin(xref)
     208         iter=0
     209         while iter <= 10:
     210            iter=iter+1
     211            zdx=-(zx0-e_elips*m.sin(zx0)-xref)/(1.-e_elips*m.cos(zx0))
     212            if(np.abs(zdx) <= (1.e-7)):
     213              continue
     214            zx0=zx0+zdx
     215         zx0=zx0+zdx
     216         if(zanom < 0.): zx0=-zx0
     217# compute true anomaly zteta, now that eccentric anomaly zx0 is known
     218         zteta=2.*m.atan(m.sqrt((1.+e_elips)/(1.-e_elips))*m.tan(zx0/2.))
     219# compute Ls
     220         ls=zteta-timeperi
     221         if(ls < 0.): ls=ls+2.*np.pi
     222         if(ls > 2.*np.pi): ls=ls-2.*np.pi
     223# convert Ls in deg.
     224         ls=radtodeg*ls
     225         solout[i]=ls
     226         i=i+1
     227      return solout
     228
Note: See TracChangeset for help on using the changeset viewer.