Re: regrid from ascii text

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Jun 13 2014 - 13:49:04 MDT

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
>> given is not in a neat deconstructed latxlon 1D array. That is, for any
>> gridcell that had 0 or NaN, the value was deleted or not outputted to th=
e
>> text file 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 clea=
n rectangle
>> and for rainfall, there are locations with 0 values that aren’t =
outputted
>> 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” gri=
d 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 wa=
s
>> written in you ascii file (i.e. lat values first or lon values first). O=
nce
>> 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 (a=
ll
>> lat/lon 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 throu=
gh
>> 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 array=
s)
>> for lat and lon values at 1km resolution and the corresponding data valu=
e
>> 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 “stre=
tches” the
>> data). Is there another simple yet better approach to take this data an=
d
>> 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 13 07:49:04 2014

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