Changeset 2460 in lmdz_wrf for trunk/tools/generic_tools.py


Ignore:
Timestamp:
Apr 23, 2019, 2:59:43 PM (6 years ago)
Author:
lfita
Message:

Ading:

  • `sign': Function to provide the sign of a number
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2459 r2460  
    192192# shrinkarray_dim: Function to shrink a given array with a vector of True/False along a given dimension
    193193# significant_decomposition: Function to decompose a given number by its signifcant potencies
     194# sign: Function to provide the sign of a number
    194195# singleline_printing_class: Function to print all the values of a given class in a single line to be parseavel
    195196# stagger_unstagger: Function to de-stagger a variable
     
    1582615827    return isleap
    1582715828
     15829def sign(number):
     15830    """ Function to provide the sign of a number
     15831      num: number to provide the sign
     15832    >>> sign(7109)
     15833    1
     15834    >>> sign(-3.43512)
     15835    -1.0
     15836    """
     15837    fname = 'sign'
     15838
     15839    sign = np.abs(number)/number
     15840
     15841    return sign
     15842
     15843def juliandate(yr,mo,dd,hr,mi,ss):
     15844    """ Function to provide the julian date (in days) for a date between 1801 and 2099
     15845      refdate: 1 January 4713 BC (= -4712 January 1), Greenwich mean noon (= 12h UT).
     15846    FROM: https://aa.usno.navy.mil/faq/docs/JD_Formula.php
     15847      after 1990 edition of the U.S. Naval Observatory's Almanac for Computers
     15848    >>> juliandate(1978,1,1,0,0,0)
     15849
     15850    >>> juliandate(1978,7,21,15,0,0)
     15851
     15852    """
     15853    fname = 'juliandate'
     15854
     15855    K = dd
     15856    I = yr
     15857    J = mo
     15858    UT = hr + mi/60. + ss/3600.
     15859
     15860    sec1 = 367.*K
     15861    sec2 = int((7.*(K+int((M+9)/12.)))/4)
     15862    sec3 = int((275.*M)/9.)
     15863    sec4 = I
     15864    sec5 = 1721013.5
     15865    sec6 = UT/24.
     15866    sec7 = 0.5*sign(100.*K+M-190002.5)
     15867
     15868    juliand = int(dd - 32075. + 1461.*(yr+4800.+(mo-14)/12.)/4. +               \
     15869      367.*(mo-2-(mo-14)/12.*12)/12. - 3*((yr+4900+(mo-14)/12.)/100.)/4.)
     15870
     15871    JD= K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12)                \
     15872      /12-3*((I+4900+(J-14)/12)/100)/4
     15873
     15874    print yr,mo,dd,hr,mi,ss,' JD:', JD
     15875
     15876#    juliand = juliand + hr/24. + mi/(24.*60.) + ss/(24.*3600.)
     15877
     15878    return juliand
     15879print juliandate(1877,8,11,7,30,0)
     15880
     15881print juliandate(1970,1,1,0,0,0)
     15882
     15883print juliandate(1978,1,1,0,0,0)
     15884
     15885print juliandate(1978,7,21,15,0,0)
     15886quit()
     15887
    1582815888def fix_CFdates(timevals, origcftimeu, origcal,                                      \
    1582915889  newcftimeu= 'hours since 1949-12-01 00:00:00', newcal='gregorian'):
Note: See TracChangeset for help on using the changeset viewer.