[ncl-talk] Shapefile_mask_data error

Christian Adrián Álvarez Báez christian.alvarez813 at gmail.com
Wed Oct 3 13:38:29 MDT 2018


Hi Mary,

I took your advice again and checked the shapefile with
print_shapefile_info  and that was the problem. The shapefile were on
different coordinates, my bad.

Thank you very much and so to Rick that helped me a lot understanding the
function.

On Tue, Oct 2, 2018 at 3:16 PM Mary Haley <haley at ucar.edu> wrote:

> I forgot to mention : please respond back to ncl-talk with all follow-up
> messages.
>
> Thanks,
>
> --Mary
>
>
> On Tue, Oct 2, 2018 at 2:15 PM, Mary Haley <haley at ucar.edu> wrote:
>
>> The way shapefile_mask_data works is that it makes a copy of your
>> original variable, and then it sets values in that new variable to missing
>> at locations where the lat/lon location falls outside the mask area of
>> interest. So, it is correct that what this function gives back is a
>> variable of the same size.
>>
>> I think what's going on is that it didn't find any lat/lon pairs from
>> your original data that fell inside the lat/lon area defined in your
>> shapefile.  This might happen because your two areas do not overlap, or if
>> your shapefile longitudes go from 0 to 360 and your data longitudes go from
>> -180 to 180 (or vice versa).
>>
>> I would first suggest that you make sure your shapefile area and your
>> data lat/lon area actually intersect. You can do this by using the
>> "print_shapefile_info" procedure mentioned at:
>>
>> http://www.ncl.ucar.edu/Applications/shapefiles.shtml
>>
>> and then simply using printMinMax to print your data's lat/lon min and
>> max:
>>
>> printMinMax(var at lat2d,0)
>> printminMax(var at lon2d,0)
>>
>> If the lat/lon areas don't intersect, then you will get back all missing
>> values.
>>
>> --Mary
>>
>>
>>
>>
>> On Tue, Oct 2, 2018 at 11:00 AM, Christian Adrián Álvarez Báez <
>> christian.alvarez813 at gmail.com> wrote:
>>
>>> Hi Mary,
>>>
>>> I took your advice and that made the code advance. I have tried before
>>> with setting "opt"  on
>>> data_keep = shapefile_mask_data(var,shp_filename,opt)
>>>
>>> but that sent me and error:
>>> ---- shapefile_mask_data : Error: The given variable name to use does
>>> not exist on the given shapefile.
>>> My only options are:
>>> ;---Set masking options for shapefile_mask_data function
>>> opt = True
>>> opt at shape_var = "NAME_1"
>>> opt at shape_names = "GOLFO"
>>> opt at debug = True
>>> opt at keep = True
>>> data_keep = shapefile_mask_data(var,shp_filename,opt)
>>>
>>> So I tried with just "True" and it worked, but I don't think that's ok
>>> because when I print min and max of the temperature on the data_keep, it
>>> says:
>>> (0)     Temperature (C) : min=9.96921e+36   max=9.96921e+36
>>>
>>> A print min and max over var would send me:
>>> (0)     Temperature (C) : min=1.26712   max=20.9307
>>>
>>> When I print a var summary on data_keep it let me know that
>>> shapefile_mask_data is not working (al least not how I expected) since it
>>> has the same size as the variable "var" before applying the mask even
>>> though the values are different as I said above:
>>> ---------------------------------
>>> Variable: var
>>> Type: float
>>> Total Size: 47124 bytes
>>>             11781 values
>>> Number of Dimensions: 2
>>> Dimensions and sizes:   [south_north | 119] x [west_east | 99]
>>> Coordinates:
>>> Number Of Attributes: 8
>>>   description : Temperature
>>>   coordinates : XLONG XLAT XTIME
>>>   stagger :
>>>   units :       C
>>>   MemoryOrder : XYZ
>>>   FieldType :   104
>>>   lon2d :       <ARRAY of 11781 elements>
>>>   lat2d :       <ARRAY of 11781 elements>
>>> --------------------------------
>>> Variable: data_keep
>>> Type: float
>>> Total Size: 47124 bytes
>>>             11781 values
>>> Number of Dimensions: 2
>>> Dimensions and sizes:   [south_north | 119] x [west_east | 99]
>>> Coordinates:
>>> Number Of Attributes: 9
>>>   description : Temperature
>>>   coordinates : XLONG XLAT XTIME
>>>   stagger :
>>>   units :       C
>>>   MemoryOrder : XYZ
>>>   FieldType :   104
>>>   lon2d :       <ARRAY of 11781 elements>
>>>   lat2d :       <ARRAY of 11781 elements>
>>>
>>> I think it has to do with the not using "opt" instead of just "True" but
>>> then I need to solve that "shapefile_mask_data : Error: The given variable
>>> name to use does not exist on the given shapefile" error first. Sorry for
>>> so much detail, but I just wanted to give the pieces of the puzzle.
>>>
>>> Thank you for your attention!
>>>
>>> On Mon, Oct 1, 2018 at 3:06 PM Mary Haley <haley at ucar.edu> wrote:
>>>
>>>> If I may jump in. This error:
>>>>
>>>> fatal:Argument type mismatch on argument (1) of (shapefile_mask_data)
>>>> can not coerce
>>>>
>>>>
>>>> is indicating that the second argument (argument count starts at 0) is
>>>> not the correct expected type.
>>>>
>>>> This argument is expecting the shapefile that's already been opened by
>>>> addfile, and not the name of the shapefile itself.
>>>>
>>>> For example:
>>>>
>>>>   shp_file  = "ne_10m_geography_regions_polys.shp"
>>>>   a         = addfile(shp_file,"r")
>>>>   opt = True
>>>> *  <...set possible "opt" options here...>*
>>>>   data_mask = shapefile_mask_data(data,shp_file,opt)
>>>>
>>>> --Mary
>>>>
>>>> On Fri, Sep 28, 2018 at 1:38 PM, Rick Brownrigg <brownrig at ucar.edu>
>>>> wrote:
>>>>
>>>>> Hmmm...that all looks about right. Have you done a
>>>>> printVarSummary(var)  to make sure that variable is what you think it is?
>>>>>
>>>>> Rick
>>>>>
>>>>> On Fri, Sep 28, 2018 at 1:01 PM Christian Adrián Álvarez Báez <
>>>>> christian.alvarez813 at gmail.com> wrote:
>>>>>
>>>>>> Hi, I'm triying to extract data with a mask from an WRF output using
>>>>>> the example shapefiles_19.ncl. I had many errors so looking I found some
>>>>>> modifications, including the shapefile_mask_data: Error: not a valid
>>>>>> rectilinear, curvilinear, or unstructured grid that I think it was solved
>>>>>> by using the copy_VarMeta function. But I'm stuck with the error:
>>>>>> fatal:Argument type mismatch on argument (1) of (shapefile_mask_data)
>>>>>> can not coerce
>>>>>> caused on line 60 of my script.
>>>>>> tc = wrf_user_getvar(a,"tc",it)
>>>>>> var=tc(0,:,:)
>>>>>> copy_VarMeta(tc,var)
>>>>>>
>>>>>> Line 60
>>>>>> data_keep = shapefile_mask_data(var,shp_filename,opt)
>>>>>>
>>>>>>
>>>>>> The script it's a little messy because of many modifications, I hope
>>>>>> I made sense. I don't know if the problem could be the shape, it's just a
>>>>>> simple polygon test projected on Lambert conformal conical as the WRF
>>>>>> output.
>>>>>>
>>>>>> I'm sending my script and my shape files if there is a clue.
>>>>>>
>>>>>> Thank you very much,
>>>>>> Christian
>>>>>> _______________________________________________
>>>>>> ncl-talk mailing list
>>>>>> ncl-talk at ucar.edu
>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181003/089c66b5/attachment.html>


More information about the ncl-talk mailing list