[ncl-talk] Issue to fill delimited area (using a shapefile) with a constant value
Thierno Doumbia
elthiedo at gmail.com
Tue Jun 23 01:10:10 MDT 2020
Hi Rick and ncl-users,
I realized that my code below provides the cumulative sum,
whereas I just want to record the values of each area listed in
"opt at shape_name" in a single variable.
If you or someone else could help me to avoid this cumulative sum, I would
appreciate it.
... below is part of the code I had attached in my first post
...
;-- Open and read data off the shapefile
dirShapf = "./"
shp_name = "gadm36_1.shp"
shp_path = dirShapf+shp_name
;print_shapefile_info(shp_path)
ratio_mask = sample
;-- Put trend values to the areas that I don't want masked
;get the size of the lat/lon grid of variable data
iNumlat = dimsizes(sample&latitude)
iNumlon = dimsizes(sample&longitude)
; Create a new variable to put in the daily trends for each region
; and fill the other grids with the value 1.
;maskedRatio = new((/iNumlat,iNumlon/),float,sample at _FillValue)
;copy_VarMeta(ratio_mask, maskedRatio)
maskedRatio = ratio_mask
maskedRatio = 0
;-- Loop over the country/region/province
do ir=0,dimsizes(reg_names)-1
vname = reg_names(ir)
print("region ="+vname)
;print(vtrend(62,ir)/100.)
;set masking options
opt = True
opt at keep = True
opt at shape_var = "NAME_1"
opt at shape_names = (/vname/)
opt at return_mask = True
;opt at debug = True
;mask the sample data by country/region/province
ratio_mask = ratio_mask +
(/shapefile_mask_data(sample,shp_path,opt)/)
copy_VarMeta(sample, ratio_mask)
do j=0,iNumlat-1
do i=0,iNumlon-1
if ((.not.ismissing(ratio_mask(j,i))).and.(ratio_mask(j,i) .eq.
1)) then
maskedRatio(j,i) = maskedRatio(j,i) + vtrend(62,ir)/100.
end if
end do
end do
end do ; end looping over the list of string names in "shape_names"
printMinMax(maskedRatio, True)
...
Sincerely,
Thierno
Le sam. 20 juin 2020 à 21:16, Thierno Doumbia <elthiedo at gmail.com> a écrit :
> Thank you Rick, the initialization of the two variables was missing.
>
> Thierno
>
> Le ven. 19 juin 2020 à 23:07, Rick Brownrigg <brownrig at ucar.edu> a écrit :
>
>> I don't know for certain. If the regions are not overlapping, what about
>> initializing "data" and "data_mask" to zero and then simply adding the loop
>> results back into those variable each time? Something like
>>
>> data = data + (/shapefile_mask_data(dgrid_fs,shp_path,opt)/)
>> ...
>> data_mask(j,i) = data_mask(j,i) + vtrend(0,ir)/100.
>>
>> Rick
>>
>>
>> On Fri, Jun 19, 2020 at 1:24 PM Thierno Doumbia <elthiedo at gmail.com>
>> wrote:
>>
>>> Hi,
>>> If that is exactly what I done, it was not what I wanted. In this case
>>> how do I get a single variable containing data for all regions ?
>>>
>>> Thank you
>>> Thierry
>>>
>>> Le ven. 19 juin 2020 à 20:53, Rick Brownrigg <brownrig at ucar.edu> a
>>> écrit :
>>>
>>>> Hi,
>>>>
>>>> If I read the script correctly, it looks like you are looping over
>>>> region names and over writing the variables "data" and "data_mask" each
>>>> time through. Then the plot is generated after the loop has terminated --
>>>> the values of data and data_mask would contain the last region.
>>>>
>>>> ??
>>>> Rick
>>>>
>>>>
>>>> On Fri, Jun 19, 2020 at 12:23 PM Thierno Doumbia via ncl-talk <
>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>
>>>>> Dear NCL community,
>>>>>
>>>>> As indicated in the subject line of this mail, I have a problem to
>>>>> create a gridded netcdf file containing constant values for different
>>>>> regions of the globe, using world administrative boundaries shapefile as a
>>>>> mask.
>>>>> My code seems to be working for one region. But when I try to loop
>>>>> through multiple regions, the result is not what I expected. Please find
>>>>> attached my code, the obtained plot and a sample of my data.
>>>>>
>>>>> I would appreciate it if you would check to see what I have done
>>>>> wrong.
>>>>>
>>>>> Sincerely,
>>>>> --
>>>>> Thierry
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at mailman.ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
--
DOUMBIA Thierno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200623/fef631d3/attachment.html>
More information about the ncl-talk
mailing list