Ejemplo n.º 1
0
 def test_returned_dataset_values(self):
     ''' Tests returned dataset variable values '''
     self.ten_year_dataset = ten_year_monthly_dataset()
     start_index = 1
     end_index = 4
     values = self.ten_year_dataset.values[start_index:end_index + 1]
     new_dataset = dp.temporal_slice(start_index, end_index,
                                     self.ten_year_dataset)
     np.testing.assert_array_equal(new_dataset.values, values)
Ejemplo n.º 2
0
 def test_returned_dataset_values(self):
     ''' Tests returned dataset variable values '''
     self.ten_year_dataset = ten_year_monthly_dataset()
     start_index = 1
     end_index = 4
     values = self.ten_year_dataset.values[start_index:end_index + 1]
     new_dataset = dp.temporal_slice(self.ten_year_dataset,
                                     start_index,
                                     end_index)
     np.testing.assert_array_equal(new_dataset.values, values)
Ejemplo n.º 3
0
 def test_returned_dataset_times(self):
     ''' Tests returned dataset times values '''
     self.ten_year_dataset = ten_year_monthly_dataset()
     start_index = 1
     end_index = 4
     dates = np.array([datetime.datetime(2000, month, 1)
                       for month in range(start_index + 1, end_index + 2)])
     new_dataset = dp.temporal_slice(self.ten_year_dataset,
                                     start_index,
                                     end_index)
     np.testing.assert_array_equal(new_dataset.times, dates)
Ejemplo n.º 4
0
 def test_returned_dataset_times(self):
     ''' Tests returned dataset times values '''
     self.ten_year_dataset = ten_year_monthly_dataset()
     start_index = 1
     end_index = 4
     dates = np.array([datetime.datetime(2000, month, 1)
                       for month in range(start_index + 1, end_index + 2)])
     new_dataset = dp.temporal_slice(self.ten_year_dataset,
                                     start_index,
                                     end_index)
     np.testing.assert_array_equal(new_dataset.times, dates)
SE_bounds = Bounds(boundary_type='us_states', us_states=regions[6])

regional_bounds = [
    NW_bounds, SW_bounds, NGP_bounds, SGP_bounds, MW_bounds, NE_bounds,
    SE_bounds
]
""" Load nClimDiv file into OCW Dataset """
obs_dataset = local.load_file(file_obs, variable_name='tave')
""" Load CMIP5 simulations into a list of OCW Datasets"""
model_dataset = local.load_multiple_files(file_path=model_file_path,
                                          variable_name='tas',
                                          dataset_name=dataset_name,
                                          variable_unit='K')
""" Temporal subset of obs_dataset """
obs_dataset_subset = dsp.temporal_slice(obs_dataset,
                                        start_time=start_date,
                                        end_time=end_date)
obs_dataset_season = dsp.temporal_subset(obs_dataset_subset,
                                         month_start,
                                         month_end,
                                         average_each_year=True)
""" Temporal subset of model_dataset """
model_dataset_subset = [
    dsp.temporal_slice(dataset, start_time=start_date, end_time=end_date)
    for dataset in model_dataset
]
model_dataset_season = [
    dsp.temporal_subset(dataset,
                        month_start,
                        month_end,
                        average_each_year=True)
                   us_states=regions[5])
SE_bounds = Bounds(boundary_type='us_states',
                   us_states=regions[6])

regional_bounds = [NW_bounds, SW_bounds, NGP_bounds,
                   SGP_bounds, MW_bounds, NE_bounds, SE_bounds]

""" Load nClimGrid file into OCW Dataset """
obs_dataset = local.load_file(file_obs, variable_name='tave')

""" Load CMIP5 simulations into a list of OCW Datasets"""
model_dataset = local.load_multiple_files(file_path=model_file_path, variable_name='tas',
                                          dataset_name=dataset_name, variable_unit='K')

""" Temporal subset of obs_dataset """
obs_dataset_subset = dsp.temporal_slice(obs_dataset,
                  start_time=start_date, end_time=end_date)
