<jupyter_start><jupyter_text>Difference between gridded field (GRIB) and scattered observations (BUFR) In this example we will load a gridded model field in GRIB format and a set of observation data in BUFR format. We will then use Metview to compute and plot their differences.<jupyter_code>import metview as mv<jupyter_output><empty_output><jupyter_text>Metview reads GRIB and BUFR data into its [Fieldset](https://confluence.ecmwf.int/display/METV/Fieldset+Functions) and [Bufr](https://confluence.ecmwf.int/display/METV/Observations+Functions) classes respectively.As these are based on Macro data types, see the Macro documentation links.<jupyter_code>t2m_grib = mv.read('./t2m_grib.grib')
obs_3day = mv.read('./obs_3day.bufr')<jupyter_output><empty_output><jupyter_text>BUFR can contain a complex arragement of data. Metview has a powerful BUFR examiner [tool](https://confluence.ecmwf.int/display/METV/CodesUI) to inspect the data contents and to see the available keynames. This can be launched from the Metview user interface by right-clicking on a BUFR file and selecting 'examine', or directly from the command line: `metview -e bufr /path/to/bufr/file`. With the information gleaned from that, we can filter the variable we require using the obsfilter() function. This returns a [Geopoints](https://confluence.ecmwf.int/display/METV/Geopoints) object, which has many more [functions](https://confluence.ecmwf.int/display/METV/Geopoints+Functions) available to it. Note: prior to Metview 5.1, only a numeric descriptor could be used to specify the parameter.<jupyter_code>t2m_gpt = mv.obsfilter(
    parameter = 'airTemperatureAt2M',
    output = 'geopoints',
    data = obs_3day
)<jupyter_output><empty_output><jupyter_text>Computing the difference between the gridded field and the scattered data is one line of code. Metview will, for each observation point, compute the interpolated value from the field at that location, perform the subtraction and put the result into a new Geopoints object.<jupyter_code>diff = t2m_grib - t2m_gpt<jupyter_output><empty_output><jupyter_text>To plot this, we first need to tell Metview to send the plot to Jupyter.<jupyter_code>mv.setoutput('jupyter')<jupyter_output><empty_output><jupyter_text>Plotting is performed through Metview's interface to the [Magics](https://confluence.ecmwf.int/display/MAGP/Magics) library developed at ECMWF. We will first define the view parameters (by default we will get a global map in cylindrical projection).<jupyter_code># shaded land to make the points stand out more
grey_land_shading = mv.mcoast(
    map_coastline_land_shade        = "on",
    map_coastline_land_shade_colour = "grey",
    map_grid_latitude_increment     = 10,
    map_grid_longitude_increment    = 10,
    map_grid_colour                 = "charcoal"
)

area_view = mv.geoview(
    map_area_definition = 'corners',
    area = [45.83,-13.87,62.03,8.92], # South, West, North, East
    coastlines = grey_land_shading
)<jupyter_output><empty_output><jupyter_text>We can then use Magics' powerful symbol plotting routine to assign colours and sizes based on the magnitude of the differences.<jupyter_code>max_diff = mv.maxvalue(mv.abs(diff))

levels = [max_diff * x for x in [-1, -0.67, -0.33, -0.1, 0.1, 0.33, 0.67, 1]]
 
diff_symb = mv.msymb(
    legend                               = "on",
    symbol_type                          = "marker",
    symbol_table_mode                    = "advanced",
    symbol_outline                       = "on",
    symbol_outline_colour                = "charcoal",
    symbol_advanced_table_selection_type = "list",
    symbol_advanced_table_level_list     = levels,
    symbol_advanced_table_colour_method  = "list",
    symbol_advanced_table_colour_list    = ["blue","sky","rgb(0.82,0.85,1)","white","rgb(0.9,0.8,0.8)","rgb(0.9,0.5,0.5)","red"],
    symbol_advanced_table_height_list    = [0.6,0.5,0.4,0.3,0.3,0.4,0.5,0.6]
)
mv.plot(area_view, diff, diff_symb)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09907198394783046, 'fraction_numerical': 0.020817657386506146, 'mean_word_length': 4.317333333333333, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '263327', 'license': 'Apache-2.0', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1305, 'n_words': 362, 'path': 'processing/field_obs_difference.ipynb', 'repo_name': 'mrocklin/notebook-examples', 'size': '3987'}