Changeset 403 for trunk/UTIL


Ignore:
Timestamp:
Nov 21, 2011, 6:09:07 PM (14 years ago)
Author:
acolaitis
Message:

PYTHON.

############################################
1/------------------------------------------
############################################
# First version of a new command line routine
# that takes in input a diagfi and a MCS datafile
# as formatted by Luca Montabone
# and find the values in the diagfi temp field
# corresponding to daytime and nightime localtimes in MCS file
# (at each longitude and latitude, which is especially important at the poles
# where the spacecraft covers multiple local times for each bin)
# The selected diagfi data is then binned at the Ls of the MCS file
# and written as a diagfi_MCS.nc file.
#
# Example: (you have to be connected on Penn, as the file is on the local disk)

/san0/acolmd/SVN/trunk/UTIL/PYTHON/mcs.py -f /home/local_home/colaitis/Polar_simulations/Polar_All_Th/diagfi16.nc -m /san0/acolmd/DATA/MCS/MCS_processeddata/MCSdata_binned_MY29.nc

# It is then easy to compare the resulting gcm re-arranged data to the MCS dataset using
# your favorite pp command. Note that in this first version of the routine, only the temperature field is
# recomputed. A more complex version will come out later, with variable selection and conservation of
# fields needed to then use zrecast or hrecast.

############################################
2/------------------------------------------
############################################

# Added python versions of ls2sol and sol2ls
# which can work either with single values or arrays
# These routines are in times.py so that you can add
# in your script:

from times import ls2sol,sol2ls

############################################
2/------------------------------------------
############################################

# Added new routine in mymath, which finds the index of the
# element nearest to "value" in "array". The array
# can be masked or not, the output is an array.
# If the value is a NaN, the routine returns a NaN.
# One can specify the option "strict=True" so that
# the routine will return a NaN if the value asked is not
# between the min and max of the array.

Location:
trunk/UTIL/PYTHON
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/mymath.py

    r398 r403  
    172172    return [item[0] for item in self.items() if item[1] == value]
    173173
     174# A.C. routine that gets the nearest value index of array and value
     175def find_nearest(arr,value,axis=None,strict=False):
     176    import numpy as np
     177    # Special case when the value is nan
     178    if value*0 != 0: return np.NaN
     179    # Check that the value we search is inside the array for the strict mode
     180    if strict:
     181       min=arr.min()
     182       max=arr.max()
     183       if ((value > max) or (value < min)): return np.NaN
     184
     185    if type(arr).__name__=='MaskedArray':
     186       mask=np.ma.getmask(arr)
     187       idx=np.ma.argmin(np.abs(arr-value),axis=axis)
     188    # Special case when there are only missing values on the axis
     189       if mask[idx]:
     190          idx=np.NaN
     191    else:
     192       idx=(np.abs(arr-value)).argmin(axis=axis)
     193    return idx
     194
  • trunk/UTIL/PYTHON/time.F

    r261 r403  
    1818      double precision    pi,radtodeg
    1919c number of martian days (sols) in a martian year
    20       parameter (year_day=668.6d0)
     20      parameter (year_day=668.6)
    2121c perihelion date (in sols)
    22       parameter (peri_day=485.35d0)
     22      parameter (peri_day=485.35)
    2323c orbital eccentricity
    24       parameter (e_elips=0.09340d0)
    25       parameter (pi=3.14159265358979d0)
     24      parameter (e_elips=0.09340)
     25      parameter (pi=3.14159265358979)
    2626c  radtodeg: 180/pi
    27       parameter (radtodeg=57.2957795130823d0)
     27      parameter (radtodeg=57.2957795130823)
    2828c  timeperi: 2*pi*( 1 - Ls(perihelion)/ 360 ); Ls(perihelion)=250.99
    29       parameter (timeperi=1.90258341759902d0)
     29      parameter (timeperi=1.90258341759902)
    3030
    3131      double precision    zanom,xref,zx0,zdx,zteta,zz
     
    4141      do 110 iter=1,10
    4242         zdx=-(zx0-e_elips*dsin(zx0)-xref)/(1.-e_elips*dcos(zx0))
    43          if(dabs(zdx).le.(1.d-7)) then ! typically, 2 or 3 iterations are enough
     43         if(dabs(zdx).le.(1.d-7)) then
    4444           goto 120
    4545         endif
     
    7777c  Local:
    7878      double precision xref,zx0,zteta,zz
    79 c       xref: mean anomaly, zteta: true anomaly, zx0: eccentric anomaly
    80       double precision year_day
    8179      double precision peri_day,timeperi,e_elips
    8280      double precision pi,degrad
    83       parameter (year_day=668.6d0) ! number of sols in a amartian year
    84 c      data peri_day /485.0/
    85       parameter (peri_day=485.35d0) ! date (in sols) of perihelion
    86 c  timeperi: 2*pi*( 1 - Ls(perihelion)/ 360 ); Ls(perihelion)=250.99
    87       parameter (timeperi=1.90258341759902d0)
    88       parameter (e_elips=0.0934d0)  ! eccentricity of orbit
    89       parameter (pi=3.14159265358979d0)
    90       parameter (degrad=57.2957795130823d0)
     81      double precision,parameter :: year_day=668.6
     82      parameter (peri_day=485.35)
     83      parameter (timeperi=1.90258341759902)
     84      parameter (e_elips=0.0934) 
     85      parameter (pi=3.14159265358979)
     86      parameter (degrad=57.2957795130823)
    9187
    9288      if (abs(ls).lt.1.0e-5) then
Note: See TracChangeset for help on using the changeset viewer.