AI-4-atmosphere-remote-sensing / satellite_collocation

Apache License 2.0
3 stars 1 forks source link

The attribute 'Profile_Datetime' read by instrument_reader.py for CALIPSO_L2_1km data is not correct #6

Open lixy4567 opened 6 months ago

lixy4567 commented 6 months ago

Could anyone please confirm the code to extract time range attributes from CALIPSO_1km files? The code I'm talking about is at 'satellite_collocation/instrument_reader.py', Row 215, which is part of the function load_caliop_clayer1km_geoloc ():

I found the generated colocation index is not aligned with the original CALIPSO data for some of the dates when I run examples of abi-calipso colocation. Specifically, I input a CALIPSO granule with time range '2017-02-28T23:35:37 - 2017-03-01T00:02:59', but when I print the returned attribute 'Profile_Datetime', it prints date time ranges from 2017-02-28 to 2017-05-12. Here is the output:

array([datetime.datetime(2017, 2, 28, 23, 35, 37, 198520), datetime.datetime(2017, 2, 28, 23, 35, 37, 198520), ...,datetime.datetime(2017, 5, 12, 0, 2, 59, 198520), datetime.datetime(2017, 5, 12, 0, 2, 59, 198520)], dtype=object)

So I checked the code inside instrument.reader.py, and finally located at Row 215: profile_deltas = (cal_utc - cal_utc[0]) * 3600. * 24.

As my understanding, we want to get how many days are past by the start date, and then transform it to seconds. However, it is wrong to calculate by (cal_utc - cal_utc[0]). For example, if the start date is 2017-02-28 and end date is 2017-03-01, then we will have: cal_utc[-1]- cal_utc[0] = 170301.00208008 - 170228.98306943 = 72.01901065. And 72 days is wrong because actually, the time difference is only 1 day. This also happens when the dates go from Marchi to April, from April to May, etc.

So the point is, the number before the decimal point and after the decimal point is not on the same scale, where the former is year-month-day and the latter is the percentage of a day.

Please let me know if my understanding is wrong or if this should be corrected. Thanks.

lixy4567 commented 6 months ago

To provide better understanding, this is original code of 'satellite_collocation/instrument_reader.py', Row 211 to Row 218:

n_profile = cal_lon.shape[0]
prof_s = 0
prof_e = n_profile
profile_dts = list()
profile_deltas = (cal_utc - cal_utc[0]) * 3600. * 24.
for i_profile in range(0,n_profile):
    profile_dt = cstart_dt + datetime.timedelta(seconds=int(profile_deltas[i_profile]))
    profile_dts.append(profile_dt)

and I would like to replace it by:

n_profile = cal_lon.shape[0]
prof_s = 0
prof_e = n_profile
profile_dts = list()
for i_profile in range(0,n_profile):
    stime = datetime.datetime.strptime(str(int((cal_utc[0] + 20000000.))),'%Y%m%d')
    current_time = datetime.datetime.strptime(str(int((cal_utc[i_profile] + 20000000.))),'%Y%m%d')
    profile_delta = ((current_time - stime).days + (cal_utc[i_profile]%1 - cal_utc[0]%1)) * 3600. * 24.
    profile_dt = cstart_dt + datetime.timedelta(seconds=int(profile_delta))
    profile_dts.append(profile_dt)