Github user lewismc commented on a diff in the pull request: https://github.com/apache/climate/pull/383#discussion_r75452030 --- Diff: ocw/data_source/podaac.py --- @@ -0,0 +1,113 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from podaac_data_source import Podaac +import numpy as np +from ocw.dataset import Dataset +from netCDF4 import Dataset as netcdf_dataset +from netcdftime import utime +import os +import urllib +import xml.etree.ElementTree as ET + + +def convert_times_to_datetime(time): + '''Convert the time object's values to datetime objects + + The time values are stored as some unit since an epoch. These need to be + converted into datetime objects for the OCW Dataset object. + + :param time: The time object's values to convert + :type time: pydap.model.BaseType + + :returns: list of converted time values as datetime objects + ''' + units = time.units + # parse the time units string into a useful object. + # NOTE: This assumes a 'standard' calendar. It's possible (likely?) that + # users will want to customize this in the future. + parsed_time = utime(units) + return [parsed_time.num2date(x) for x in time[:]] + + +def load_dataset(variable, datasetId='', datasetShortName='', name=''): + '''Loads a Dataset from PODAAC + + :param variable: The name of the variable to read from the dataset. + :type variable: :mod:`string` + + :param datasetId: dataset persistent ID. datasetId or \ + shortName is required for a granule search. Example: \ + PODAAC-ASOP2-25X01 + :type datasetId: :mod:`string` + + :param shortName: the shorter name for a dataset. \ + Either shortName or datasetId is required for a \ + granule search. Example: ASCATA-L2-25km + :type shortName: :mod:`string` + + :param name: (Optional) A name for the loaded dataset. + :type name: :mod:`string` + + :returns: A :class:`dataset.Dataset` containing the dataset pointed to by + the OpenDAP URL. + + :raises: ServerError + ''' + # Downloading the dataset using podaac toolkit + podaac = Podaac() + path = os.path.dirname(os.path.abspath(__file__)) + granuleName = podaac.extract_l4_granule( + datasetId=datasetId, shortName=datasetShortName, path=path) + path = path + '/' + granuleName + d = netcdf_dataset(path, mode='r') + dataset = d.variables[variable] + + # By convention, but not by standard, if the dimensions exist, they will be in the order: --- End diff -- Make this Python function documentation rather than hidden docs please.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---