Пример #1
0
def _load_rcmed_dataset_object(dataset_info, eval_bounds):
    ''' Create an ocw.dataset.Dataset object from supplied data.

    :param dataset_info: The necessary data to load a RCMED dataset with
        ocw.data_source.rcmed. Must be of the form:
        {
            'dataset_id': The dataset id to grab from RCMED.
            'parameter_id': The variable id value used by RCMED.
            'name': Optional dataset name
        }
    :type dataset_info: Dictionary

    :param eval_bounds: The time, lat, and lon bounds values for this Evaluation.
        Must be of the form:
        {
            'start_time': request.query.start_time,
            'end_time': request.query.end_time,
            'lat_min': request.query.lat_min,
            'lat_max': request.query.lat_max,
            'lon_min': request.query.lon_min,
            'lon_max': request.query.lon_max
        }
    ;type eval_bounds: Dictionary

    :returns: An ocw.dataset.Dataset object containing the requested information.

    :raises KeyError: If the required keys aren't present in the dataset_info or
        eval_bounds objects.
    '''
    dataset = rcmed.parameter_dataset(int(dataset_info['dataset_id']),
                                      int(dataset_info['parameter_id']),
                                      eval_bounds['lat_min'],
                                      eval_bounds['lat_max'],
                                      eval_bounds['lon_min'],
                                      eval_bounds['lon_max'],
                                      eval_bounds['start_time'],
                                      eval_bounds['end_time'])

    # If a name is passed for the dataset, use it. Otherwise, use the file name.
    if 'name'in dataset_info.keys():
        name = dataset_info['name']
    else:
        for m in rcmed.get_parameters_metadata():
            if m['parameter_id'] == str(dataset_info['parameter_id']):
                name = m['longname']
                break
        else:
            # If we can't find a name for the dataset, default to something...
            name = "RCMED dataset"

    dataset.name = name

    return dataset
Пример #2
0
def _load_rcmed_dataset_object(dataset_info, eval_bounds):
    ''' Create an ocw.dataset.Dataset object from supplied data.

    :param dataset_info: The necessary data to load a RCMED dataset with
        ocw.data_source.rcmed. Must be of the form:
        {
            'dataset_id': The dataset id to grab from RCMED.
            'parameter_id': The variable id value used by RCMED.
            'name': Optional dataset name
        }
    :type dataset_info: Dictionary

    :param eval_bounds: The time, lat, and lon bounds values for this Evaluation.
        Must be of the form:
        {
            'start_time': request.query.start_time,
            'end_time': request.query.end_time,
            'lat_min': request.query.lat_min,
            'lat_max': request.query.lat_max,
            'lon_min': request.query.lon_min,
            'lon_max': request.query.lon_max
        }
    ;type eval_bounds: Dictionary

    :returns: An ocw.dataset.Dataset object containing the requested information.

    :raises KeyError: If the required keys aren't present in the dataset_info or
        eval_bounds objects.
    '''
    dataset = rcmed.parameter_dataset(int(dataset_info['dataset_id']),
                                      int(dataset_info['parameter_id']),
                                      eval_bounds['lat_min'],
                                      eval_bounds['lat_max'],
                                      eval_bounds['lon_min'],
                                      eval_bounds['lon_max'],
                                      eval_bounds['start_time'],
                                      eval_bounds['end_time'])

    # If a name is passed for the dataset, use it. Otherwise, use the file name.
    if 'name'in dataset_info.keys():
        name = dataset_info['name']
    else:
        for m in rcmed.get_parameters_metadata():
            if m['parameter_id'] == str(dataset_info['parameter_id']):
                name = m['longname']
                break
        else:
            # If we can't find a name for the dataset, default to something...
            name = "RCMED dataset"

    dataset.name = name

    return dataset
    def setUp(self):
        metadata = rcmed.get_parameters_metadata()
        # Load TRMM from RCMED
        dataset_dat = [m for m in metadata if m['parameter_id'] == '36'][0]

        self.dataset_info = {
            'dataset_id': int(dataset_dat['dataset_id']),
            'parameter_id': int(dataset_dat['parameter_id'])
        }

        self.eval_bounds = {
            'start_time': dt.datetime(1998, 02, 01),
            'end_time': dt.datetime(1998, 03, 01),
            'lat_min': -10,
            'lat_max': 10,
            'lon_min': -15,
            'lon_max': 15
        }
