[ncl-talk] How to combine many separate nc files together and convert them to monthly?

Setareh Rahimi setareh.rahimi at gmail.com
Tue Jun 28 17:47:35 MDT 2022


Dear Dennis,
So many thanks for your help. I could finally run the script successfully.
I attached the script and the plot. However, I would like to set the title
of the plot as "NDVI average from 2021-03-03 to 2021-03-12"
But this title overlaps with the main title of the file. How can I remove
the original title, please?
So many thanks for the time you allocate to check my request.
Best wishes,


On Wed, Jun 29, 2022 at 12:57 AM Dennis Shea <shea at ucar.edu> wrote:

> The file you sent,
>
> VIIRS-Land_v001-preliminary_NPP13C1_S-NPP_20210312_c20220419124706.nc
>
> does not have a problem.
>
> As you requested, I ran *https://www.ncl.ucar.edu/Applications/Scripts/ndvi_3.ncl
> <https://www.ncl.ucar.edu/Applications/Scripts/ndvi_3.ncl>*
> on the file you sent*, I*t is appended.
>
> %> ncl  setareh_VIIRS.ncl
>
> As you requested, I ran the script  on the VIIRS file. It ran
> successfully. The png is attached.
> I think it would be best to send help requests to ncl-talk.
> Maybe others can see issues that I am not seeing.
>
> Regards
> Dennis
>
>
>
> On Tue, Jun 28, 2022 at 1:42 PM Setareh Rahimi <setareh.rahimi at gmail.com>
> wrote:
>
>> Dear Dennis,
>> I tried to plot NDVI for a specific day, hence 12 March 2021 using the
>> file available at :
>> https://www.ncl.ucar.edu/Applications/Scripts/ndvi_3.ncl
>> However, I got an error again. It seems that there is a problem with the
>> file. I attached the error message and the nc file. May I ask you please to
>> run the script for this data?
>> I need to make sure that the file is damaged.
>> Thanks in advance,
>>  VIIRS-Land_v001-preliminary_NPP13C1_S-NPP_20210...
>> <https://drive.google.com/file/d/12H5UHVPVoQisuBgo62hs4-66_B7OVXS_/view?usp=drive_web>
>>
>> On Tue, Jun 28, 2022 at 11:35 PM Dennis Shea <shea at ucar.edu> wrote:
>>
>>> These messages do not even look like NCL error messages.
>>>
>>> If you entered the following at the command line and got those messages,
>>> NCL in not involved.:
>>>
>>> %>  ls [1-2][8-9-0-1]*/*nc
>>>
>>> I'm not sure what to suggest.
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Jun 28, 2022 at 12:59 PM Setareh Rahimi <
>>> setareh.rahimi at gmail.com> wrote:
>>>
>>>> Dear Dennis,
>>>> Thanks again for your advice. I did as you suggested and again got an
>>>> error. (attached)
>>>> Why should I receive this message, please?
>>>> ================================================
>>>> ncattname: ncid 23986176: NetCDF: Variable not found
>>>> ncattname: ncid 23986176: NetCDF: Variable not found
>>>> ncattname: ncid 23986176: NetCDF: Variable not found
>>>> ncattname: ncid 23986176: NetCDF: Variable not found
>>>> ncattname: ncid 23986176: NetCDF: Variable not found
>>>> file: NclNetCDF4.c, line: 2493
>>>>
>>>> We Thought It Was Compound Data, But NOT.
>>>> ================================================
>>>>
>>>> On Tue, Jun 28, 2022 at 11:23 PM Dennis Shea <shea at ucar.edu> wrote:
>>>>
>>>>> NCL's *systemfunc* is invoking the Unix/Linux system 'ls'. It is
>>>>> *independent* of NCL.
>>>>>
>>>>> From directory your NCL script is located, enter the following at the
>>>>> command line:
>>>>>
>>>>> %>  ls [1-2][8-9-0-1]*/*nc
>>>>>
>>>>>
>>>>> On Tue, Jun 28, 2022 at 11:46 AM Setareh Rahimi <
>>>>> setareh.rahimi at gmail.com> wrote:
>>>>>
>>>>>> Dear Dennis,
>>>>>> Many thanks for your email. I run the attached script and received
>>>>>> the attached error.
>>>>>> What is wrong, please?
>>>>>>
>>>>>> On Tue, Jun 28, 2022 at 10:07 PM Dennis Shea <shea at ucar.edu> wrote:
>>>>>>
>>>>>>> As indicated before, your path is wrong.
>>>>>>> ====
>>>>>>> The attached works just fine.
>>>>>>>
>>>>>>> %>  ncl NDVI_TimeSeries.ncl >&! NDVI.Daily_to_Monthly.txt
>>>>>>>
>>>>>>> On Tue, Jun 28, 2022 at 10:25 AM Setareh Rahimi via ncl-talk <
>>>>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>>>>
>>>>>>>> Dear all,
>>>>>>>>
>>>>>>>> I have downloaded the Normalized Difference Vegetation Index
>>>>>>>> (NDVI), from the Advanced Very High-Resolution Radiometer (AVHRR) sensor
>>>>>>>> from the link below:
>>>>>>>>
>>>>>>>> https://www.ncei.noaa.gov/metadata/geoportal/rest/metadata/item/gov.noaa.ncdc:C01558/html
>>>>>>>>
>>>>>>>> As you can see this link provides daily data. And I have downloaded
>>>>>>>> daily data from 1986 to 2021. I put the daily data for each year in a
>>>>>>>> separate folder.
>>>>>>>> Now I tend to calculate the monthly anomaly of NDVI and do not know
>>>>>>>> how to combine all these files.
>>>>>>>>
>>>>>>>> I used the below commands to call the files:
>>>>>>>> ========================================
>>>>>>>> fils = systemfunc("ls [1-2][8-9-0-1]*/*nc")
>>>>>>>>    print(fils)
>>>>>>>>
>>>>>>>>    f   = addfiles (fils, "r")
>>>>>>>>
>>>>>>>>    x   = short2flt(f[:]->NDVI)
>>>>>>>>
>>>>>>>>    printVarSummary(x)
>>>>>>>> =========================================
>>>>>>>> but got the attached error! Please have a look at the attached
>>>>>>>> screenshot.
>>>>>>>> How can I combine all those files together, please?
>>>>>>>> I really appreciate any help you can provide.
>>>>>>>> Best wishes,
>>>>>>>>
>>>>>>>> --
>>>>>>>> S.Rahimi
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> ncl-talk mailing list
>>>>>>>> ncl-talk at mailman.ucar.edu
>>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> S.Rahimi
>>>>>>
>>>>>>
>>>>
>>>> --
>>>> S.Rahimi
>>>>
>>>>
>>
>> --
>> S.Rahimi
>>
>>

