Skip to content
Snippets Groups Projects
MatfiletoNetCDF_CL_ARTofMELT_v1.py 57.9 KiB
Newer Older
                                     long_name="Ceilometer Range",
                                     description="Ranges for the ceilometer backscatter profile, including the instrument height",),) #added as 1D


#2D: dimension time/cloud_layer


da_baseht=xr.DataArray(data=np.array(DF_20min_cloudbh,dtype=float).astype('float32'),
                    name="cloud_base_altitude",dims=["time","cloud_layer"],
                       coords=dict(time=Time_steps_dt64_org,cloud_layer=cloud_layer_levs),
                   attrs=dict(type="float32",dimension="time, cloud_layer", units="m",
                              long_name="Cloud Base Altitude",
                              description="cloud base height of 1-3 cloud layers; NaN if no layer detected. " +\
                              "Instrument height incorporated."),) #added as 2D

#2D: dimension time/sky_condition_layer



da_scfrac=xr.DataArray(data=np.array(DF_20min_scfrac,dtype=float).astype('float32'),
                    name="sky_condition_cloud_fraction",dims=["time","sky_condition_layer"],
                       coords=dict(time=Time_steps_dt64_org,sky_condition_layer=sc_layer_levs),
                   attrs=dict(type="float32",dimension="time, sky_condition_layer", units="octal",
                              long_name="Sky Condition Cloud Fraction",
                            description="Cloud fraction calculated with the sky condition algorithm. "+\
                             "0-8 = cloud coverage of up to 5 levels; 9 = obscuration. " +\
                             "NaN = missing data or no detected layer."),) #added as 2D

da_scht=xr.DataArray(data=np.array(DF_20min_scht,dtype=float).astype('float32'),
                    name="sky_condition_cloud_altitude",dims=["time","sky_condition_layer"],
                     coords=dict(time=Time_steps_dt64_org,sky_condition_layer=sc_layer_levs),
                   attrs=dict(type="float32",dimension="time, sky_condition_layer", units="m",
Sonja Murto's avatar
Sonja Murto committed
                              long_name="Sky Condition Cloud Altitude",
                              description = "Cloud layer height calculated with the sky condition algorithm. "+\
                             "Cloud layer height given for 1-5 sky condition layers; NaN if no layer detected. "+\
                             "Vertical visibility is reported as height if obscuration (at sky_condition_cloud_fraction 9). "+\
                             "Instrument height incorporated."),) #added as 2D



#2D: dimension time/range

da_bsprof=xr.DataArray(data=np.array(DF_20min_range,dtype=float).astype('float32'),
                    name="backscatter_profile",dims=["time","range_levels"],
                       coords=dict(time=Time_steps_dt64_org,range_levels=range_levs),
                   attrs=dict(type="float32",dimension="time, range_levels", units="1 km-1 steradians-1",
                              long_name="Backscatter Profile", description="backscatter coefficient profile"),) #added as 2D


# +
#merge all arrays into one

ds_all=xr.merge([da_doy,da_year,da_month,da_day,da_hour,da_min,da_sec,
                da_ceilrange,da_cloudcode,da_vertvis,da_high_sig,
                da_baseht,da_scfrac,da_scht,da_bsprof])

len(ds_all)

# -

#get time range - start
Times_nomicrosec[0]

#get time range - end
Times_nomicrosec[-1]

# +
# modify attributes (start/end time and text in comments); 
# note again geospatial bounds from the weather station data

ds_all.attrs = {"Conventions" :"CF-1.8",
                "source" : "Ceilometer",
                "instrument_model" : "Vaisala Ceilometer CL31",
                "creator_name" : "Sonja Murto",
                "creator_email" : "sonja.murto@misu.su.se",
                "creator_url" : "https://orcid.org/0000-0002-4966-9077",
                "institution" : "Stockholm University",  
                "processing_software" : "Matlab (for creating the matlab file) and a jupyter notebook script (netCDF)",
                "sampling_interval": "original 30s; here 20min averages", 
                "product_version" : "v01",
                "last_revised_date" : "2024-05-31T15:00:00", 
                "project" : "ARTofMELT",
                "project_principal_investigator" : "Michael Tjernström",
                "project_principal_investigator_email" : "michaelt@misu.su.se",
                "project_principal_investigator_url" : "https://orcid.org/0000-0002-6908-7410",                
                "acknowledgement" : " Knut och Alice Wallenbergs Stiftelse, Grant 2016-0024",
                "platform" : "Swedish Icebreaker Oden",
                "platform_type" : "On Oden's 7th deck above the bridge",
                "deployment_mode" : "ship",
                "title" : "Ceilometer cloud base height, vertical visibility and backscatter profiles",
                "feature_type" : "time series",   
                "time_coverage_start" : "2023-05-07T00:10:22",
                "time_coverage_end" : "2023-06-13T16:10:07",
                "geospatial_bounds" : "80.52392166666667N, -3.8737749999999997E, 78.04355166666666N, 15.660881666666667E",
                "platform_altitude" : "Located at approximately 25 m a.s.l",
                "location_keywords": "Oden, Arctic Ocean, Fram Strait, atmosphere, on the ship",
                "comments" : "This file consists of 20 min averages of ceilometer data " +\
                "measured with the Vaisala Ceilometer CL31 that was located on the 7th deck, "+\
                "above the bridge (at approximately 25m)." + \
                "The sky condition measurements are time averages to represent an area average. " + \
                "The vertical resolution is 10m * 770, but the measurement height (25m) is included in the backscatter profile ranges, " + \
                "as well as in the cloud base heights (cloud_base_altitude and sky_condition_cloud_altitude). " + \
                "Geospatial bounds are taken from the gps location of the weather station dataset located on Oden. " +\
                "Time variables month, day, hour, minute and second are approximated to the nearest second. " +\
                "Data produced by Sonja Murto. See the document - Readme_CL.txt - for more details."}
               
# -

ds_all

#save to netCDF
ds_all.to_netcdf(load_data + 'CL31_ceilometer_ARTofMELT_20230507_20230613_20min_v01.nc')

# +
#test plot
ds_all.sel(cloud_layer=1).cloud_base_altitude.plot(color='r',label='cloud_layer = 1')
ds_all.sel(cloud_layer=2).cloud_base_altitude.plot(color='b',label='cloud_layer = 2')
ds_all.sel(cloud_layer=3).cloud_base_altitude.plot(color='y',label='cloud_layer = 3')

plt.title('')
plt.legend()
plt.show()