obs_dataset_season = dsp.temporal_subset(obs_dataset_subset, month_start, month_end,
                      average_each_year=True)

""" Temporal subset of model_dataset """
model_dataset_subset = [dsp.temporal_slice(dataset,start_time=start_date, end_time=end_date)
                        for dataset in model_dataset]
model_dataset_season = [dsp.temporal_subset(dataset, month_start, month_end,
                      average_each_year=True) for dataset in model_dataset_subset]


""" Spatial subset of obs_dataset and generate time series """
obs_timeseries = np.zeros([nyear, n_region])   # region index 0-6: NW, SW, NGP, SGP, MW, NE, SE
model_timeseries = np.zeros([nmodel, nyear, n_region])

for iregion in np.arange(n_region):
Ejemplo n.º 7
0
    print 'start_time:', start_time
    print 'end_time:', end_time

if temporal_resolution == 'monthly' and end_time.day != 1:
    end_time = end_time.replace(day=1)
if ref_data_info['data_source'] == 'rcmed':
    min_lat = np.max([min_lat, ref_dataset.lats.min()])
    max_lat = np.min([max_lat, ref_dataset.lats.max()])
    min_lon = np.max([min_lon, ref_dataset.lons.min()])
    max_lon = np.min([max_lon, ref_dataset.lons.max()])
bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)

if ref_dataset.lats.ndim != 2 and ref_dataset.lons.ndim != 2:
    ref_dataset = dsp.subset(bounds, ref_dataset)
else:
    ref_dataset = dsp.temporal_slice(bounds.start, bounds.end, ref_dataset)
for idata, dataset in enumerate(model_datasets):
    if dataset.lats.ndim != 2 and dataset.lons.ndim != 2:
        model_datasets[idata] = dsp.subset(bounds, dataset)
    else:
        model_datasets[idata] = dsp.temporal_slice(bounds.start, bounds.end,
                                                   dataset)

# Temporaly subset both observation and model datasets for the user specified season
month_start = time_info['month_start']
month_end = time_info['month_end']
average_each_year = time_info['average_each_year']

ref_dataset = dsp.temporal_subset(month_start, month_end, ref_dataset,
                                  average_each_year)
for idata, dataset in enumerate(model_datasets):
Ejemplo n.º 8
0
    print 'start_time:', start_time
    print 'end_time:', end_time

if temporal_resolution == 'monthly' and end_time.day !=1:
    end_time = end_time.replace(day=1)
if ref_data_info['data_source'] == 'rcmed':
    min_lat = np.max([min_lat, ref_dataset.lats.min()])
    max_lat = np.min([max_lat, ref_dataset.lats.max()])
    min_lon = np.max([min_lon, ref_dataset.lons.min()])
    max_lon = np.min([max_lon, ref_dataset.lons.max()])
bounds = Bounds(min_lat, max_lat, min_lon, max_lon, start_time, end_time)

if ref_dataset.lats.ndim !=2 and ref_dataset.lons.ndim !=2:
    ref_dataset = dsp.subset(bounds,ref_dataset)
else:
    ref_dataset = dsp.temporal_slice(bounds.start, bounds.end, ref_dataset)
for idata,dataset in enumerate(model_datasets):
    if dataset.lats.ndim !=2 and dataset.lons.ndim !=2:
        model_datasets[idata] = dsp.subset(bounds,dataset)
    else:
        model_datasets[idata] = dsp.temporal_slice(bounds.start, bounds.end, dataset)

# Temporaly subset both observation and model datasets for the user specified season
month_start = time_info['month_start']
month_end = time_info['month_end']
average_each_year = time_info['average_each_year']

ref_dataset = dsp.temporal_subset(month_start, month_end,ref_dataset,average_each_year)
for idata,dataset in enumerate(model_datasets):
    model_datasets[idata] = dsp.temporal_subset(month_start, month_end,dataset,average_each_year)