<s> import datetime <EOL> import math <EOL> import urllib <EOL> from os import path <EOL> import numpy as np <EOL> import ocw . data_source . local as local <EOL> import ocw . data_source . rcmed as rcmed <EOL> from ocw . dataset import Bounds as Bounds <EOL> import ocw . dataset_processor as dsp <EOL> import ocw . evaluation as evaluation <EOL> import ocw . metrics as metrics <EOL> import ocw . plotter as plotter <EOL> import ssl <EOL> if hasattr ( ssl , '<STR_LIT>' ) : <EOL> ssl . _create_default_https_context = ssl . _create_unverified_context <EOL> FILE_LEADER = "<STR_LIT>" <EOL> YEARS = <NUM_LIT:1> <EOL> FILE_1 = "<STR_LIT>" <EOL> FILE_2 = "<STR_LIT>" <EOL> OUTPUT_PLOT = "<STR_LIT>" <EOL> if path . exists ( FILE_1 ) : <EOL> pass <EOL> else : <EOL> urllib . urlretrieve ( FILE_LEADER + FILE_1 , FILE_1 ) <EOL> if path . exists ( FILE_2 ) : <EOL> pass <EOL> else : <EOL> urllib . urlretrieve ( FILE_LEADER + FILE_2 , FILE_2 ) <EOL> """<STR_LIT>""" <EOL> knmi_dataset = local . load_file ( FILE_1 , "<STR_LIT>" ) <EOL> knmi_dataset . name = "<STR_LIT>" <EOL> wrf311_dataset = local . load_file ( FILE_2 , "<STR_LIT>" ) <EOL> wrf311_dataset . name = "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> metadata = rcmed . get_parameters_metadata ( ) <EOL> cru_31 = [ m for m in metadata if m [ '<STR_LIT>' ] == "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> """<STR_LIT>""" <EOL> dataset_id = int ( cru_31 [ '<STR_LIT>' ] ) <EOL> parameter_id = int ( cru_31 [ '<STR_LIT>' ] ) <EOL> min_lat , max_lat , min_lon , max_lon = wrf311_dataset . spatial_boundaries ( ) <EOL> min_lat = math . ceil ( min_lat ) <EOL> max_lat = math . floor ( max_lat ) <EOL> min_lon = math . ceil ( min_lon ) <EOL> max_lon = math . floor ( max_lon ) <EOL> print ( "<STR_LIT>" ) <EOL> cru_start = datetime . datetime . strptime ( cru_31 [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> cru_end = datetime . datetime . strptime ( cru_31 [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> knmi_start , knmi_end = knmi_dataset . time_range ( ) <EOL> start_time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> end_time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" % ( start_time . strftime ( "<STR_LIT>" ) , <EOL> end_time . strftime ( "<STR_LIT>" ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> cru31_dataset = rcmed . parameter_dataset ( dataset_id , <EOL> parameter_id , <EOL> min_lat , <EOL> max_lat , <EOL> min_lon , <EOL> max_lon , <EOL> start_time , <EOL> end_time ) <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> knmi_dataset = dsp . temporal_rebin ( knmi_dataset , temporal_resolution = '<STR_LIT>' ) <EOL> wrf311_dataset = dsp . temporal_rebin ( wrf311_dataset , temporal_resolution = '<STR_LIT>' ) <EOL> cru31_dataset = dsp . temporal_rebin ( cru31_dataset , temporal_resolution = '<STR_LIT>' ) <EOL> new_bounds = Bounds ( min_lat , max_lat , min_lon , max_lon , start_time , end_time ) <EOL> knmi_dataset = dsp . subset ( new_bounds , knmi_dataset ) <EOL> wrf311_dataset = dsp . subset ( new_bounds , wrf311_dataset ) <EOL> """<STR_LIT>""" <EOL> new_lons = np . arange ( min_lon , max_lon , <NUM_LIT:0.5> ) <EOL> new_lats = np . arange ( min_lat , max_lat , <NUM_LIT:0.5> ) <EOL> knmi_dataset = dsp . spatial_regrid ( knmi_dataset , new_lats , new_lons ) <EOL> wrf311_dataset = dsp . spatial_regrid ( wrf311_dataset , new_lats , new_lons ) <EOL> cru31_dataset = dsp . spatial_regrid ( cru31_dataset , new_lats , new_lons ) <EOL> ensemble_dataset = dsp . ensemble ( [ knmi_dataset , wrf311_dataset ] ) <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> bias = metrics . Bias ( ) <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> bias_evaluation = evaluation . Evaluation ( cru31_dataset , <EOL> [ knmi_dataset , wrf311_dataset , ensemble_dataset ] , <EOL> [ bias ] ) <EOL> print ( "<STR_LIT>" ) <EOL> bias_evaluation . run ( ) <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> results = bias_evaluation . results [ <NUM_LIT:0> ] <EOL> print ( "<STR_LIT>" ) <EOL> lats = new_lats <EOL> lons = new_lons <EOL> fname = OUTPUT_PLOT <EOL> gridshape = ( <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> plotnames = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> for i in np . arange ( <NUM_LIT:3> ) : <EOL> plot_title = "<STR_LIT>" % ( plotnames [ i ] , start_time . strftime ( "<STR_LIT>" ) , end_time . strftime ( "<STR_LIT>" ) ) <EOL> output_file = "<STR_LIT>" % ( fname , plotnames [ i ] . lower ( ) ) <EOL> print "<STR_LIT>" % ( output_file , ) <EOL> plotter . draw_contour_map ( results [ i , : ] , lats , lons , output_file , <EOL> gridshape = gridshape , ptitle = plot_title ) </s>
