Fwd: [ncl-talk] regrid from ascii text

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Jun 20 2014 - 14:30:19 MDT

I just tried to use triple2grid, but I didn't realize that it actually
tries to fill up every grid point of a rectilinear grid? Is that correct?
 I was expecting a grid with some missing values.

--Mary

---------- Forwarded message ----------
From: Mary Haley <haley@ucar.edu>
Date: Thu, Jun 19, 2014 at 4:08 PM
Subject: Re: regrid from ascii text
To: "Marcella, Marc" <MMarcella@air-worldwide.com>
Cc: Maria Gehne - NOAA Affiliate <maria.gehne@noaa.gov>


Yes, triple2grid will not interpolate values. See example narr_3.ncl at:

http://www.ncl.ucar.edu/Applications/narr.shtml#ex3

I'll try to come up with a better example. This one is not truly random
data, as it is converting a 2D array to 1D.

--Mary


On Wed, Jun 18, 2014 at 2:44 PM, Marcella, Marc <MMarcella@air-worldwide.co=
m
> wrote:

> Great, thanks Mary!
>
> Ill look into this. I definitely don’t want to interpolate/fill =
the
> values. Id be happier if I had FV/NaN at the points/grid cells where the
> data has no values. Would triple2grid do this?
>
>
>
> -Marc
>
>
>
>
>
> *From:* Mary Haley [mailto:haley@ucar.edu]
> *Sent:* Friday, June 13, 2014 3:49 PM
> *To:* Marcella, Marc
> *Cc:* ncl-talk@ucar.edu; Maria Gehne - NOAA Affiliate
>
> *Subject:* Re: [ncl-talk] regrid from ascii text
>
>
>
> Hi Marc,
>
>
>
> What Maria suggests sounds like a good idea. It just depends on whether
> you want to actually interpolate the values to the new grid, or simply
> place them on the new grid.
>
>
>
> I would look at the triple2grid function, which places the values at the
> nearest location of the given lat/lon grid, and then you can also use
> poisson_grid_fill to fill in the missing values if desired.
>
>
>
> See the follow page for some examples of this:
>
>
>
> http://www.ncl.ucar.edu/Applications/grid_fill.shtml
>
>
>
> If you want to interpolate the values, then you can use the unstructured
> method in ESMF_regrid, but this method may work better if you are able to
> provide grid corners as well. You can give it a try and see if it's
> acceptable. See example ESMF_regrid_21.ncl at:
>
>
>
> http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex21
>
>
>
> which does something similar to what you have.
>
>
>
> --Mary
>
>
>
>
>
> On Wed, Jun 11, 2014 at 3:49 PM, Maria Gehne - NOAA Affiliate <
> maria.gehne@noaa.gov> wrote:
>
> Hi Marc,
>
>
>
> I see what your problem is now. Unfortunately I don't have a better idea
> than you. I would probably go through and fill in the missing values so
> that you end up with a nice 2D array. Those are much easier to handle.
>
>
>
> Sorry for not being able to help, hopefully someone else on the list has
> an idea!
>
>
>
> Maria
>
>
>
> On Tue, Jun 10, 2014 at 4:16 PM, Marcella, Marc <
> MMarcella@air-worldwide.com> wrote:
>
> Hi Maria,
>
>
> Thank you very much for your response and taking the time to write back; =
I
> initially was going to go that route. Unfortunately, the data I was giv=
en
> is not in a neat deconstructed latxlon 1D array. That is, for any gridce=
ll
> that had 0 or NaN, the value was deleted or not outputted to the text fil=
e
> to save space (ugh). Apologies for not being clear about that initially.
>
>
>
> As a result, I have (for one time step) for the country of Bangladesh,
> data for population and rainfall from an event (two separate text files,
> both with the corresponding lat/lon values). So neither dataset is a
> simple rectangle, since for population, the country isn’t a clean=
 rectangle
> and for rainfall, there are locations with 0 values that aren’t o=
utputted
> to the text file. I was thinking of going back and “filling=
in the 0/NaN
> values with FillValues, but thought that could get a bit messy to code.
> So, I thought using something like an “unstructured” grid=
 in ESMF_regrid
> may do the trick. Did you happen to have any ideas?
>
>
>
> Thanks again!
>
> Marc
>
>
>
>
>
>
>
> *From:* Maria Gehne - NOAA Affiliate [mailto:maria.gehne@noaa.gov]
> *Sent:* Tuesday, June 10, 2014 3:54 PM
> *To:* Marcella, Marc
> *Cc:* ncl-talk@ucar.edu
> *Subject:* Re: [ncl-talk] regrid from ascii text
>
>
>
> Hi Marc,
>
>
>
> I'm not sure I understand what exactly you are trying to do. Do you want
> to read in the ascii data and turn it into a 2D array with lat and lon
> dimension attached? In order to do that you need to know how the data was
> written in you ascii file (i.e. lat values first or lon values first). On=
ce
> you know that you can read in the whole ascii file using
>
>
>
> data1D = asciiread("asciifile",-1,"float")
>
>
>
> (assuming your data format is float, otherwise replace with the correct
> format).
>
>
>
> Then you can use the onedtond function to turn the 1D array into your 2D
> array:
>
>
>
> data = onedtond(data1D,(/nlat,nlon/))
>
>
>
> or
>
>
>
> data = onedtond(data1D,(/nlon,nlat/))
>
>
>
> depending on how your data was written.
>
>
>
> After that you just need to attach the dimension arrays lat and lon:
>
>
>
> data!0 = "lat"
>
> data&lat = lat
>
> data!1 = "lon"
>
> data&lon = lon
>
>
>
> Note: this assumes your ascii file only contains one time step (you didn'=
t
> say if it has one or more). If you have more than one you need to figure
> out how many time steps are in the file. How they were written (all lat/l=
on
> values for one time step together and then the next time step?) And then
> you can make a 3D array of size (/ntim,nlat,nlon/) by looping through the
> number of time steps for example.
>
>
>
>
>
> Hope this helps,
>
>
>
> Maria
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Mon, Jun 9, 2014 at 2:57 PM, Marcella, Marc <
> MMarcella@air-worldwide.com> wrote:
>
> Hi all,
>
>
>
> I have an ascii file that was basically written out from a 1km gridded
> dataset to this said text file. I am trying to “reconstruct=
the data and
> put it back on a 2D grid. The text file has the corresponding (1D arrays=
)
> for lat and lon values at 1km resolution and the corresponding data value
> at that point. What is the best technique to put this back on a 2d grid?
> I tried following the ESMF_regrid data example for “unstructured=
” data, but
> the results look a little bit off (i.e. the regrid fills in the data for
> locations where the value should be NaN which subsequently “stret=
ches” the
> data). Is there another simple yet better approach to take this data and
> place it on a regular grid to map in NCL?
>
>
>
> Thank you for the help in advance!
>
>
>
> Marc
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>

Received on Fri Jun 20 08:30:19 2014

This archive was generated by hypermail 2.1.8 : Wed Jul 23 2014 - 15:33:46 MDT