jleinonen / cloudsat-gan

Reconstruction of Cloud Vertical Structure with a Generative Adversarial Network
MIT License
23 stars 8 forks source link

On Data Preprocessing #2

Closed zzh23323 closed 1 year ago

zzh23323 commented 2 years ago

Hello, the author. How do you put MODIS products and CLOUDSAT scenarios in one NC file

jleinonen commented 2 years ago

Hello @zzh23323,

There is a CloudSat data product that has the MODIS products collocated into the CloudSat grid: https://www.cloudsat.cira.colostate.edu/data-products/mod06-1km-aux So there is no need to download the much-larger MODIS data files.

zzh23323 commented 2 years ago

I know what you said. I mean how to put 190000 data into a data set in NC format. Do you have the corresponding procedure?

jleinonen commented 2 years ago

Here is the function I used to create the file. The variables in the tuple patches should contain the data.

def save_modis_patches(fn, patches):
    calendar = 'standard'
    timeunits = 'days since 1970-01-01 00:00'

    (tau_c, p_top, r_e, twp, lat, lon, time, mask) = patches
    with netCDF4.Dataset(fn, 'w', format="NETCDF4") as ds:
        npix = ds.createDimension("npix", tau_c.shape[1])
        nsamples = ds.createDimension("nsamples", tau_c.shape[0])
        var_params = {"zlib": True, "complevel": 9}
        tau_c_var = ds.createVariable("tau_c", "f4", ("nsamples","npix","npix"),
            **var_params)
        tau_c_var[:] = tau_c
        p_top_var = ds.createVariable("p_top", "f4", ("nsamples","npix","npix"),
            **var_params)
        p_top_var[:] = p_top
        r_e_var = ds.createVariable("r_e", "f4", ("nsamples","npix","npix"),
            **var_params)
        r_e_var[:] = r_e
        twp_var = ds.createVariable("twp", "f4", ("nsamples","npix","npix"),
            **var_params)
        twp_var[:] = twp
        lat_var = ds.createVariable("lat", "f4", ("nsamples","npix","npix"),
            **var_params)
        lat_var[:] = lat
        lon_var = ds.createVariable("lon", "f4", ("nsamples","npix","npix"),
            **var_params)
        lon_var[:] = lon
        time_var = ds.createVariable("time", "f8", ("nsamples",),
            **var_params)
        time_var[:] = netCDF4.date2num(time, units=timeunits, 
            calendar=calendar)
        mask_var = ds.createVariable("mask", "u1", ("nsamples","npix","npix"),
            **var_params)
        mask_var[:] = mask