masking out regions beyond the country boundary

21 views
Skip to first unread message

Tamirat Bekele

unread,
Oct 17, 2022, 7:43:08 AM10/17/22
to pycpt-esa
Dear Colleagues,

I hope we all arrived safely home.

Here is a snippet of code that could mask out regions beyond the country boundary.

#prepare a mask for your country
lats = np.arange(2.5,15.5,0.1)
lons = np.arange(32.5,48.5,0.1)

country = r'/home/jonyt/Desktop/ethiopiaONDJanalysis/shapefiles/eth_admbnda_adm0_csa_bofedb_itos_2021.shp'

eth = gp.read_file(country, crs=ccrs.PlateCarree())
#print(type(eth))
mask = regionmask.mask_geopandas(eth, lons, lats)

axis.contourf(lons,lats, np.where(mask,0,np.nan), cmap='Greys')

This code doesn't mask the actual data returned from pycpt-extra functions (i.e., pycpt view function); it overlays another plot on top of the original graph and hides regions beyond the country boundary. I will try to understand and work on the pycpt-extra functions side to implement the option for the actual masking of data.

best,
Tamirat

KEENNESS MANG'ANDA

unread,
Oct 17, 2022, 7:54:49 AM10/17/22
to Tamirat Bekele, pycpt-esa
Thanks Tamirat for this script, it will be very useful

Regards
Keenness Mang'anda
Principal Meteorologist

Department of climate change and Meteorological  services
P.O. Box 1808
Blantyre
Phone: (+265) 993 042 180
'''''''''''''''''''The Lord is my shepherd, I shall not want''''''''''''''''''''''''''''''''


--
You received this message because you are subscribed to the Google Groups "pycpt-esa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pycpt-esa+...@iri.columbia.edu.
To view this discussion on the web visit https://groups.google.com/a/iri.columbia.edu/d/msgid/pycpt-esa/84FDB08F-69AF-4842-B85B-48978721254B%40getmailspring.com.
For more options, visit https://groups.google.com/a/iri.columbia.edu/d/optout.

Tamirat Bekele

unread,
Oct 17, 2022, 8:50:04 AM10/17/22
to pycpt-esa
you are all welcome!

Tamirat B. Jimma
Addis Ababa University
On Oct 17 2022, at 3:48 pm, Tamirat Bekele <atomic...@gmail.com> wrote:
Hi Bohar,

I keep all the changes I made in the notebooks and share them with everyone later.

regards,

Tamirat B. Jimma
Addis Ababa University
On Oct 17 2022, at 3:18 pm, Bohar Singh <bo...@iri.columbia.edu> wrote:
Thanks Tamirat, 
Good work 

Keep taking note of the functionality that can added in the next version of PyCPTv2. 

Amanda Grossi

unread,
Oct 17, 2022, 8:53:07 AM10/17/22
to Tamirat Bekele, pycpt-esa
Thank you, Tamirat! You are a PyCPT rockstar. 



--

Amanda Grossi

AICCRA Project Senior Country Manager

Ethiopia, Senegal, Ghana, Kenya, Mali, Zambia

International Research Institute for Climate and Society
Earth Institute | Columbia University

 

(M) +1 702 688 0940 (S) amandagrossi55
https://iri.columbia.edu

    


Tamirat Bekele

unread,
Oct 17, 2022, 8:57:00 AM10/17/22
to Amanda Grossi, pycpt-esa
Oh...feeling excited! thanks Amanda

Tamirat B. Jimma
Addis Ababa University

Andrew Robertson

unread,
Oct 17, 2022, 9:02:46 AM10/17/22
to Tamirat Bekele, Amanda Grossi, pycpt-esa
Thanks Tamirat, that’s great! Last week we used many of your modifications for the West Africa training which was really helpful. FYI I put that Notebook on their wiki page:
Example Jupyter Notebook for West Africa

Let’s keep working together on this!
Andy


Jonas Zucule

unread,
Oct 17, 2022, 9:07:03 AM10/17/22
to Tamirat Bekele, pycpt-esa
Dear Tamirat;

Thank you for sharing the script and keeping the communication on.

Kind Regards.


            -------------------------------------------------------------     
                  Do not judge people about what they do
                   but from their heart and attitude.

                                             JZ            
                                             


Tamirat Bekele

unread,
Oct 17, 2022, 9:10:09 AM10/17/22
to Andrew Robertson, Amanda Grossi, pycpt-esa
Dear Andy,

You are welcome, Andy. I feel good to hear that my small contributions could help others. Sure, I will keep in touch with you and everyone.

regards,

Tamirat B. Jimma
Addis Ababa University

Tamirat Bekele

unread,
Oct 17, 2022, 10:42:38 AM10/17/22
to pycpt-esa
Dear Colleagues,

After discussing with friends via phone call, I realized that I forgot to mention the two modules you should import to use the code, i.e.,

import geopandas as pd
import  regionmask

If you don't have those packages, you can install them as follows:

conda install geopandas regionmask -c conda-forge

regards,

Tamirat B. Jimma
Addis Ababa University

Tamirat Bekele

unread,
Oct 17, 2022, 10:44:57 AM10/17/22
to pycpt-esa
Sorry for the typo.

import geopandas as gp

Tamirat B. Jimma
Addis Ababa University
Reply all
Reply to author
Forward
0 new messages