示例#1
0
def get_area(ds_lda):
    '''get the area of lda file'''
    attrs = ds_lda.attrs
    i = attrs['WEST-EAST_GRID_DIMENSION']
    j = attrs['SOUTH-NORTH_GRID_DIMENSION']

    # calculate attrs for area definition
    shape = (j, i)
    radius = (i * attrs['DX'] / 2, j * attrs['DY'] / 2)

    # create area as same as WRF
    area_id = 'wrf_circle'
    proj_dict = {
        'proj': wrf_projs[attrs['MAP_PROJ']],
        'lat_0': attrs['MOAD_CEN_LAT'],
        'lon_0': attrs['STAND_LON'],
        'lat_1': attrs['TRUELAT1'],
        'lat_2': attrs['TRUELAT2'],
        'a': 6370000,
        'b': 6370000
    }
    center = (0, 0)
    wrf_area = AreaDefinition.from_circle(area_id,
                                          proj_dict,
                                          center,
                                          radius,
                                          shape=shape)

    return wrf_area
示例#2
0
def get_area(hrit_files,
             central_lat,
             central_lon,
             elevation,
             time,
             save_path,
             fov,
             shape,
             proj,
             projection_parameters,
             composite=None,
             fov_deg=True):
    """Shows in Jupyter Notebook results of pictures seen from sat
    Parameters
        Array of saved on disc files.
        :param save_path:
        :param composite:
        :param time:
        :param elevation:
        :param central_lon:
        :param central_lat:
        :param hrit_files:

    """
    # TO DO: Add local earth radius
    from satpy.scene import Scene
    import math
    from pyresample.geometry import AreaDefinition, SwathDefinition, create_area_def
    from pyresample import create_area_def

    if composite is None:
        composite = 'realistic_colors'

    if fov_deg == True:
        fov = [fov[0] * math.pi / 180, fov[1] * math.pi / 180]

    area_def = []
    for i in range(0, len(central_lon)):
        altitude = elevation[i]
        rad = satellite_info(6371228, elevation[i], fov[0], fov[1])[5] / 2
        lat_0, lon_0 = central_lat[i], central_lon[i]
        lat_1, lat_2 = central_lat[i], central_lon[i]
        center = (central_lat[i], central_lon[i])
        radius = (rad, rad)
        area_id = 'wrf_circle'
        proj_dict = {'proj': proj, 'lat_0': lat_0, 'lon_0': lon_0, \
                     'lat_1': lat_1, 'lat_2': lat_2, \
                     'a': 6370000, 'b': 6370000, 'h': altitude, 'azi': projection_parameters[0],
                     'tilt': projection_parameters[1]}
        area_def.append(
            AreaDefinition.from_circle(area_id,
                                       proj_dict,
                                       center,
                                       radius=radius,
                                       shape=shape))
        # area_def.append(AreaDefinition.create_area_def(area_id, proj_dict, center, radius=radius, shape=shape))

    files = return_files(time, hrit_files)

    return (area_def, files, composite)
示例#3
0
    def get_info(self, ):
        '''
        Read basic info from geo file generated by WPS
            If want to run this on your laptop and care about the space,
            you can use ncks to subset the nc file (we just need attrs)
            ncks -F -d Time,1,,1000 -v Times geo_em.d01.nc geo_em.d01_subset.nc
        ref: https://fabienmaussion.info/2018/01/06/wrf-projection/
        '''
        self.geo = xr.open_dataset(data_path + 'geo_em.'+domain+'.nc')
        attrs = self.geo.attrs
        i = attrs['i_parent_end']
        j = attrs['j_parent_end']

        # calculate attrs for area definition
        shape = (j, i)
        radius = (i*attrs['DX']/2, j*attrs['DY']/2)

        # create area as same as WRF
        area_id = 'wrf_circle'
        proj_dict = {'proj': wrf_projs[attrs['MAP_PROJ']],
                     'lat_0': attrs['MOAD_CEN_LAT'],
                     'lon_0': attrs['STAND_LON'],
                     'lat_1': attrs['TRUELAT1'],
                     'lat_2': attrs['TRUELAT2'],
                     'a': 6370000,
                     'b': 6370000}
        center = (0, 0)
        self.area_def = AreaDefinition.from_circle(area_id,
                                                   proj_dict,
                                                   center,
                                                   radius,
                                                   shape=shape)
