OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
249 stars 120 forks source link

Reader problem when reading lon and lat data #122

Closed amandaivl closed 3 years ago

amandaivl commented 5 years ago

Hi, I am getting an attribute error when I'm trying to use OceanDrift to model the trajectory of a drifting buoy. I'm using data from the NASA's PO.DAAC Drive OSCAR files (https://podaac-tools.jpl.nasa.gov/drive/files/OceanCirculation/oscar/preview/L4/oscar_third_deg). I already checked that if follows CF conventions, and also tried changing variables names. The only difference I could find between this and the drifter example data is that this one uses longitude and latitude instead of a projection in meters.

This is the code I'm running:

from opendrift.models.oceandrift import OceanDrift o = OceanDrift() from opendrift.readers import reader_netCDF_CF_generic reader_oscar = reader_netCDF_CF_generic.Reader('file_path')

And I'm getting the following result: 15:14:03 INFO: Opening dataset: file_path 15:14:03 INFO: Opening file with Dataset 15:14:03 DEBUG: Finding coordinate variables. 15:14:03 DEBUG: Parsing variable: time 15:14:03 DEBUG: Parsing variable: year 15:14:03 DEBUG: Parsing variable: depth 15:14:03 DEBUG: Parsing variable: latitude 15:14:03 DEBUG: Parsing variable: longitude 15:14:03 DEBUG: Parsing variable: u 15:14:03 DEBUG: Parsing variable: v 15:14:03 DEBUG: Parsing variable: um 15:14:03 DEBUG: Parsing variable: vm


AttributeError Traceback (most recent call last)

in ----> 1 reader_oscar = reader_netCDF_CF_generic.Reader('C:/Users/amand/Dropbox (MIT)/CEiiA/Data/OSCAR/oscar_vel2019.nc') c:\users\amand\opendrift\opendrift\readers\reader_netCDF_CF_generic.py in __init__(self, filename, name, proj4) 174 175 if 'x' not in locals(): --> 176 if self.lon.ndim == 1: 177 x = self.lon[:] 178 self.xname = lon_var_name AttributeError: 'Reader' object has no attribute 'lon'
knutfrode commented 5 years ago

Hi, sorry for delayed feedback due to holidays.

One difference is that longitude and latitude of Oscar-files seem to have capitalised long_name. I have now updated the reader to allow for this: https://github.com/OpenDrift/opendrift/commit/e9458de3ae61750c1cac925f34c17155390af89a

However, the variables of the Oscar-files do also not have standard_name. This may be added with e.g. NCO like this:

ncatted -a standard_name,u,o,c,x_sea_water_velocity oscar_vel2019.nc
ncatted -a standard_name,v,o,c,y_sea_water_velocity oscar_vel2019.nc
gauteh commented 3 years ago

Closing due to inactivity.