kthyng / tracpy

Fortran core of Tracmass + Python wrapping around the outside.
MIT License
28 stars 19 forks source link

Issue with datetime #11

Closed fascani closed 9 years ago

fascani commented 9 years ago

Hello, I finally succeeded to install everything (octant, pyproj, etc) but I am getting an issue about a comparison between datetime and an array when I performed the tests you provided. For instance:

In [1]: from test_rect import *
/Users/fascani/anaconda/lib/python2.7/site-packages/matplotlib/cbook.py:133: MatplotlibDeprecationWarning: The matplotlib.delaunay module was deprecated in version 1.4. Use matplotlib.tri.Triangulation instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)

In [2]: test_run_2d_ll()
building grid took: 5.96046447754e-06
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-0fb1b50e64f5> in <module>()
----> 1 test_run_2d_ll()

/Users/fascani/programs/python/TracPy/tests/test_rect.pyc in test_run_2d_ll()
     81     # tp._readgrid()
     82 
---> 83     lonp, yp, zp, t, T0, U, V = tracpy.run.run(tp, date, lon0, lat0)
     84 
     85     ## check the results:

/Users/fascani/programs/python/TracPy/tracpy/run.pyc in run(tp, date, lon0, lat0, T0, U, V)
     33 
     34     # Initialize everything for a simulation
---> 35     tinds, nc, t0save, xend, yend, zend, zp, ttend, flag = tp.prepare_for_model_run(date, lon0, lat0)
     36 
     37     timer.addtime('1: Preparing for simulation   ')

/Users/fascani/programs/python/TracPy/tracpy/tracpy_class.pyc in prepare_for_model_run(self, date, lon0, lat0)
    217 
    218         # Figure out what files will be used for this tracking
--> 219         nc, tinds = tracpy.inout.setupROMSfiles(self.currents_filename, date, self.ff, self.tout, self.time_units, tstride=self.tstride)
    220 
    221         # Read in grid parameters into dictionary, grid, if haven't already

/Users/fascani/programs/python/TracPy/tracpy/inout.pyc in setupROMSfiles(loc, date, ff, tout, time_units, tstride)
     62         if ff == 1: #forward in time
     63             dates = nc.variables['ocean_time'][:] # don't stride here, need all times to make index determinations
---> 64             ilow = date >= dates
     65             # time index with time value just below datenum_in (relative to file ifile)
     66             istart = dates[ilow].size - 1

TypeError: can't compare datetime.datetime to numpy.ndarray

I see some workaround on the web like using np.less_than() or np.greater_than() functions instead but maybe you know the reason of that mistake.

Thanks

Francois

kthyng commented 9 years ago

Ah! Thanks. I'll try to fix that now and get back to you.

kthyng commented 9 years ago

Ok it is working for me now. What about for you?

fascani commented 9 years ago

It works for me as well! Thanks a bunch!