Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a loop over the number of fields, and setting the parameter grib_field_position to the position of the field in your fieldset ( starting from 1) 

    Code Block
    languagepy
    titlePython Example: Loop over over the fields in a grib fieldset
    collapsetrue
    from Magics.macro import *
    
    #Setting output
    output = output(
        output_formats                = ['ps'],
        output_name                   = 'precip',
        output_name_first_page_number = 'off')
    #Setting the coastlines
    background = mcoast(
        map_coastline_land_shade        = 'on',
        map_coastline_land_shade_colour = 'cream')
    #Defining the contour
    contour = mcont(
    )
    #actions will contains the list of actions to pass to Magics
    actions = []
    # n is the number of filds in the fieldset
    for i in range(1, n) :
    	#Setting data
        grib = mgrib(grib_field_position = i,
              grib_input_file_name = "path/data.grib")
        actions.append(background)
        actions.append(grib)
        actions.append(contour)
    	# Add an page() action to create a new page
        actions.append(page())
    #Plotting
    plot(output, actions)


Info

To know the number of fields in your grib files, you can use the function grib_count of the grib_api package.

...

info

Content by Label
showLabelsfalse
max5
spaces~usa
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "kb-how-to-article" and type = "page" and space = "~usa"
labelskb-how-to-article

...