Project

General

Profile

How to join/combine nc files?

Added by Jeisson Javier Leal Rojas about 1 year ago

Hi.

I have two nc files corresponding to two different basins. I want to combine this two nc files so, for example, when doing `ncview` I can see both basins in the same nc file.

Is there a way to do that?

Both files have the same coordinate system, timeframes and time step.

When I do `ncdump -h` to any of those files I get:

dimensions:
        lat = 1400 ;
        lon = 3600 ;
        time = UNLIMITED ; // (750 currently)
variables:
        double lon(lon) ;
                lon:units = "degrees_east" ;
                lon:long_name = "longitude" ;
                lon:missing_value = -9999. ;
        double lat(lat) ;
                lat:units = "degrees_north" ;
                lat:long_name = "latitude" ;
                lat:missing_value = -9999. ;
        int time(time) ;
                time:units = "hours since 2020-02-10 00:00:00" ;
                time:long_name = "time" ;
        double Qrouted(time, lat, lon) ;
                Qrouted:long_name = "routed streamflow" ;
                Qrouted:unit = "m3 s-1" ;
                Qrouted:scale_factor = 1. ;
                Qrouted:missing_value = -9999. ;
                Qrouted:coordinates = "lat lon" ;

// global attributes:
                :project = "Ulysses project" ;
                :setup_description = "model run for the Ulysses project" ;
                :simulation_type = "simulation" ;
                :Conventions = "tbd" ;
                :contact = "Stephan Thober (email: stephan.thober@ufz.de" ;
                :mRM_details = "Helmholtz Center for Environmental Research - UFZ, Department Computational Hydrosystems, Stochastic Hydrology Group, release mRMv1.0" ;
                :history = "2023-04-12 21:40:39," ;
                :title = "mRMv1.0 simulation outputs" ;
                :creation_date = "2023-04-12 21:40:39" ;

Replies (3)

RE: How to join/combine nc files? - Added by Estanislao Gavilan about 1 year ago

Hi Jeisson,

You can probably use collgrid. Take a look to the documentation. It is well explained there.

Kind regards,

Estanislao

RE: How to join/combine nc files? - Added by Jeisson Javier Leal Rojas about 1 year ago

Hi.

I tried that, but the resulting nc file is not the one I was expecting.

I executed:

cdo collgrid file[1-2].nc output.nc

Instead of combining both nc files (one on top of the other), the resulting file is the result of both nc files next to each other (see picture bellow):

Any ideas of what can be done?

RE: How to join/combine nc files? - Added by Jeisson Javier Leal Rojas about 1 year ago

I found out how to do it!

cdo mergegrid input1.nc input2.nc output.nc

that did the trick :)

    (1-3/3)