Dear CDS team,

I have a 4D variable in the Toolbox (Tropospheric Humidity Profiles). How do I make a geomap or pcolormesh using x=latitude and y=height?

how do I select a center of desired map domain, analog to the Basemap lon_0 or lat_0?


<xarray.DataArray 'hus' (time: 1, height: 251, lat: 36, lon: 1)>

dask.array<shape=(1, 251, 36, 1), dtype=float32, chunksize=(1, 251, 36, 1)>


Thanks and kind regards,

Alex Bobryshev

7 Comments

  1. Dear Alex,

    To define which dimensions should be considered as the 'x' and 'y' axes of the geomap you should use the pcolormesh_kwargs argument.

    fig = ct.cdsplot.geomap(
        data,
    	pcolormesh_kwargs = {
            'x': 'lat',
            'y': 'height',
        }
    )

    You can find all the keyword you can use in pcolormesh_kwargs here http://xarray.pydata.org/en/stable/generated/xarray.plot.pcolormesh.html.

    Regarding the centering the map around a specific lat and lon I can't think of anything just now. Will have a think about it. You could select an area centered around the lat lon you want and then plot it but that's not quite what you want.

    Let me know how you get on and if you send me your workflow I can try things out with the data you use.

    Regards.

    Vivien

  2. Dear Vivien,

    here is a code for the 4D variable plot generation. With this code I get an empty rectangular, a colorbar that goes from 0.002 to 0.016 and a title.

    import cdstoolbox as ct
    
    layout = {
        'input_ncols': 1,
        'output_align': 'bottom'
    }
    
    @ct.input.dropdown('variable', label='Variable', values=['brokered'])
    
    @ct.application(title='Tropospheric Humidity Profiles', layout=layout)
    @ct.output.figure()
    
    def application(variable, month, year):
        
        data = ct.catalogue.retrieve(
            'satellite-humidity-profiles',
            {
            'variable':'all',
            'product_type':'observed_ro_data',
            'year':'2017',
            'month':'02'
            })
        
        fig = ct.cdsplot.geomap(data,
                pcolormesh_kwargs={
                    'x':'lat',
                    'y':'height',
                }
                               
            )
        return fig
    


    Regarding the centering a map question. My motivation is to plot the global data, but center it around the longitude=180 (Pacific Ocean). I attach the code for the precipitation plot below. I am using the PlateCarree projection to make the map rectangular. Also, I don't understand why the ylabel is wrong and how do I control the title of the plot (now it is in the top left corner far away from the plot).


    import cdstoolbox as ct
    
    layout = {
        'input_ncols': 1,
        'output_align': 'bottom'
    }
    
    @ct.input.dropdown('variable', label='Variable', values=['total_precipitation'])
    
    @ct.application(title='Average Precipitation', layout=layout)
    @ct.output.figure()
    
    def application(variable,):
        
        request=['reanalysis-era5-single-levels-monthly-means',
                {
            'format':'grib',
            'product_type':'monthly_averaged_reanalysis',
            'variable':'total_precipitation',
            'year':['%04d'%(year) for year in range(2014,2016)],
            'month':['%02d'%(mnth) for mnth in range(1,13)],
            'time':'00:00'
                }]
    
        data = ct.catalogue.retrieve(*request)
        gdd_map = ct.cube.average(data, 'time')
    
        fig = ct.cdsplot.geomap(gdd_map,
            left=0.08, right=0.97, bottom=0.2, top=0.96,
            pcolormesh_kwargs={
                'cmap': 'YlGnBu','vmin':0, 'vmax':50,
                'cbar_kwargs':{
                    'orientation': 'vertical', 'shrink': 0.6,
                    'extend':'max', 'pad':0.05,
                    },
                'xticks':[0,60,120,-60,-120],
                'yticks':[0,60,-60],
                },
            coastlines_kwargs={'linewidth':0.4, },
            title='Average precipitation',
            projection=ct.cdsplot.crs.PlateCarree(),
            #xlabel='', ylabel='latitude',
            )
        return fig

    Non-related question, how do I insert my code in the nice rectangular block?

    Kind regards,

    Alex

  3. Dear Alex,

    Regarding your question on how to center a map on a specific longitude geomap uses Cartopy in the background and here is an example of how to do it.

    fig = ct.cdsplot.geomap(
        data,
        projection=ct.cdsplot.crs.Robinson(central_longitude=80.0)
    )

    Note that you can also choose the projection this way. The way to choose the central longitude might change from one projection to the other. Projections an their parameters are documented here: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#robinson

    For the Robinson projection you can also set a false easting and false northing.

    Here is an example of application you can run to see how the map changes.

    import cdstoolbox as ct
    
    @ct.application(title='Plot Map')
    @ct.output.figure()
    def plot_map():
        
        data = ct.catalogue.retrieve(
            'reanalysis-era5-single-levels',
            {
                'variable': '2m_temperature',
                'product_type': 'reanalysis',
                'year': '2010',
                'month': '08',
                'day': '15',
                'time': '12:00',
            }
        )
    
        fig = ct.cdsplot.geomap(
            data,
            projection=ct.cdsplot.crs.Robinson(central_longitude=80.0)
        )
    
        return fig




  4. To insert code in confluence go to  > Other macros > Search for code > Choose "Code block"

    I didn't get what the problem with xlabel and ylabel is, once I commented them back in they worked fine.

    The title has been taken out of the figure to have more consistent outputs, I am not sure if there is a way to center it.

  5. Yes, now the central longitude works exactly as I want to. And thanks for pointing out the documentation page with the list of parameters!

    The ylabel now says 'Total precipitation rate', and not 'the latitudes [degrees _norths]'

  6. Dear CDS-Team,


    my question is related to the first one in terms of selecting/switching the x- and y-axis. But this time with a simple 2D "ct.chart.line".

    The Code is about the zonal average of a parameter and it would obviously look better to have the "Latidude" as y-axis and the zonal-averaged-parameter as x-axis.

    Is there a similar way to the mentioned solution with some keywords? Didn't found it so far :/


    Thanks in advance and have a nice weekend!

    Tim

    import cdstoolbox as ct
    
    @ct.application()
    @ct.output.livefigure()
    
    def application():
        precipitation = ct.catalogue.retrieve(
            'reanalysis-era5-land-monthly-means',
            {
                'product_type': 'monthly_averaged_reanalysis',
                'variable': '2m_temperature',
                'year': '2002',
                'month': '06',
                'time': '00:00',
            }
        )    
              
        precipitation_mean = ct.cube.average(precipitation, dim='lon')
    
        fig  = ct.chart.line(precipitation_mean)    
           
        return fig
    
    
    
  7. Hello Guys,


    has anyone made progress here and maybe knows a solution to share with me/other users?

    Kind regards,
    Tim