Ejemplo n.º 1
0
    the areal_data dataframe with average rainfall data in each areal.
    '''
    areal_data_copy = areal_data.copy()
    points = point_data['geometry']
    areas = areal_data['geometry']

    results = []
    for area in areas:
        filtered_points = point_data[points.within(area)]
        results.append(filtered_points[column_name].mean())

    areal_data_copy = areal_data_copy.assign(**{column_name: results})
    return areal_data_copy


if __name__ == '__main__':

    rainfall_daily = load_rainfall_data('daily')
    flood_daily = load_flood_data('daily')

    rain_geo_pandas = convert_to_geopanda(rainfall_daily)
    flood_geo_pandas = convert_to_geopanda(flood_daily)

    huc8_units_file = '/Users/haigangliu/SpatialTemporalBayes/data/shape_file/hydrologic_HUC8_units/wbdhu8_a_sc.shp'
    huc8_units = gpd.read_file(huc8_units_file)
    areal_data = fill_area_with_point_data(huc8_units, rain_geo_pandas, 'PRCP')
    areal_data = fill_area_with_point_data(areal_data, flood_geo_pandas,
                                           'GAGE_MAX')

    test_dataset = areal_data[['NAME', 'geometry', 'PRCP', 'GAGE_MAX']]
Ejemplo n.º 2
0
            self.predictions = np.exp(
                np.median(self.simulated_values['y_pred'], axis=0))

        l1_loss = np.mean(np.abs(self.predictions - self.y_test))
        l2_loss = np.mean(np.square(self.predictions - self.y_test))
        self.summary = {'l1_loss': l1_loss, 'l2_loss': l2_loss}

        output_df = self.test_loc_cache.copy()
        output_df['PRED'] = self.predictions

        return self.predictions


if __name__ == '__main__':
    from SampleDataLoader import load_rainfall_data
    data = load_rainfall_data('monthly')

    gp_spatial_model = GPModelSpatial(data,
                                      split_ratio=0.7,
                                      response_var='PRCP')
    gp_spatial_model.fit(traceplot_name='test_traceplot.png',
                         fast_sampling=True)
    vars_ = gp_spatial_model.predict()

    import pickle
    with open('result.pickle', 'wb') as handler:
        pickle.dump(gp_spatial_model,
                    handler,
                    protocol=pickle.HIGHEST_PROTOCOL)

    print(gp_spatial_model.summary)
Ejemplo n.º 3
0
        snapshots = []
        indices =  self._find_time_index()

        start_year_  = self.start_year
        start_month_ = self.start_month
        start_date_ = self.start_date

        for index in indices:
            self.sst.data[index,:,:][~self.nc_mask] = np.nan
            df_single_month = self._monthly_look_up(index)

            df_single_month.loc[:,'MONTH'] = start_month_
            df_single_month.loc[:,'YEAR'] = start_year_
            snapshots.append(df_single_month)

            start_date_ = start_date_ + relativedelta(months=1)
            current_month = start_date_.month
            current_year = start_date_.year

        return pd.concat(snapshots, ignore_index=True)

if __name__ == '__main__':

    from SampleDataLoader import load_rainfall_data
    new_df = load_rainfall_data()
    locs = new_df.groupby('STATION').first().reset_index()[['STATION','LONGITUDE', 'LATITUDE']]
    lats_and_lons = locs[['LONGITUDE', 'LATITUDE']]
    test_case = SSTcalculator(lats_and_lons, 2011, 10, 2011, 11).run()
    print(test_case.SST.describe())