<s> from pydap . client import open_url <EOL> from netcdftime import utime <EOL> import numpy as np <EOL> from ocw . dataset import Dataset <EOL> def load ( url , variable , name = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> d = open_url ( url ) <EOL> dataset = d [ variable ] <EOL> temp_dimensions = map ( lambda x : x . lower ( ) , dataset . dimensions ) <EOL> dataset_dimensions = dataset . dimensions <EOL> time = dataset_dimensions [ temp_dimensions . index ( '<STR_LIT:time>' ) if '<STR_LIT:time>' in temp_dimensions else <NUM_LIT:0> ] <EOL> lat = dataset_dimensions [ temp_dimensions . index ( '<STR_LIT>' ) if '<STR_LIT>' in temp_dimensions else <NUM_LIT:1> ] <EOL> lon = dataset_dimensions [ temp_dimensions . index ( '<STR_LIT>' ) if '<STR_LIT>' in temp_dimensions else <NUM_LIT:2> ] <EOL> times = np . array ( _convert_times_to_datetime ( d [ time ] ) ) <EOL> lats = np . array ( dataset [ lat ] [ : ] ) <EOL> lons = np . array ( dataset [ lon ] [ : ] ) <EOL> values = np . array ( dataset [ : ] ) <EOL> origin = { <EOL> '<STR_LIT:source>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : url <EOL> } <EOL> return Dataset ( lats , lons , times , values , variable , <EOL> name = name , origin = origin ) <EOL> def _convert_times_to_datetime ( time ) : <EOL> '''<STR_LIT>''' <EOL> units = time . units <EOL> parsed_time = utime ( units ) <EOL> return [ parsed_time . num2date ( x ) for x in time [ : ] ] </s>
