0

I am trying to store the results of v_tide for each time delta and for each grid point. I need to store the v_tide results which are dependent on the latitude, longitude and time.

If for example the time vector has dimensions 120x1, latitude 101x121 and longitude 101x121, then the dimensions of the v_tide matrix are 120x101x121.

northward_velocity = fes.Handler("ocean", "memory", configuration_file)
# eastward_velocity = fes.Handler("ocean", "memory", configuration_file)

# GRID

lats = np.arange(1, 2, 0.5)
lons = np.arange(-79, -78, 0.5)

assert lons.shape == lats.shape
size = lats.size

lons, lats = np.meshgrid(lons, lats)

# DATES

ai, mi, di = 2019, 6, 3
af, mf, df = 2019, 6, 4
dates = datetime(ai, mi, di)
step = timedelta(minutes=60)

# DATENUM

def datenum(dt):
   mdn = dt + timedelta(days = 366)
   frac = (dt - datetime(dt.year,dt.month,dt.day,0,0,0)).seconds/86400.0
   return mdn.toordinal() + frac

dat=np.empty(lons.shape,dtype='datetime64[us]')

while dates < datetime(af, mf, df):
    dat.fill(dates)
    v_tide, _ = northward_velocity.vector(lats.ravel(), lons.ravel(), dat.ravel())
    # u_tide, lp = eastward_velocity.vector(lats.ravel(), lons.ravel(), dates.ravel())
    dates += step
martineau
  • 119,623
  • 25
  • 170
  • 301
  • Ok and where is the problem? Or what is your question? – Joe Jun 12 '20 at 18:05
  • Hello @Joe, my question is about how should I store the v_tide results for each time delta and each grid coordinate in an array. – Estefania Giraldo Jun 12 '20 at 18:22
  • It's not clear what kind of datatype `v_tide` is. The dimensions (101, 120, 121) that you mention are not consistent with `lats` and `lons` in the code; that doesn't help either. – Han-Kwang Nienhuys Jun 12 '20 at 18:57
  • How familiar are you with Numpy? This should be a really basic thing. https://stackoverflow.com/questions/40690248/copy-numpy-array-into-part-of-another-array – Joe Jun 12 '20 at 19:51
  • https://numpy.org/devdocs/user/quickstart.html#indexing-slicing-and-iterating – Joe Jun 12 '20 at 19:52
  • Sorry for not writing the question more clearly. v_tide values are double datatype. I wrote the dimensions (120x101x121) as an example of the v_tide 3D array dimensions for given lats, lons and dates dimesions. But I need to store the calculation data of v_tide for a grid of whatever dimension and for any time range (and its respective delta). @Han-Kwang Nienhuys – Estefania Giraldo Jun 12 '20 at 21:54

1 Answers1

0

Are you looking for something like this?

import numpy as np

n = 10
time = np.arange(n)

all_data = np.zeros((10, 5, 6))

for i in range(n):

    tide = np.random.rand(5, 6)
    all_data[i] = tide

This is a very bad and basic example. And there are probably 100 ways to do it better. But we know nothing about your data and it should get you started.

Filling a 2D matrix in numpy using a for loop

Please read the following tutorials:

https://numpy.org/devdocs/user/quickstart.html#indexing-slicing-and-iterating

https://scipy-lectures.org/

Joe
  • 6,758
  • 2
  • 26
  • 47