Esempio n. 1
0
 def test_fromutc_a(self):
     index = pystare.from_utc(datetime.astype(numpy.int64), 6)
     expected = numpy.array([
         34656606509596698, 35184372097220634, 35220842678627354,
         35466003203795994
     ])
     numpy.testing.assert_array_equal(index, expected)
Esempio n. 2
0
 def test_fromutc_b(self):
     index = pystare.from_utc(datetime.astype(numpy.int64), 27)
     expected = numpy.array([
         34656606509596782, 35184372097220718, 35220842678627438,
         35466003203796078
     ])
     numpy.testing.assert_array_equal(index, expected)
Esempio n. 3
0
def merra2_stare_time(ds, iTime=None, tType=2, centered=True):
    if centered:
        start_time_mn = ds['time'].begin_time / 100
        start_time_sec = ds['time'].begin_time % 100
        resolution = stare_temporal_resolutions[tType]['1/2hr']
    else:
        start_time_mn = 0
        start_time_sec = 0
        resolution = stare_temporal_resolutions[tType]['1hr']
    yr, mo, dy = merra2_parse_begin_date(ds['time'].begin_date)
    tm = []
    if iTime is None:
        i0 = 0
        i1 = 24
    else:
        i0 = iTime
        i1 = iTime + 1
    for i in range(i0, i1):
        # hr,mn    = merra2_make_time(ds['time'].begin_date,ds['time'][i])
        hr, mn = merra2_make_time(start_time_mn, ds['time'][i])
        sc = start_time_sec
        tm.append(format_time(yr, mo, dy, hr, mn, sc))
    dt = np.array(tm, dtype='datetime64[ms]')
    idx = ps.from_utc(dt.astype(np.int64), resolution)
    return idx
Esempio n. 4
0
 def add_temporal_stare(self):
     numeric_timestamp = numpy.datetime64(self.time_stamp).astype(
         numpy.int64)
     stare_value = pystare.from_utc([numeric_timestamp], 27)
     stare_temporal = numpy.full(shape=self.lats.shape,
                                 fill_value=stare_value,
                                 dtype='int64')
     self.data['stare_temporal'] = stare_temporal
     self.data_types['stare_temporal'] = 'int64'
Esempio n. 5
0
def temporal_id_centered_from_merra2_filename(m2name):
    m2name_split = m2name.split(".")
    yr  = int(m2name_split[2][0:4])
    mo  = int(m2name_split[2][4:6])
    dy  = int(m2name_split[2][6:8])
    hr  = 12
    mn  = 0
    sec = 0
    m2dt_str = format_time(yr,mo,dy,hr,mn,sec)
    m2dt_np = np.array([m2dt_str],dtype='datetime64[ms]')
    m2tid_centered = ps.from_utc(m2dt_np.astype(np.int64),stare_temporal_resolutions[2]['1/2day'])
    return m2tid_centered
Esempio n. 6
0
def temporal_id_centered_from_goes_filename(gfname):
    gfname_split = gfname.split(".")
    yr  = gfname_split[1]
    ydy = gfname_split[2]
    hr  = int(gfname_split[3][0:2])
    mn  = int(gfname_split[3][2:4])
    sec = int(gfname_split[3][4:6])
    gdt = dt.datetime(int(yr),1,1)+dt.timedelta(int(ydy)-1)
    gdt_str = format_time(int(yr),int(gdt.month),int(gdt.day),hr,mn,sec)
    gdt_np = np.array([gdt_str],dtype='datetime64[ms]')
    gtid_centered = ps.from_utc(gdt_np.astype(np.int64),stare_temporal_resolutions[2]['1/4hr'])
    return gtid_centered
