Summed Field Indexing Error #1142
JonathanC33
started this conversation in
General
Replies: 1 comment 3 replies
-
Thank you for asking this question, @JonathanC33. It's hard to find out what's happening without seeing the full error message. However, could it be that your drifter longitudes are defined between 0 and 360 degrees, while your fieldset longitude is defined between -180 and 180 degrees (or the other way around)? That kind of mismatch in coordinate systems often gives errors on the western hemisphere |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm trying to run ocean parcels using a summed windage and ocean velocity field and the initial particle set locations are determined from real-world drifter starting location and times. Every time I start the pset.execute command though I get an immediate error "index 990 is out of bounds for axis 0 with size 990" where 990 is one less than the number of the rows in the windage velocity field. I've also checked the starting location of the drifter and it is within the bounds of both the windage and ocean velocity fields so I'm not sure where the error comes. I've included my code below.
`
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.animation as animation
from matplotlib.animation import FuncAnimation, writers, PillowWriter
import matplotlib
matplotlib.interactive(False)
from parcels import Field, NestedField, FieldSet, ParticleSet, Variable, JITParticle, AdvectionRK4, plotTrajectoriesFile, ErrorCode
import numpy as np
import math
from datetime import timedelta
from operator import attrgetter
import xarray as xr
import cartopy.crs as ccrs
import cartopy
#Import the Bay of Fundy large domain U and V velocity fields
filepath = '/home/joc000/Documents/Data/ocean_drifters/'
filepath_const = '/home/stt001/gpfs4/CONSTANTS/Fundy500/'
coord = filepath_const + 'Bathymetry_Fundy500.nc'
mesh_mask = filepath_const + 'mesh-mask_Fundy500.nc'
filepath_depth = filepath + 'FUNDY500_HC_1h_grid_U_20191225-20191225.nc'
filepath_ocean_u = filepath+'FUNDY500_HC_1h_grid_U_20*.nc'
filepath_ocean_v = filepath+'FUNDY500_HC_1h_grid_V_20*.nc'
#Names for the U and V files, opens multiple
filenames = {
'U': {'lon': coord, 'lat': coord, 'depth':filepath_depth, 'data': filepath_ocean_u},
'V': {'lon': coord, 'lat': coord, 'depth':filepath_depth, 'data': filepath_ocean_v}
}
#Define the dictionary of the variables and the dimensions, no depth in this case
variables = {
'U': 'uo',
'V': 'vo'
}
dimensions = {
'lat': 'nav_lat',
'lon': 'nav_lon',
'depth': 'depthu',
'time': 'time_instant'
}
#Take the depth at 15m (approximately, it's at 14.68m)
indices = {
'U': {'depth': [0]},
'V': {'depth': [0]}
}
#Fieldset using FieldSet.from_netcdf using the filenames, variables, and dimensions
fieldset_ocean = FieldSet.from_netcdf(
filenames,
variables,
dimensions,
indices=indices,
gridindexingtype='nemo',
chunksize=False,
allow_time_extrapolation=True)
#Import the windage
filepath_windg = '/home/joc000/Documents/Data/windage_drifters/'
filepath_wind = filepath_windg+'HRDPS_OPPeast_ps2.5km_y20*.nc'
filepath_coord = filepath_windg+'HRDPS_OPPeast_ps2.5km_y2019m12d20.nc'
#Account for the difference in longitude coordinates
#pfile = xr.open_dataset(filepath_coord)
#pfile['nav_lon'] = pfile['nav_lon'] - 360
#pfile.to_netcdf(filepath_windg+'windage_coords.nc')
filepath_coord = filepath_windg+'windage_coords.nc'
pfile = xr.open_dataset(filepath_windg+'HRDPS_OPPeast_ps2.5km_y2020m01d20.nc')
filenames = {
'U': {'lon': filepath_coord, 'lat': filepath_coord, 'data': filepath_wind},
'V': {'lon': filepath_coord, 'lat': filepath_coord, 'data': filepath_wind}
}
#Define the dictionary of the variables and the dimensions, no depth in this case
variables = {
'U': 'u_wind',
'V': 'v_wind'
}
dimensions = {
'lat': 'nav_lat',
'lon': 'nav_lon',
'time': 'time_counter'
}
#Fieldset using FieldSet.from_netcdf using the filenames, variables, and dimensions
fieldset_wind = FieldSet.from_netcdf(
filenames,
variables,
dimensions,
chunksize=False,
gridindexingtype='nemo',
allow_time_extrapolation=True)
#Scale the wind some percentage
percentage_wind = 0.5
fieldset_wind.U.set_scaling_factor(percentage_wind/100)
fieldset_wind.V.set_scaling_factor(percentage_wind/100)
#Add the two together, wind and ocean
fieldset_sum = FieldSet(
U=fieldset_wind.U+fieldset_ocean.U,
V=fieldset_wind.V+fieldset_ocean.V)
#,fields={'umask': fieldset_ocean.umask})
#Import the Davis drifter data
drifter_number = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13']
drifter_dates = ['20191220-20200224','20191220-20200111','20200106-20200112',
'20200106-20200224','20200120-20200414','20200120-20200221',
'20200203-20200228','20200203-20200414','20200218-20200323',
'20200218-20200414','20200302-20200405','20200302-20200406',
'20200319-20200414','20200319-20200414']
#Run through each of the Davis drifters
#Run for the entire length of the drifter
for i in np.arange(np.shape(drifter_number)[0]):
Beta Was this translation helpful? Give feedback.
All reactions