[ncl-talk] urgent issue about reading time series in each subarea of a shapefile

Mary Haley haley at ucar.edu
Thu Nov 29 18:14:43 MST 2018


It is still not quite clear to me what you are trying to do.

For example, why is the variable being called "pmask" on the file? The
original variable name is "dox", and I see that you also used "oxygen", so
wouldn't one of these be a better variable name?

You don't need a do loop in order to mask all the data across time steps.
Instead, create the 2D mask, and then you can apply this mask across your
4D dox variable using "conform_dims" to convert your 2D mask variable to a
4D mask variable:

   pmask2d    = shapefile_mask_data(dox(0,0,:,:),shp_fname,opt)

   pmask4d    = conform_dims(dox_dims,pmask2d,(/2,3/))
   dox_masked = mask(dox,pmask4d,1)

You could also create pmask4d with one line, but it's not as readable:

   pmask4d = conform_dims(dox_dims,
shapefile_mask_data(dox(0,0,:,:),shp_fname,opt),(/2,3/))

   dox_masked = mask(dox,pmask4d,1)

The dox_masked variable is now a 4D variable that you can write to a file.
No looping required.  See attached script.

--Mary


On Thu, Nov 29, 2018 at 11:18 AM Amal Inge <amalingenieur89 at gmail.com>
wrote:

> Thank you so much Prof!!You understood me perfectly!
>
> Last question, i made the loop just to add the time steps to the 2D mask
> and after i will concatenate them to have one nc file for all the time
> steps.
> Is there another way to have directly ncfile without passing by the loop
> and having ncfile for each time step?
> (this morning i made this ncfile attached but i didn't succeed to have the
> ncfile 4D)
>
> thanks again
> best regards
>
> Le jeu. 29 nov. 2018 à 18:10, Mary Haley <haley at ucar.edu> a écrit :
>
>> In the future, it would help if you tell us what you mean by the files
>> being wrong.  I had to run your script and look at different variables in
>> order to determine what exactly was wrong.
>>
>> It looks your "pmask" variable is all missing in each of the output files.
>>
>> It gets calculated correctly with these lines:
>>
>> ;---Create masked data array
>>
>>    pmask = where(oxygen.eq.1,f,f at _FillValue)
>>    copy_VarMeta(f,pmask)
>>
>> But then later, before "pmask" is written to a NetCDF file, it is reset
>> to a 4D array with missing values with this line:
>>
>>  pmask=new((/1,1,nlat,nlon/), float)
>>
>> pmask is never repopulated with values, and hence when it is written to
>> the file it is all missing.
>>
>> I think what you meant to do was convert pmask to a 4D array, where time
>> and depth each have one dimension, and then copy the 2D pmask to this new
>> 4D pmask array, correct?
>>
>> If so, then instead of the "new" command, you should create a new
>> variable, say "pmask4d", as follows:
>>
>>  pmask4d = reshape(pmask,(/1,1,nlat,nlon/))
>>  copy_VarAtts(pmask,pmask4d)    ; IMPORTANT, YOU MAY WANT TO ADJUST SOME
>>                                 ; ATTRIBUTES BEFORE WRITING TO FILE
>>   pmask4d!0         = "time"
>>   pmask4d!1         = "depth"
>>   pmask4d!2         = "latitude"
>>   pmask4d!3         = "longitude"
>>   pmask4d&time      = time
>>   pmask4d&depth     = lev
>>   pmask4d&latitude  = lat
>>   pmask4d&longitude = lon
>>
>> and then change "pmask" to "pmask4d" in all the code that follows that
>> writes stuff to the file. For example:
>>
>>    filevardef(fout, "pmask"    ,typeof(pmask4d)  ,getvardims(pmask4d))
>>
>>    filevarattdef(fout,"pmask",pmask4d)
>>
>>    fout->pmask      = (/pmask4d/)
>>
>> I've attached a modified version of your script.
>>
>> --Mary
>>
>>
>> On Thu, Nov 29, 2018 at 5:39 AM Amal Inge <amalingenieur89 at gmail.com>
>> wrote:
>>
>>> i want to have a time series from an ncfile (bbio.nc attached) for each
>>> subarea of a shapefilen(pic and zip attached)
>>> i tried the script attached newtest.ncl to do the mask and produce
>>> ncfile output for each time step
>>> but i get  wrong ncfiles
>>> could you help please?
>>>
>>>
>>>  bbio.nc
>>> <https://drive.google.com/file/d/1B0Y5bU6_hMcdYROmP4p-BJoGHUxo9FDH/view?usp=drive_web>
>>> _______________________________________________
>>> 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/20181129/84bec3f1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aa_mod.ncl
Type: application/octet-stream
Size: 7093 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181129/84bec3f1/attachment.obj>


More information about the ncl-talk mailing list