Esempio n. 7
0
def temporal_id_centered_from_modis_filename(mfname):
    mfname_split = mfname.split(".")
    yr  = mfname_split[1][1:5]
    ydy = mfname_split[1][5:8]
    hr  = int(mfname_split[2][0:2])
    mn  = int(mfname_split[2][2:4])
    # sec = int(mfname_split[2][4:6])
    sec = 0
    mdt = dt.datetime(int(yr),1,1)+dt.timedelta(int(ydy)-1)
    mdt_str = format_time(int(yr),int(mdt.month),int(mdt.day),hr,mn,sec)
    mdt_np = np.array([mdt_str],dtype='datetime64[ms]')
    mtid_centered = ps.from_utc(mdt_np.astype(np.int64),stare_temporal_resolutions[2]['1/16hr'])
    return mtid_centered
Esempio n. 8
0
def load_modis():

    dataPath = "/home/mrilee/data/MODIS/"

    # MOD03.A2005349.2120.061.2017187042837.hdf  MOD05_L2.A2005349.2120.061.2017294065852.hdf
    # MOD03.A2005349.2125.061.2017187042720.hdf  MOD05_L2.A2005349.2125.061.2017294065400.hdf

    modis_base = "MOD05_L2."

    # 1 modis_item       = "A2005349.2120.061.2017294065852"
    # 1 modis_time_start = "2005-12-15T21:20:00"

    modis_item = "A2005349.2125.061.2017294065400"
    modis_time_start = "2005-12-15T21:25:00"
    modis_geofilename = "MOD03.A2005349.2125.061.2017187042720.hdf"

    modis_suffix = ".hdf"
    modis_filename = modis_base + modis_item + modis_suffix

    fmt_suffix = ".h5"
    workFileName = "sketchG." + modis_base + modis_item + fmt_suffix

    key_across = 'Cell_Across_Swath_1km:mod05'
    key_along = 'Cell_Along_Swath_1km:mod05'

    print('loading: ', dataPath + modis_filename)
    hdf = SD(dataPath + modis_filename, SDC.READ)
    ds_wv_nir = hdf.select('Water_Vapor_Near_Infrared')
    data = ds_wv_nir.get()

    # MODIS_Swath_Type_GEO/Geolocation_Fields/
    # Latitude

    hdf_geo = SD(dataPath + modis_geofilename, SDC.READ)
    print('hg info: ', hdf_geo.info())
    # for idx,sds in enumerate(hdf_geo.datasets().keys()):
    #     print(idx,sds)
    # hdf_geo_ds = hdf_geo.select['']

    # hdf_geo_swath     = hdf_geo.select('MODIS_Swath_Type_GEO')
    # hdf_geo_swath_gf  = hdf_geo_swath['Geolocation_Fields']
    hdf_geo_lat = hdf_geo.select('Latitude').get()
    hdf_geo_lon = hdf_geo.select('Longitude').get()
    print('hgl type  ', type(hdf_geo_lat))
    print('hgl shape ', hdf_geo_lat.shape, hdf_geo_lon.shape)
    print('hgl dtype ', hdf_geo_lat.dtype)
    # exit()

    add_offset = ds_wv_nir.attributes()['add_offset']
    scale_factor = ds_wv_nir.attributes()['scale_factor']
    print('scale_factor = %f, add_offset = %f.' % (scale_factor, add_offset))
    data = (data - add_offset) * scale_factor
    print('data mnmx: ', np.amin(data), np.amax(data))

    nAlong = ds_wv_nir.dimensions()[key_along]
    nAcross = ds_wv_nir.dimensions()[key_across]
    print('ds_wv_nir nAlong,nAcross: ', nAlong, nAcross)

    dt = np.array([modis_time_start], dtype='datetime64[ms]')
    t_resolution = 26  # 5 minutes resolution? 2+6+10+6+6
    tid = ps.from_utc(dt.astype(np.int64), t_resolution)
    # print(np.arange(np.datetime64("2005-12-15T21:20:00"),np.datetime64("2005-12-15T21:25:00")))
    # exit()

    fill_value = ds_wv_nir.attributes()['_FillValue']

    mod_lat = hdf_geo_lat.flatten()
    mod_lon = hdf_geo_lon.flatten()
    mod_dat = data.flatten()

    return mod_lon, mod_lat, mod_dat  # load_modis
Esempio n. 9
0
print('hgl dtype ', hdf_geo_lat.dtype)
# exit()

