Re: regrid from ascii text

From: Maria Gehne - NOAA Affiliate <maria.gehne_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 11 2014 - 15:49:37 MDT

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.co=
m
> 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
>
>
>

Received on Wed Jun 11 09:50:13 2014

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