Пример #4
0
    def setUp(self):
        metadata = rcmed.get_parameters_metadata()
        # Load TRMM from RCMED
        dataset_dat = [m for m in metadata if m['parameter_id'] == '36'][0]

        self.dataset_info = {
            'dataset_id': int(dataset_dat['dataset_id']),
            'parameter_id': int(dataset_dat['parameter_id'])
        }

        self.eval_bounds = {
            'start_time': dt.datetime(1998, 02, 01),
            'end_time': dt.datetime(1998, 03, 01),
            'lat_min': -10,
            'lat_max': 10,
            'lon_min': -15,
            'lon_max': 15
        }
Пример #5
0
def get_parameters_bounds():
    ''' Return temporal and spatial bounds metadata for all of JPL's RCMED parameters.

    **Example Call Format**

    .. sourcecode:: javascript

        /parameters/bounds/

    **Example Return JSON Format**

    .. sourcecode:: javascript

        {
          "38": {
            "start_date": "1901-01-15",
            "end_date": "2009-12-15",
            "lat_max": 89.75,
            "lat_min": -89.75,
            "lon_max": 179.75,
            "lon_min": -179.75
          },
          "39": {
            "start_date": "1901-01-15",
            "end_date": "2009-12-15",
            "lat_max": 89.75,
            "lat_min": -89.75,
            "lon_max": 179.75,
            "lon_min": -179.75
          }
        }

    '''
    parameter_bounds = {}
    raw_parameters = rcmed.get_parameters_metadata()
    for parameter in raw_parameters:
        if parameter['bounding_box'] != None:
            param_id, bounds_data = extract_bounds(parameter)
            parameter_bounds[param_id] = bounds_data


    return parameter_bounds
Пример #6
0
    urllib.urlretrieve(FILE_LEADER + FILE_2, FILE_2)


""" Step 1: Load Local NetCDF File into OCW Dataset Objects """
# Load local knmi model data
knmi_dataset = local.load_file(FILE_1, "tasmax")
knmi_dataset.name = "AFRICA_KNMI-RACMO2.2b_CTL_ERAINT_MM_50km_1989-2008_tasmax"

wrf311_dataset = local.load_file(FILE_2, "tasmax")
wrf311_dataset.name = "AFRICA_UC-WRF311_CTL_ERAINT_MM_50km-rg_1989-2008_tasmax"



""" Step 2: Fetch an OCW Dataset Object from the data_source.rcmed module """
print("Working with the rcmed interface to get CRU3.1 Daily-Max Temp")
metadata = rcmed.get_parameters_metadata()

cru_31 = [m for m in metadata if m['parameter_id'] == "39"][0]

""" The RCMED API uses the following function to query, subset and return the 
raw data from the database:

rcmed.parameter_dataset(dataset_id, parameter_id, min_lat, max_lat, min_lon, 
                        max_lon, start_time, end_time)

The first two required params are in the cru_31 variable we defined earlier
"""
# Must cast to int since the rcmed api requires ints
dataset_id = int(cru_31['dataset_id'])
parameter_id = int(cru_31['parameter_id'])
Пример #7
0
# Filename for the output image/plot (without file extension)
OUTPUT_PLOT = "cru_31_tmax_knmi_africa_bias_full"

# Download necessary NetCDF file if not present
if path.exists(MODEL):
    pass
else:
    urllib.urlretrieve(FILE_LEADER + MODEL, MODEL)
""" Step 1: Load Local NetCDF File into OCW Dataset Objects """
print("Loading %s into an OCW Dataset Object" % (MODEL, ))
knmi_dataset = local.load_file(MODEL, "tasmax")
print("KNMI_Dataset.values shape: (times, lats, lons) - %s \n" %
      (knmi_dataset.values.shape, ))
""" Step 2: Fetch an OCW Dataset Object from the data_source.rcmed module """
print("Working with the rcmed interface to get CRU3.1 Daily-Max Temp")
metadata = rcmed.get_parameters_metadata()

cru_31 = [m for m in metadata if m['parameter_id'] == "39"][0]
""" The RCMED API uses the following function to query, subset and return the 
raw data from the database:

rcmed.parameter_dataset(dataset_id, parameter_id, min_lat, max_lat, min_lon, 
                        max_lon, start_time, end_time)

The first two required params are in the cru_31 variable we defined earlier
"""
# Must cast to int since the rcmed api requires ints
dataset_id = int(cru_31['dataset_id'])
parameter_id = int(cru_31['parameter_id'])

print("We are going to use the Model to constrain the Spatial Domain")
Пример #8
0
 def test_function_get_parameters_metadata(self):
     rcmed.urllib2.urlopen = self.return_text
     self.assertEqual(rcmed.get_parameters_metadata(), self.param_metadata_output)