示例#4
0
    def get_info(self, ):
        # read basic info from geo file generrated by WPS
        self.geo = xr.open_dataset(wps_path + 'geo_em.' + domain + '.nc')
        attrs = self.geo.attrs
        # read original attrs
        self.lat_1 = attrs['TRUELAT1']
        self.lat_2 = attrs['TRUELAT2']
        self.lat_0 = attrs['MOAD_CEN_LAT']
        self.lon_0 = attrs['STAND_LON']
        self.cenlat = attrs['CEN_LAT']
        self.cenlon = attrs['CEN_LON']
        self.i = attrs['WEST-EAST_GRID_DIMENSION']
        self.j = attrs['SOUTH-NORTH_GRID_DIMENSION']
        self.dx = attrs['DX']
        self.dy = attrs['DY']
        self.mminlu = attrs['MMINLU']
        self.map = attrs['MAP_PROJ']
        self.eta = attrs['BOTTOM-TOP_GRID_DIMENSION']

        # calculate attrs for area definition
        shape = (self.j, self.i)
        center = (0, 0)
        radius = (self.i * self.dx / 2, self.j * self.dy / 2)

        # create area as same as WRF
        area_id = 'wrf_circle'
        proj_dict = {'proj': 'lcc', 'lat_0': self.lat_0, 'lon_0': self.lon_0, \
                    'lat_1': self.lat_1, 'lat_2': self.lat_2, \
                    'a':6370000, 'b':6370000}
        self.area_def = AreaDefinition.from_circle(area_id,
                                                   proj_dict,
                                                   center,
                                                   radius,
                                                   shape=shape)
示例#5
0
文件: wrfchem.py 项目: cycle13/pyXZ
    def get_info(self, wrf_path, fname, vnames):
        # self.wrf = xr.open_dataset(wrf_path+fname)._file_obj.ds
        self.ds = Dataset(wrf_path+fname)
        self.xrds = xr.open_dataset(wrf_path+fname)

        # check vname and read all of them
        self.dv = {}
        if isinstance(vnames, str):
            self.dv.update({vnames: getvar(self.ds, vnames, timeidx=ALL_TIMES)})
            if vnames != 'Times' and 'lon' not in self.dv:
                self.dv.update({'lat': latlon_coords(self.dv[vnames])[0]})
                self.dv.update({'lon': latlon_coords(self.dv[vnames])[1]})
        elif isinstance(vnames, list):
            for index, v in enumerate(vnames):
                self.dv.update({v: getvar(self.ds, v, timeidx=ALL_TIMES)})
                if v != 'Times' and 'lon' not in self.dv:
                    self.dv.update({'lat': latlon_coords(self.dv[v])[0]})
                    self.dv.update({'lon': latlon_coords(self.dv[v])[1]})

        # get proj
        attrs = self.xrds.attrs
        i = attrs['WEST-EAST_GRID_DIMENSION']
        j = attrs['SOUTH-NORTH_GRID_DIMENSION']

        # calculate attrs for area definition
        shape = (j, i)
        radius = (i*attrs['DX']/2, j*attrs['DY']/2)

        # create area as same as WRF
        area_id = 'wrf_circle'
        proj_dict = {'proj': wrf_projs[attrs['MAP_PROJ']],
                     'lat_0': attrs['MOAD_CEN_LAT'],
                     'lon_0': attrs['STAND_LON'],
                     'lat_1': attrs['TRUELAT1'],
                     'lat_2': attrs['TRUELAT2'],
                     'a': 6370000,
                     'b': 6370000}
        center = (0, 0)
        self.area_def = AreaDefinition.from_circle(area_id, proj_dict,
                                                   center, radius,
                                                   shape=shape)
示例#6
0
    def get_info(self, wps_path, domain):
        # read basic info from geo file generrated by WPS
        self.geo = xr.open_dataset(wps_path + 'geo_em.'+domain+'.nc')
        attrs = self.geo.attrs
        i = attrs['i_parent_end']
        j = attrs['j_parent_end']

        # calculate attrs for area definition
        shape = (j, i)
        radius = (i*attrs['DX']/2, j*attrs['DY']/2)

        # create area as same as WRF
        area_id = 'wrf_circle'
        proj_dict = {'proj': wrf_projs[attrs['MAP_PROJ']],
                     'lat_0': attrs['MOAD_CEN_LAT'],
                     'lon_0': attrs['STAND_LON'],
                     'lat_1': attrs['TRUELAT1'],
                     'lat_2': attrs['TRUELAT2'],
                     'a': 6370000,
                     'b': 6370000}
        center = (0, 0)
        self.area_def = AreaDefinition.from_circle(area_id, proj_dict,
                                                   center, radius,
                                                   shape=shape)
