Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files
CLIMATE-768 - Fix failing tests in Add extra logic to da…
… to check for named dimensions.
  • Loading branch information
MichaelArthurAnderson committed Feb 26, 2016
1 parent de190c6 commit 4e36c1db769959b870f4e49355731e19388c92d3
Showing 1 changed file with 13 additions and 7 deletions.
@@ -17,10 +17,10 @@

from pydap.client import open_url
from netcdftime import utime
import requests
import numpy as np
from ocw.dataset import Dataset

def load(url, variable, name=''):
'''Load a Dataset from an OpenDAP URL
@@ -42,16 +42,21 @@ def load(url, variable, name=''):
d = open_url(url)
dataset = d[variable]

# Grab the lat, lon, and time variable names.
# We assume the variable order is (time, lat, lon)
# By convention, but not by standard, if the dimensions exist, they will be in the order:
# time (t), altitude (z), latitude (y), longitude (x)
# but conventions aren't always followed and all dimensions aren't always present so
# see if we can make some educated deductions before defaulting to just pulling the first three
# columns.
temp_dimensions = map(lambda x:x.lower(),dataset.dimensions)

dataset_dimensions = dataset.dimensions
time = dataset_dimensions[0]
lat = dataset_dimensions[1]
lon = dataset_dimensions[2]
time = dataset_dimensions[temp_dimensions.index('time') if 'time' in temp_dimensions else 0]
lat = dataset_dimensions[temp_dimensions.index('lat') if 'lat' in temp_dimensions else 1]
lon = dataset_dimensions[temp_dimensions.index('lon') if 'lon' in temp_dimensions else 2]

# Time is given to us in some units since an epoch. We need to convert
# these values to datetime objects. Note that we use the main object's
# time object and not the dataset specific reference to it. We need to
# time object and not the dataset specific reference to it. We need to
# grab the 'units' from it and it fails on the dataset specific object.
times = np.array(_convert_times_to_datetime(d[time]))

@@ -67,6 +72,7 @@ def load(url, variable, name=''):
return Dataset(lats, lons, times, values, variable,
name=name, origin=origin)

def _convert_times_to_datetime(time):
'''Convert the OpenDAP time object's values to datetime objects

0 comments on commit 4e36c1d

Please sign in to comment.