[ncl-talk] Read Matlab file and shift data longitudinally

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Fri Dec 15 08:32:17 MST 2023


Giorgio, I think you are right, there may be something wrong with the way
the Netcdf file is created.  Your link pointed to "Write Data to NetCDF
File Using Low-Level Functions".  Try using the Matlab high-level Netcdf
export functions instead, such as *ncwrite*.  Those do a better job of
preserving dimensions and data alignment.

It will be more constructive to debug your Matlab export process, than to
try to manipulate a damaged data file.  Check your work by comparing
dimensions and data alignment with Matlab and Netcdf diagnostic functions.
Dimensions before and after export should match exactly.  Data samples at
the same indices should match exactly.  I find that NCL is convenient for
examining small data samples, such as:

    print (temp(24089,20,0:3))

Matlab has something similar.


On Fri, Dec 15, 2023 at 5:47 AM Giorgio Graffino via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Dear NCL experts,
>
>
>
> Hope you're all well. As per the subject, I want to read a .mat file
> containing daily SST data from 1940 to 2005 and run some analysis I've
> already written in NCL. If I try to directly read the file with NCL I get
> Segmentation fault, so that's not the right way to go. I converted the file
> into NetCDF using Matlab (
> https://uk.mathworks.com/help/matlab/import_export/exporting-to-network-common-data-form-netcdf-files.html?s_tid=answers_rc2-3_p6_MLT#bsxb70y-1),
> but there is a problem with the data.
>
>
>
> At some point in the time series (around 1962), the data get shifted in
> the longitude sense by about 40 degrees. I checked this in NCL and in
> Ferret, as shown in the attached screenshot: the left-hand side is SST on a
> random day before 1962, while the right-hand side is after 1962. It's like
> there is an offset in the data longitudes. The plots are drawn using only
> four lines in Ferret, so the error can't be due to the the software. There
> must be something wrong going on when the file is created. It would be
> great to know what happens to the data in the first place, but maybe it's a
> discussion that doesn't belong here.
>
>
>
> This is the printVarSummary of the full data. The longitudes array does
> not change over time, but the data are shifted.
>
>
>
> Variable: temp
> Type: float
> Total Size: 710269560 bytes
>            177567390 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 24090] x [lats | 120] x [lons | 180]
> Coordinates:
>            time: [350616..929160]
>            lats: [ -90..88.5]
>            lons: [   0.. 358]
> Number Of Attributes: 1
>  _FillValue :  -9e+33
>
>
> I'd like to know how I can correct the second part of the time series to
> make it like the first part. I tried with LonFlip and LonPivot but I
> couldn't make it work. I'm thinking about a way to shift the data back by
> that longitude offset, but I can't wrap my head around it.
>
>
>
> Please let me know.
>
>  Cheers,
>
> Giorgio
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20231215/e89d52a9/attachment.htm>


More information about the ncl-talk mailing list