示例#7
0
def show_sat_perspective3(hrit_files,
                          central_lat,
                          central_lon,
                          elevation,
                          time,
                          save_path,
                          fov,
                          shape,
                          proj,
                          projection_parameters,
                          composite=None,
                          fov_deg=True):
    """Shows in Jupyter Notebook results of pictures seen from sat
    Parameters
        Array of saved on disc files.
        :param save_path:
        :param composite:
        :param time:
        :param elevation:
        :param central_lon:
        :param central_lat:
        :param hrit_files:

    """
    # TO DO: Add local earth radius
    from satpy.scene import Scene
    import math
    from pyresample.geometry import AreaDefinition, SwathDefinition, create_area_def
    from pyresample import create_area_def

    if composite is None:
        composite = 'realistic_colors'

    if fov_deg == True:
        fov = [fov[0] * math.pi / 180, fov[1] * math.pi / 180]

    # lla = mat.find_sourounding_list(earth_rads, latitudes, longitudes, elevations, fov)

    area_def = []
    for i in range(0, len(central_lon)):
        altitude = elevation[i]
        rad = satellite_info(6371228, elevation[i], fov[0], fov[1])[5] / 2
        lat_0, lon_0 = central_lat[i], central_lon[i]
        lat_1, lat_2 = central_lat[i], central_lon[i]
        center = (central_lat[i], central_lon[i])
        radius = (rad, rad)
        area_id = 'wrf_circle'
        proj_dict = {'proj': proj, 'lat_0': lat_0, 'lon_0': lon_0, \
                     'lat_1': lat_1, 'lat_2': lat_2, \
                     'a': 6370000, 'b': 6370000, 'h': altitude, 'azi': projection_parameters[0],
                     'tilt': projection_parameters[1]}
        area_def.append(
            AreaDefinition.from_circle(area_id,
                                       proj_dict,
                                       center,
                                       radius=radius,
                                       shape=shape))
        # area_def.append(AreaDefinition.create_area_def(area_id, proj_dict, center, radius=radius, shape=shape))

    files = return_files(time, hrit_files)

    scn = Scene(filenames=files)
    scn.load([composite])
    new_scn = scn

    for i, area_def in enumerate(area_def, start=0):
        local_scn = scn.resample(area_def, radius_of_influence=50000)
        local_scn.show(composite)
        path = save_path + proj + str(projection_parameters[0]) + '_' + str(
            projection_parameters[1]) + '_' + str(shape[0]) + '_' + str(
                composite) + '_' + '_{date:%Y-%m-%d_%H_%M_%S}'.format(
                    date=scn.start_time) + '/' + str(i) + '.png'
        local_scn.save_dataset(composite,
                               path,
                               writer='simple_image',
                               num_threads=8)

    # if save_path:
    #     if (isinstance(load_photo[0], float)):
    #         photo_type = str(load_photo[0])
    #     else:
    #         photo_type = load_photo[0]
    #     name = photo_path + photo_type + pro_name + '_{date:%Y-%m-%d_%H_%M_%S}.png'.format(date=scn.start_time)
    #     plt.savefig(name, dpi=dpi)
    # if not save_path:
    #     plt.show()

    return ()