-- 
S.Rahimi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220629/fa27a4fb/attachment-0001.htm>
-------------- next part --------------
fils = systemfunc("ls VIIRS*nc")
  print(fils)

   f   = addfiles (fils, "r")
  ;ListSetType (f, "cat")
   x   = short2flt(f[:]->NDVI)

   printVarSummary(x)
;************************************************
; Compute the climatology using a function in contributed.ncl
;************************************************
wks = gsn_open_wks("png","ndvi")           ; send graphics to PNG file

  res                  = True                ; plot mods desired
  res at gsnMaximize      = True

  res at cnFillOn         = True                ; color Fill
  res at cnFillMode       = "RasterFill"        ; Raster Mode
  res at cnLinesOn        = False               ; Turn off contour lines

  res at mpCenterLonF     = 0                   ; set map center at 180
  res at mpFillOn         = False


res at cnLevelSelectionMode = "ManualLevels"     ; set manual contour levels

  res at cnMinLevelValF   =  -0.4              ; set min contour level
  res at cnMaxLevelValF   =   0.5              ; one less than max
  res at cnLevelSpacingF  =   0.05              ; set contour spacing
  res at cnFillPalette    = "NEO_div_vegetation_a"   ; <<< VEGETATION ...place holder
setvalues NhlGetWorkspaceObjectId()
    "wsMaximumSize" : 500000000
  end setvalues

 res at gsnCenterString  = "NDVI average from 2021-03-03 to 2021-03-12"

  opt = True
  opt at nval_crit = 10   ; require at least 10 values for the "avg" is calculated.

  xM = dim_avg_n_Wrap( x, 0)
 printVarSummary(xM)

plot = gsn_csm_contour_map_ce(wks,xM, res) ; create plot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ndvi.png
Type: image/png
Size: 311666 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220629/fa27a4fb/attachment-0001.png>


More information about the ncl-talk mailing list