Пример #9
0
 def test_function_get_parameters_metadata(self):
     rcmed.urllib2.urlopen = self.return_text
     self.assertEqual(rcmed.get_parameters_metadata(),
                      self.param_metadata_output)
Пример #10
0
def select_obs_screen(header):   #TODO: if the observation is already selected, don't select again.
     '''Generates screen to select observation.
     It reterives list of observations from database and make a table from that.
     User has to select observation with dataset_id, parameter_id, start_date, end_date, minimum and maximum of lat and lon.
     If the size of terminal screen is small to show whole table, a notification with link to parameter table on website will show up instead.

     :param header: Header of page
     :type header: string

     :returns: Notification
     :rtype: string
     '''

     ready_screen("select_obs_screen")
     screen.addstr(1, 1, header + " > Select Observation ")
     screen.addstr(8, 1, "Observations Table: ")
     screen.addstr(9, 2, "|Dataset ID| - |Parameter ID| - |Time Step| - |Start Date| - | End Date | - | Min Lat | - | Max Lat | - | Min Lon | - | Max Lat | - |Database name")
     screen.addstr(10, 2, "|----------| - |------------| - |---------| - |----------| - |----------| - |---------| - |---------| - |---------| - |---------| - |-------------")
     all_obs_info = rcmed.get_parameters_metadata()
     try:
          for position, obs_info in enumerate(all_obs_info):
               dataset_id = obs_info['dataset_id']
               parameter_id = obs_info['parameter_id']
               timestep = obs_info['timestep']
               start_date = obs_info['start_date']
               end_date = obs_info['end_date']
               min_lat = eval(obs_info['bounding_box'].encode())[2][0] if obs_info['bounding_box'] else None
               max_lat = eval(obs_info['bounding_box'].encode())[0][0] if obs_info['bounding_box'] else None
               min_lon = eval(obs_info['bounding_box'].encode())[2][1] if obs_info['bounding_box'] else None
               max_lon = eval(obs_info['bounding_box'].encode())[0][1] if obs_info['bounding_box'] else None
               database = obs_info['database']
               line = "|{0:>10}| - |{1:>12}| - |{2:>9}| - |{3}| - |{4}| - |{5:>9}| - |{6:>9}| - |{7:>9}| - |{8:>9}| - |{9}".format(
                    dataset_id, parameter_id, timestep, start_date, end_date,
                    str(min_lat), str(max_lat), str(min_lon), str(max_lon), database)
               screen.addstr(11 + position, 2, line)
     except:
          ready_screen("select_obs_screen")
          screen.addstr(1, 1, header + " > Select Observation ")
          screen.addstr(10, 1, "Observation table cannot be shown due to small screen size. ")
          screen.addstr(11, 1, "Please enlarge your screen and try again or refer to 'http://rcmes.jpl.nasa.gov/rcmed/parameters'. ")
     try:
          screen.addstr(4, 2, "Enter Dataset ID: ")
          dataset_id = screen.getstr()
          screen.addstr(5, 2, "Enter Parameter ID: ")
          parameter_id = screen.getstr()

          for obs in all_obs_info:
               if obs['dataset_id'] == dataset_id and obs['parameter_id'] == parameter_id:
                    observations_info.append({
                                        'database':obs['database'],
                                        'dataset_id':dataset_id,
                                        'parameter_id':parameter_id,
                                        'start_date':obs['start_date'],
                                        'end_date':obs['end_date'],
                                        'bounding_box':obs['bounding_box'],
                                        'timestep':obs['timestep'],
                                        'min_lat':float(eval(obs['bounding_box'].encode())[2][0]) if obs['bounding_box'] else None,
                                        'max_lat':float(eval(obs['bounding_box'].encode())[0][0]) if obs['bounding_box'] else None,
                                        'min_lon':float(eval(obs['bounding_box'].encode())[2][1]) if obs['bounding_box'] else None,
                                        'max_lon':float(eval(obs['bounding_box'].encode())[0][1]) if obs['bounding_box'] else None,
                                        'timestep':obs['timestep'],
                                        'timestep':obs['timestep'],
                                        'timestep':obs['timestep'],
                                        'lat_res':float(obs['lat_res'].encode()),
                                        'lon_res':float(obs['lon_res'].encode())
                                        })
                    note = "Observation sucessfully selected."
                    break
               else:
                    note = "WARNING: Observation cannot be selected. There is no observation with given info."
     except:
          note = "WARNING: Observation cannot be selected, dataset or parameter id is wrong."

     return  note