示例#8
0
def show_sat_perspective2(hrit_files,
                          central_lat,
                          central_lon,
                          elevation,
                          time,
                          save_path,
                          fov,
                          shape,
                          composite=None,
                          fov_deg=True):
    """Shows in Jupyter Notebook results of pictures seen from sat
    Parameters
        Array of saved on disc files.
        :param save_path:
        :param composite:
        :param time:
        :param elevation:
        :param central_lon:
        :param central_lat:
        :param hrit_files:

    """
    # TO DO: Add local earth radius
    import datetime as dt
    from satpy.scene import Scene
    import math
    from satpy.resample import get_area_def
    from datetime import datetime
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy
    import cartopy.feature as cfeature
    from skyfield.api import Topos, load
    import pyproj
    import numpy as np
    from astropy import units as u
    from astropy.coordinates import Angle
    # %matplotlib inline
    import matplotlib.pyplot as plt
    from pyresample.geometry import AreaDefinition, SwathDefinition, create_area_def

    if composite is None:
        composite = 'realistic_colors'

    if fov_deg == True:
        fov = [fov[0] * math.pi / 180, fov[1] * math.pi / 180]

    area_def = []
    for i in range(0, len(central_lon)):
        area_id = 'ease_sh'
        rad = satellite_info(6371228, elevation[i], fov[0], fov[1])[5] / 2
        lat_0, lon_0 = central_lat[i], central_lon[i]
        lat_1, lat_2 = central_lat[i], central_lon[i]
        center = (central_lat[i], central_lon[i])
        radius = (rad, rad)
        area_id = 'wrf_circle'
        proj_dict = {'proj': 'lcc', 'lat_0': lat_0, 'lon_0': lon_0, \
                     'lat_1': lat_1, 'lat_2': lat_2, \
                     'a': 6370000, 'b': 6370000}
        area_def.append(
            AreaDefinition.from_circle(area_id,
                                       proj_dict,
                                       center,
                                       radius,
                                       shape=shape))

    files = return_files(time, hrit_files)

    scn = Scene(filenames=files)
    scn.load([composite])
    new_scn = scn

    for i, area_def in enumerate(area_def, start=0):
        local_scn = scn.resample(area_def, radius_of_influence=50000)
        local_scn.show(composite)
        path = save_path + str(shape[0]) + '_' + str(composite) + '_' + str(
            i) + '_{date:%Y-%m-%d_%H_%M_%S}.png'.format(date=scn.start_time)
        local_scn.save_dataset(composite,
                               path,
                               writer='simple_image',
                               num_threads=8)

    # if save_path:
    #     if (isinstance(load_photo[0], float)):
    #         photo_type = str(load_photo[0])
    #     else:
    #         photo_type = load_photo[0]
    #     name = photo_path + photo_type + pro_name + '_{date:%Y-%m-%d_%H_%M_%S}.png'.format(date=scn.start_time)
    #     plt.savefig(name, dpi=dpi)
    # if not save_path:
    #     plt.show()

    return ()
示例#9
0
def calculate_and_project(hrit_files,
                          sat_positions,
                          time,
                          save_path,
                          fov,
                          shape,
                          proj,
                          nadir_proj=True,
                          composite=None,
                          fov_deg=True,
                          save_data_path=None,
                          save_photos=True):
    """Shows in Jupyter Notebook results of pictures seen from sat
    Parameters
        Array of saved on disc files.
        :param save_path:
        :param composite:
        :param time:
        :param elevation:
        :param central_lon:
        :param central_lat:
        :param hrit_files:

    """
    # TO DO: Add local earth radius
    from satpy.scene import Scene
    from wutsat.fun import mat_fun
    import math
    from pyresample.geometry import AreaDefinition, SwathDefinition, create_area_def
    # from pyresample import create_area_def
    import os

    if composite is None:
        composite = 'realistic_colors'

    if fov_deg == True:
        fov = [fov[0] * math.pi / 180, fov[1] * math.pi / 180]

    if nadir_proj:
        nadir_proj = [0, 0]

    central_lat, central_lon, elevation = mat_fun.find_sourounding_list(
        earth_radius=sat_positions[3],
        lat=sat_positions[0],
        lon=sat_positions[1],
        alt=sat_positions[2],
        fov=fov)

    #print(len(central_lat))
    area_def = []
    for i in range(0, len(central_lon)):
        altitude = elevation[i]
        rad = satellite_info(6371228, elevation[i], fov[0], fov[1])[5] / 2
        lat_0, lon_0 = central_lat[i], central_lon[i]
        lat_1, lat_2 = central_lat[i], central_lon[i]
        center = (central_lat[i], central_lon[i])
        radius = (rad, rad)
        area_id = 'wrf_circle'
        proj_dict = {'proj': proj, 'lat_0': lat_0, 'lon_0': lon_0, \
                     'lat_1': lat_1, 'lat_2': lat_2, \
                     'a': 6370000, 'b': 6370000, 'h': altitude, 'azi': nadir_proj[0],
                     'tilt': nadir_proj[1]}
        area_def.append(
            AreaDefinition.from_circle(area_id,
                                       proj_dict,
                                       center,
                                       radius=radius,
                                       shape=shape))
        # area_def.append(AreaDefinition.create_area_def(area_id, proj_dict, center, radius=radius, shape=shape))

    files = return_files(time, hrit_files)

    if save_photos:
        scn = Scene(filenames=files)
        scn.load([composite])
        for i, area in enumerate(area_def, start=0):
            local_scn = scn.resample(area, radius_of_influence=50000)
            local_scn.show(composite)
            path = save_path + '/' + str(i) + '.png'
            local_scn.save_dataset(composite,
                                   path,
                                   writer='simple_image',
                                   num_threads=8)
    sat_data = [area_def, files, [central_lat, central_lon, elevation]]
    if save_data_path:
        mat_fun.rwdata(save_data_path, 'sat_data.pkl', 'w', sat_data)

    return ()