ODL Forums
Timespan is not taken into account in a granule - Printable Version

+- ODL Forums (https://forum.oceandatalab.com)
+-- Forum: SEAScope (https://forum.oceandatalab.com/forum-6.html)
+--- Forum: Bug reports (https://forum.oceandatalab.com/forum-13.html)
+--- Thread: Timespan is not taken into account in a granule (/thread-36.html)



Timespan is not taken into account in a granule - Pasha Pivaev - 2019-07-07

Hello,

Following the notebooks from https://docs.google.com/presentation/d/1uTSElHKKFCuMmcQxkdrqkWxGGiQmGApq0uxMkC69YNQ/edit#slide=id.g3de1913eda_0_0 (specifically about lagrangian advection), a Timespan option doesn't seem to be accounted for. That is, when a granule is loaded to the notebook it is always done regardless of the exact time span I have chosen in the SEAScope viewer.  

These "default" time spans are the following (I know about sea current collections only, as this kind of data is used in the notebook):

-- GlobCurrent geostrophic (current speed): time span is equal to 1 day.
-- Oscar (current speed): time span is equal to 5 days
-- AVISO altimetry (Current from MDT): this granule records the whole span of the collection, i.e. from 2000 to 2020.

I looked up these dates by typing extractions[data]['meta']['start'] and extractions[data]['meta']['stop'] in the notebook. In fact, it is only the metadata which change - the actual dataset (granule) doesn't seem to comprise any different time moments from the one chosen on the timeline in the viewer (without a time span; time span is considered around some date, so a current filed on this exact date is loaded only). Since there are no any other fields for different time moments in a granule, I can't calculate advection or, at least, can't follow the notebook escaping significant changes in code.

Is there the time span bug, or might I forget to do some obvious routine?

And also I would like to copy a cell's content of lagrangian_advection.ipynb 


Code:
k_u = [3, 2, 7, 4, 0, 6, 5, 1] # /!\ Change this

# If you have only selected current you can compute k_u automatically
# Uncomment the following lines
# list_name = []
# list_date = []
# for k, data in enumerate(extractions.keys()):
#     list_name.append(os.path.basename(data))
#     list_date.append(extractions[data]['meta']['start'])
# k_u = sorted(range(len(list_date)), key=list_date.__getitem__)

print(k_u)

To tell the truth, I did get the point of how to construct this k_u list myself. Should I just create it in a manner of [i for i in range(amount of time moments)] or how?

With my time span bug print(k_u) produces [0] with the commented lines above being uncommented, and "IndexError : list index out of rangeis raised on a line where the advcection is calculated in the cell below (the same notebook), which is understandable, because there is no time evolution of a current field in a granule.

Code:
### Set name_var_u, name_var_v
name_var_u = 'eastward_geostrophic_current_velocity' # /!\ Change this
name_var_v = 'northward_geostrophic_current_velocity' # /!\ Change this
#name_var_u = 'u_geo' # /!\ Change this
#name_var_v = 'v_geo' # /!\ Change this
# Get and concatenate velocity variable
u_vel = []
v_vel = []
for ind in k_u:
    granule_uri =  next( v for i, v in enumerate(extractions.keys()) if i == ind )
    extraction = extractions[granule_uri] 
    u_vel.append(extraction['data'][name_var_u])
    v_vel.append(extraction['data'][name_var_v])

from SEAScope.lib.utils import get_lonlat
lon2D, lat2D = get_lonlat(extraction, numpy.shape(u_vel[0]))

# Advect particles
traj_lon, traj_lat, adv_time = tools_advection.advection(part_lon,
                                part_lat, lon2D, lat2D, u_vel,
                                v_vel, tadv, time_step)
stop_dt = start + datetime.timedelta(days=adv_time[-1])

# Trajectory time
traj_time = []
start_ref = datetime.datetime(2015,12,1)
for i in range(len(adv_time)):
    traj_dt = (start + datetime.timedelta(days=adv_time[i]) - start_ref)
    traj_time.append(traj_dt.days)

OS is Ubuntu 18.04
Version of Python is 3.6.8


Thank you in advance.


RE: Timespan is not taken into account in a granule - Sylvain Herlédan - 2019-07-08

Hi,

If you selected the "1w" (one week)  timespan in SEAScope but only get 1 granule for the Geostrophic current after the extraction is complete, it probably means that you did not follow the instructions provided in slide 6 of the presentation you linked.

By default the config.ini file for "GlobCurrent geotrophic current" collection has the mustBeCurrent parameter set to True, so that SEAScope only displays the granule which intersects the current datetime. This is the behavior you seem to witness.

SEAScope can only perform extraction on data displayed on the screen, and for the lagrangian advection notebook we need to extract several GlobCurrent geostrophic current granules at once, so we have to modify the aforementioned configuration to alter SEAScope behavior for this collection and get it to display several days of geostrophic current at once.

The instructions in slide 6 provide a new config.ini where mustBeCurrent has been set to False, so that SEAScope can display (and therefore extract) "GlobCurrent geostrophic current" granules as long as there time coverage intersects SEAScope selected timespan (one week evenly distributed around the current date).

Doing so should allow you to extract the data required in the notebook and to perform the advection. Let us know if there are other issues.

PS: regarding your question about the k_u variable: the extractions object is an unsorted list of extracted data, but we need these data sorted in chronological order so we build the k_u list which contains the indices of extracted data sorted by time (the beginning of their time coverage actually, obtained with ['meta']['start']).


RE: Timespan is not taken into account in a granule - Pasha Pivaev - 2019-07-08

When updated the config.ini file things got right.

The rule of thumb to remember for me: read documents properly. Haste makes waste.

Thank you.