# (C) Copyright 1996-2016 ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. import Magics Magics.init() Magics.setc("output_format", "ps") Magics.setc("output_name", "using_python01") Magics.setc("grib_input_type", "file") Magics.setc("grib_input_file_name", "data/z500.grb") Magics.grib() Magics.setc("map_coastline_colour", "khaki") Magics.setc("map_grid_colour", "grey") Magics.setc("contour", "on") Magics.setc("contour_line_colour", "sky") Magics.setc("contour_highlight_colour", "red") Magics.setc("contour_label", "on") Magics.cont() Magics.text() Magics.coast() Magics.new_page("super_page")
# -*- coding: utf-8 -*- import Magics import numpy import math dx = 1.5 dy = -1.5 def f(y,x): yy= 90.+y*dy xx=-180.+x*dx return xx + yy Magics.init () Magics.setc("output_format","ps") Magics.setc("output_name", "py_arrays") Magics.setr("INPUT_FIELD_INITIAL_LATITUDE",90.0) Magics.setr("INPUT_FIELD_INITIAL_LONGITUDE",-180.0) Magics.setr("INPUT_FIELD_LATITUDE_STEP",dy) Magics.setr("INPUT_FIELD_LONGITUDE_STEP",dx) NLON = 240 NLAT = 121 FIELD = numpy.fromfunction(f,(NLAT,NLON),dtype=numpy.float64) Magics.set2r("INPUT_FIELD",FIELD) #Magics.setr("INPUT_FIELD_INITIAL_LONGITUDE",-180.)
import sys from .convertions import convert # This is needed when running Sphinx on ReadTheDoc try: from Magics import macro except Exception as e: print(e, file=sys.stderr) macro = None try: import Magics Magics.strict_mode() except Exception as e: print(e, file=sys.stderr) LOG = logging.getLogger(__name__) class Action: default_style: object = None def __init__(self, **kwargs): self.kwargs = kwargs def __repr__(self): x = ["macro.%s(" % (self.action, )]
# (C) Copyright 1996-2016 ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. import Magics Magics.init() Magics.setc("output_format", "svg") Magics.setc("output_name", "python_simple") Magics.setr("SUBPAGE_LOWER_LEFT_LATITUDE", 30.0) Magics.setr("SUBPAGE_LOWER_LEFT_LONGITUDE", -30.0) Magics.setr("SUBPAGE_UPPER_RIGHT_LATITUDE", 65.0) Magics.setr("SUBPAGE_UPPER_RIGHT_LONGITUDE", 70.0) Magics.setc("grib_input_file_name", "../data/z500.grb") Magics.grib() Magics.setc("map_coastline_colour", "khaki") Magics.setc('map_coastline_land_shade', 'on') Magics.setc('map_coastline_land_shade_colour', 'tan') Magics.setc('map_coastline_sea_shade', 'on') Magics.setc('map_coastline_sea_shade_colour', 'sky') Magics.setc('map_boundaries', 'on') Magics.setc('map_boundaries_colour', 'white') Magics.setc('map_disputed_boundaries', 'on') Magics.setc('map_disputed_boundaries_colour', 'red') Magics.setc('map_cities', 'on')
# does it submit to any jurisdiction. import Magics import numpy taxis_key = 'andate' taxis_values = [ "2011-09-01 00:00", "2011-10-01 00:00", "2011-11-01 00:00", "2011-12-01 00:00", "2012-01-01 00:00", "2012-02-01 00:00", "2012-03-01 00:00", "2012-04-01 00:00" ] tseries_key = 'meanobsvalue' tseries_values = numpy.array([4.0, 25.5, 6.8, 2., 12.4, 8.9, 3.2, 5.3]) Magics.init() Magics.set1c("output_format", ['png', 'ps']) Magics.setc("output_name", "axis_python") Magics.setr('subpage_y_position', 2.0) Magics.setc('subpage_map_projection', 'CARTESIAN') Magics.setc('axis_orientation', 'HORIZONTAL') Magics.setc('axis_type', 'DATE') Magics.setc('axis_date_type', 'months') Magics.setc('axis_date_min_value', '2011-08-01 00:00') Magics.setc('axis_date_max_value', '2012-08-01 00:00') Magics.setr('axis_tick_interval', 1.) Magics.setc('axis_title_text', taxis_key) Magics.axis()
#!/usr/bin/env python import Magics as Magics import numpy import math def f(x, y): # return ((math.sin((x-180.)/(2.*math.pi)))-(math.cos((y-90.)/(2.*math.pi)))) # return ( (x-180.) + (y-90.)*3 ) return (y - 90.) Magics.init() Magics.setc("output_format", "ps") Magics.setc("output_name", "py_arrays") Magics.setr("INPUT_FIELD_INITIAL_LATITUDE", 90.0) Magics.setr("INPUT_FIELD_INITIAL_LONGITUDE", 0.0) Magics.setr("INPUT_FIELD_LATITUDE_STEP", -1.5) Magics.setr("INPUT_FIELD_LONGITUDE_STEP", 1.5) NLON = 360 NLAT = 180 FIELD = numpy.fromfunction(f, (NLAT, NLON), dtype=numpy.float64) Magics.set2r("INPUT_FIELD", FIELD, 360, 180) Magics.setr("INPUT_FIELD_INITIAL_LONGITUDE", -180.) Magics.setr("INPUT_FIELD_INITIAL_LATITUDE", 90.) Magics.setr("INPUT_FIELD_LONGITUDE_STEP", 1.)
import Magics as ma import numpy as np ma.init() ma.setr("subpage_y_position", 2.) ma.setc("subpage_map_projection", 'cartesian') ma.setc("subpage_x_axis_type", 'date') ma.setc("subpage_y_axis_type", 'regular') ma.setc("subpage_x_date_min", "2012-03-01 12:00:00") ma.setc("subpage_x_date_max", "2012-03-03 12:00:00") ma.setr("subpage_x_min", 25.) ma.setr("subpage_x_max", 75.) ma.setr("subpage_y_min", 25.) ma.setr("subpage_y_max", 75.) ma.setc("axis_orientation", "vertical") ma.setc("axis_type", "regular") ma.setc("axis_tick_label_colour", 'navy') ma.setc("axis_grid", "on") ma.setc("axis_grid_colour", "grey") ma.setc("axis_grid_line_style", "dot") ma.setr("axis_tick_label_height", 0.4) ma.seti("axis_grid_thickness", 1) ma.axis() ma.setc("axis_orientation", "horizontal") ma.setc("axis_type", "date") ma.setc("axis_grid", "on") ma.setr("axis_days_label_height", 0.40) ma.setr("axis_months_label_height", 0.40)
# (C) Copyright 1996-2016 ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. import Magics from numpy import * Magics.init() formats = ["pdf", "PNG", "ps"] Magics.set1c("output_formats", formats) Magics.setc("output_name", "shading_py") colour = ["NAVY", "BLUE", "CYAN", "GREEN", "YELLOW", "ORANGE", "RED", "PURPLE"] level = array([480., 490., 500., 530., 545., 560., 575., 590., 600.]) markers = array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int32) print markers.dtype test = array([450., 515., 530.]) Magics.setc("legend", "on") Magics.setc("map_coastline_colour", "grey") Magics.setc("map_grid_colour", "grey") # pass the data to Magics Magics.setc("grib_input_type", "file")
import Magics as ma ma.init() ma.setr("subpage_lower_left_latitude", 40.) ma.setr("subpage_lower_left_longitude", -20.) ma.setr("subpage_upper_right_latitude", 65.) ma.setr("subpage_upper_right_longitude", 10.) ma.setc("grib_input_file_name", "../test/data.grib") ma.grib() ma.cont() ma.coast() #print ma.enqr("subpage_lower_left_latitude") ma.new_page("page") ma.reset("subpage_lower_left_latitude") ma.reset("subpage_lower_left_longitude") ma.coast() #print ma.enqr("subpage_lower_left_latitude") ma.info() ma.finalize()
def plotData(): # # G R I B A P I # f = open(INPUT) gid = gribapi.grib_new_from_file(f) values = gribapi.grib_get_values(gid) # print values.dtype # print values.shape Ni = gribapi.grib_get(gid, 'Ni') Nj = gribapi.grib_get(gid, 'Nj') print 'GRIB_API: %d (%dx%d=%d) values found in %s' % (len(values), Nj, Ni, Nj * Ni, INPUT) latitudeOfFirstGridPointInDegrees = gribapi.grib_get( gid, 'latitudeOfFirstGridPointInDegrees') longitudeOfFirstGridPointInDegrees = gribapi.grib_get( gid, 'longitudeOfFirstGridPointInDegrees') latitudeOfLastGridPointInDegrees = gribapi.grib_get( gid, 'latitudeOfLastGridPointInDegrees') longitudeOfLastGridPointInDegrees = gribapi.grib_get( gid, 'longitudeOfLastGridPointInDegrees') jDirectionIncrementInDegrees = gribapi.grib_get( gid, 'jDirectionIncrementInDegrees') iDirectionIncrementInDegrees = gribapi.grib_get( gid, 'iDirectionIncrementInDegrees') # for key in ('max','min','average'): # print ' %s=%.10e' % (key,gribapi.grib_get(gid,key)) gribapi.grib_release(gid) f.close() # # M A G I C S # Magics.init() Magics.setc("OUTPUT_FORMAT", "ps") Magics.setc("OUTPUT_NAME", "py_arrays_from_grib") Magics.setr("INPUT_FIELD_INITIAL_LATITUDE", latitudeOfFirstGridPointInDegrees) Magics.setr("INPUT_FIELD_INITIAL_LONGITUDE", longitudeOfFirstGridPointInDegrees) Magics.setr("INPUT_FIELD_LATITUDE_STEP", -jDirectionIncrementInDegrees) Magics.setr("INPUT_FIELD_LONGITUDE_STEP", iDirectionIncrementInDegrees) values2 = numpy.array(values - 273.15) # convert degree K to C # print values2.dtype # print values2.shape val = values2.reshape(Nj, Ni) # print val.dtype # print val.shape Magics.set2r("INPUT_FIELD", val) # Magics.setc ("contour_grid_value_plot", "on") # Magics.setc ("contour_grid_value_plot_type", "value") # Magics.seti ("contour_grid_value_lat_frequency", 8) # Magics.seti ("contour_grid_value_lon_frequency", 8) # Magics.setr ("contour_grid_value_height", 0.3) # Magics.setc ("contour", "off") Magics.cont() Magics.coast() Magics.finalize()