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

Feature Request: Build a DSD from non-supported format #108

Open
iancornejo opened this issue May 8, 2023 · 0 comments
Open

Feature Request: Build a DSD from non-supported format #108

iancornejo opened this issue May 8, 2023 · 0 comments

Comments

@iancornejo
Copy link

iancornejo commented May 8, 2023

I appreciate all the built in file readers, but for instances where I apply qc to raw parsivel data and then try to read it in, I need to convert to something akin to ARM's formatting:

def read_precip(nc):
    try:
        nc_temp.close()
        os.remove("temp.nc")
    except:
        pass
    nc_temp = Dataset("temp.nc","w")

    time = nc_temp.createDimension("time",1440)
    particle_size = nc_temp.createDimension("particle_size",32)
    raw_fall_velocity = nc_temp.createDimension("raw_fall_velocity",32)

    time_ = nc_temp.createVariable("time","f4",("time")); 
    time_.units = "seconds since 1970-01-01 00:00:00 0:00"
    time_[:] = date2num(num2date(nc.variables["time"][:],nc.variables["time"].units),units=time_.units)

    Nd_ = nc_temp.createVariable("number_density_drops","f4",("time","particle_size"));
    Nd_[:] = np.nansum(nc.variables["num_conc_rain"][:],axis = 1)

    vel_ = nc_temp.createVariable("fall_velocity_calculated","f4",("particle_size"));
    vel_[:] = v_gk(nc.variables["particle_size"][:])/100

    rr_ = nc_temp.createVariable("precip_rate","f4",("time"));
    rr_[:] = nc.variables["rain_rate_qc"][:]

    spec_ = nc_temp.createVariable("raw_spectrum","f4",("time","particle_size","raw_fall_velocity"))
    spec_[:] = np.moveaxis(nc.variables["qc_spectrum"][:], 1, 2)

    raw_velo_ = nc_temp.createVariable("raw_fall_velocity","f4",("raw_fall_velocity"))
    raw_velo_[:] = nc.variables["raw_fall_velocity"][:]

    dia_ = nc_temp.createVariable("particle_size","f4",("particle_size"))
    dia_[:] = nc.variables["particle_size"][:]

    width_ = nc_temp.createVariable("class_size_width","f4",("particle_size"))
    width_[:] = nc.variables["particle_size_bin_width"][:]
    
    try:
        return(pydsd.read_parsivel_arm_netcdf("temp.nc"))
    finally:
        nc_temp.close()
        os.remove("temp.nc")

This isn't a huge problem, but being able to just build the dsd object with fields from non-supported file types would be great.

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

1 participant