add_offset = ds_wv_nir.attributes()['add_offset']
scale_factor = ds_wv_nir.attributes()['scale_factor']
print('scale_factor = %f, add_offset = %f.' % (scale_factor, add_offset))
data = (data - add_offset) * scale_factor
print('data mnmx: ', np.amin(data), np.amax(data))

nAlong = ds_wv_nir.dimensions()[key_along]
nAcross = ds_wv_nir.dimensions()[key_across]
print('ds_wv_nir nAlong,nAcross: ', nAlong, nAcross)

dt = np.array([modis_time_start], dtype='datetime64[ms]')
t_resolution = 26  # 5 minutes resolution? 2+6+10+6+6
tid = ps.from_utc(dt.astype(np.int64), t_resolution)
# print(np.arange(np.datetime64("2005-12-15T21:20:00"),np.datetime64("2005-12-15T21:25:00")))
# exit()

fill_value = ds_wv_nir.attributes()['_FillValue']

# print(ds_wv_nir.info())
# print(hdf.info())
# print(ds_wv_nir.attributes())
# print(hdf.attributes().keys())

# hdf_lat = hdf.select('Latitude')
# print('hdf.lat: ',type(hdf_lat),hdf_lat.info())

lat_5km = with_hdf_get(hdf, 'Latitude')
lon_5km = with_hdf_get(hdf, 'Longitude')
Esempio n. 10
0
# This adds the silliness of how to interpret our intervals. If we keep the STARE scheme
# The start of the interval is the start, but then cmp-at-resolution is not quite right.
# Note cmp does the right thing.
print('')
for i in range(len(tim)):
    print('%3d i,tim %04d '%(i,tim[i]),' %02d:%02d '%merra2_make_time(0,tim[i]))

formatted_times = []
idx = np.zeros([tim.size],dtype=np.int64)
for i in range(len(tim)):
    yr,mo,dy = merra2_parse_begin_date(tim.begin_date)
    hr,mn    = merra2_make_time(0,tim[i])
    sc       = 0
    tm       = format_time(yr,mo,dy,hr,mn,sc)
    dt = np.array([tm],dtype='datetime64[ms]')
    idx[i]   = ps.from_utc(dt.astype(np.int64),resolution_level_1hr)
    # idx[i]   = ps.from_utc(dt.astype(np.int64),resolution_level_1o4hr)
    back     = np.array(ps.to_utc_approximate(np.array([idx[i]],dtype=np.int64)),dtype='datetime64[ms]')
    print(yr,mo,dy,hr,mn,tm,dt,hex(idx[i]),back)
    formatted_times.append(tm)

### GOES BAND_05 # Check time information

goes_b5_dataPath = "/home/mrilee/data/"
goes_b5_dataFile = "goes10.2005.349.003015.BAND_05.nc"
goes_b5_fqFilename = goes_b5_dataPath+goes_b5_dataFile
goes_b5_ds = Dataset(goes_b5_fqFilename)

# print('keys: ',goes_b5_ds.variables.keys())

tim = goes_b5_ds['time']
Esempio n. 11
0
 def test_epoch(self):
     datetime_x1 = datetime.astype(numpy.int64)
     index = pystare.from_utc(datetime_x1, 27)
     datetime_x2 = pystare.to_utc_approximate(index)
     numpy.testing.assert_array_equal(datetime_x1, datetime_x2)
Esempio n. 12
0
 def test_utc_roundtrip(self):
     index = pystare.from_utc(datetime.astype(numpy.int64), 27)
     datetime_x = pystare.to_utc_approximate(index)
     datetime_r = numpy.array(datetime_x, dtype='datetime64[ms]')
     numpy.testing.assert_array_equal(datetime, datetime_r)
Esempio n. 13
0
def goes10_img_stare_time(ds,tType=2,centered=True):
  resolution = stare_temporal_resolutions[2]['1/4hr']
  dt = np.array(ds['time'][0]*1000,dtype='datetime64[ms]').reshape([1])
  return ps.from_utc(dt.astype(np.int64),resolution)