Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different result between ncread and matlab‘s ncread #103

Closed
ZMAlt opened this issue Nov 1, 2019 · 7 comments
Closed

different result between ncread and matlab‘s ncread #103

ZMAlt opened this issue Nov 1, 2019 · 7 comments

Comments

@ZMAlt
Copy link

ZMAlt commented Nov 1, 2019

Hi, I get different result between ncread and matlab‘s ncread. And it doesn't look like offset or scale_factor‘s problem.

julia>mss=ncread(MSS_str,"mss")

julia> mss
21602×10800 Array{Int32,2}:
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14972  14947  14924  14900  14876  14852  14817
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14955  14930  14907  14884  14859  14835  14801
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14928  14905  14882  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14928  14905  14882  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14928  14905  14882  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14954  14928  14905  14882  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14905  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14905  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14905  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14953  14929  14904  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14953  14928  14904  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14953  14928  14904  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14953  14928  14904  14881  14857  14833  14799
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14953  14928  14904  14881  14857  14833  14799
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14953  14928  14904  14881  14857  14833  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14954  14929  14905  14882  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14905  14882  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14905  14882  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28856     14954  14928  14905  14882  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28856     14954  14928  14905  14882  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28856    14953  14927  14904  14881  14857  14833  14799
 -28914  -28904  -28894  -28885  -28875  -28866  -28856     14953  14927  14904  14881  14857  14833  14799
 -28914  -28904  -28894  -28885  -28875  -28866  -28856     14953  14927  14904  14881  14857  14833  14799
 -28914  -28904  -28894  -28885  -28875  -28866  -28856     14953  14927  14904  14881  14857  14833  14799
 -28914  -28904  -28894  -28885  -28875  -28866  -28856     14953  14927  14904  14881  14857  14833  14799
                                                                                                       
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14953  14929  14906  14882  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14953  14929  14906  14882  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857    14953  14929  14906  14882  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14953  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857    14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28895  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14858  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14834  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14954  14929  14906  14883  14859  14835  14800
 -28914  -28904  -28894  -28885  -28875  -28866  -28857    14972  14947  14924  14901  14877  14852  14817
 -28914  -28904  -28894  -28885  -28875  -28866  -28857     14955  14930  14907  14884  14860  14836  14801
% matlab
mss=ncread(MSS_str,'mss');

Here are some parts of matlab result
Snipaste_2019-11-01_22-41-52

Snipaste_2019-11-01_22-42-18

%matlab
>> ncdisp('./data/mss/DTU15MSS_1min.nc')
Source:
           xxx/data/mss/DTU15MSS_1min.nc
Format:
           classic
Global Attributes:
           Conventions = 'COARDS/CF-1.0'
           title       = 'DTU15MSS_1min.nc'
           source      = 'Danish National Space Center'
           node_offset = 1
Dimensions:
           lon = 21602
           lat = 10800
Variables:
    lon
           Size:       21602x1
           Dimensions: lon
           Datatype:   double
           Attributes:
                       long_name    = 'longitude'
                       units        = 'degrees_east'
                       actual_range = [-0.01666667      360.0167]
    lat
           Size:       10800x1
           Dimensions: lat
           Datatype:   double
           Attributes:
                       long_name    = 'latitude'
                       units        = 'degrees_north'
                       actual_range = [-90  90]
    mss
           Size:       21602x10800
           Dimensions: lon,lat
           Datatype:   int32
           Attributes:
                       long_name    = 'mean sea surface height'
                       units        = 'm'
                       scale_factor = 0.001
                       actual_range = [-105.568         86.76]

julia V1.2.0
julia NetCDF v0.8.0
matlab 2017b
macOS

@visr
Copy link
Member

visr commented Nov 1, 2019

Hmm this could be #102. Could you try pkg> add NetCDF#master and see if it goes away? If it does we should probably tag a new release soon. @meggart is there anything you still want to do before tagging a (breaking) v0.9.0?

@ZMAlt
Copy link
Author

ZMAlt commented Nov 2, 2019

Hi, pkg> add NetCDF#master doesn't work.
I also test my own netcdf file generated with gmt or julia, and got the same result between julia and matlab.

@visr
Copy link
Member

visr commented Nov 2, 2019

It does seem related to the scale_factor of 0.001 not being applied automatically, why don't you think it is? See also #39. You could also try out https://github.com/Alexander-Barth/NCDatasets.jl/ which I believe applies the scale factor automatically.

If you manually multiply mss by 0.001, are the values not what you expect?

@ZMAlt
Copy link
Author

ZMAlt commented Nov 3, 2019

I don't think it's scale_factor's problem. You'll see that mss multiplied by 0.001 is still different.

@visr
Copy link
Member

visr commented Nov 3, 2019

Ah but I believe the dimension ordering is reversed in Julia compared to Matlab, if think if you take that into account, is it the same? It's a bit hard to say based on screenshots.

Matlab says:

actual_range = [-105.568         86.76]

If you in julia do extrema(mss * 0.001), what do you get? And if you compare heatmap plots of the two arrays?

@ZMAlt
Copy link
Author

ZMAlt commented Nov 3, 2019

Thank you for your patience.I am very sorry, I have used different nc files, they are different versions of the same series. In fact, the results of julia and matlab are the same after multiplying by 0.001. I am so stupid, I am sorry to waste your time.

@ZMAlt ZMAlt closed this as completed Nov 3, 2019
@visr
Copy link
Member

visr commented Nov 3, 2019

Ha ok. No worries, your issue is solved and it's not a bug, great outcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants