[ncl-talk] Using merged shapefiles to create PRISM data subset
Mary Haley
haley at ucar.edu
Thu Dec 20 09:41:35 MST 2018
Correct, but I wouldn't call it "subsetting" your data, as you are actually
masking it.
So, you can have all the counties in one big shapefile, or in individual
shapefiles. It's easier if it's in one, but it will work if it's in
several. You have to do a few extra steps if the counties are in several
shapefiles.
The shapefile_mask_data function loops through all the possible segments of
all features in a shapefile and checks every point in your data to see if
it's inside one of those segements. If it is, then it doesn't do anything
to that data location. If it isn't, then it sets that data location to
missing.
What you end up with, then, is a masked array of the same size as your
original data array, but with some values set to missing.
In the script I set you, instead of returning the masked data array, I
returned a special array of 0s and 1s that serves as a mask that you can
apply to your data. You could write this mask array to a file and then
read it in later to apply it to other data arrays that are the same size.
This will make things faster.
--Mary
On Wed, Dec 19, 2018 at 5:13 PM Toni Klemm <toni-klemm at tamu.edu> wrote:
> Hi Mary!
>
> Do you mean if I left the individual counties in the shapefile as separate
> features, then NCL wouldn’t have trouble subsetting my data?
>
> Thanks,
> Toni
>
>
>
> *Toni Klemm, Ph.D.*Postdoctoral Research Associate
> Department of Ecosystem Science and Management
> College of Agriculture and Life Sciences
> Texas A&M University, College Station, TX
> Contributor to the Early Career Climate Forum <http://www.eccforum.org>
> www.toni-klemm.de | @toniklemm <http://twitter.com/toniklemm>
>
>
>
>
>
>
>
>
> On Dec 19, 2018, at 5:06 PM, Mary Haley <haley at ucar.edu> wrote:
>
> Hi Toni,
>
> Your shapefile has just one feature and several segments for that
> feature. Usually the shapefiles we see have several features and several
> segments for each feature. Your shapefile is a little unusual, but not
> unheard of. Unfortunately, the examples we have all do the averaging
> across shapefile *features* and not shapefile *segments*.
>
> This doesn't mean you can't do it with NCL. See the attached plot, where
> I contoured some dummy 2D data over the area of interest and then generated
> a second plot where the values were averaged based on whether they fell
> inside one of these segments. Is this what you are trying to accomplish?
> If so, I'll clean up the code and send it to you.
>
> --Mary
>
> On Wed, Dec 19, 2018 at 1:26 PM Toni Klemm <toni-klemm at tamu.edu> wrote:
>
>> Hello All,
>>
>> I am trying to use a shapefile of merged counties in the western Great
>> Plains to create a spatial subset of temperature and precipitation data and
>> calculate averages and totals for those counties as a whole. However, the
>> data subset doesn't look anything like the shapefile (see the Panoply
>> screenshot). I attached the shapefile as GIS files and screenshot.
>>
>> My guess is that NCL gets confused about the disconnected-yet-combined
>> counties and doesn't know how to process a shapefile like that. Does anyone
>> know what I can do to make this work? Can I manipulate the shapefile data
>> in QGIS somehow so NCL understands it? Alternatively I could process each
>> county by itself and then average the results. But there are over 100
>> counties, which would take a very long time.
>>
>> I appreciate any help!
>>
>> Thank you very much,
>> Toni
>>
>>
>>
>> *Toni Klemm, Ph.D.*Postdoctoral Research Associate
>> Department of Ecosystem Science and Management
>> College of Agriculture and Life Sciences
>> Texas A&M University, College Station, TX
>> Contributor to the Early Career Climate Forum
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.eccforum.org&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=_wmxrfPQsMF3vojIFKRAtdhltlvptw6M4HZ9fLg_3cQ&e=>
>> www.toni-klemm.de
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.toni-2Dklemm.de&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=BUcEg1gjQSTNzMQTj8-c30-A9wVn4XtHJXwJ98GJFdc&e=>
>> | @toniklemm
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__twitter.com_toniklemm&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=4uj7i-TM4DYGnhfVvqE6_pSkQa5N6ZthvK0BCZWNzK8&e=>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=PmMsnjl-ihptp2YXVfcxUt782zRG1XbIMrqgS8bUQZg&e=>
>>
> <shapefile.000002.png>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181220/7588e420/attachment.html>
More information about the ncl-talk
mailing list