def deploySat(self): deployer_name = self.deployer_name_lbl['text'] dplyr_mass = float(self.mass_box1.get()) dplyd_mass = float(self.mass_box2.get()) spdx = int(self.spdx_box.get()) spdy = int(self.spdy_box.get()) spdz = int(self.spdz_box.get()) name = self.name_box.get() cat = self.cat_box.get() for sat in self.Sats: if (sat.name == deployer_name): deployer = sat break newSat = self.dpl.deploy(cat, deployer, dplyr_mass, dplyd_mass, name, [spdx, spdy, spdz], date=self.date) self.ax_cov.append( self.ax.fill([0, 0], [0, 0], transform=Geodetic(), color='white', alpha=self.cov_alpha)[0]) self.sat_txt.append( self.ax.text([], [], "", color='yellow', size=8, transform=Geodetic(), ha="center")) self.Sats.append(newSat) self.sortSats() self.popup.destroy()
def __init__(self, directory, filename, constraints=None, callback=None, tmp_directory=None): self.directory = directory self.filename = filename self.tmp_directory = tmp_directory or os.path.join(directory, 'tmp') # try to create the temporary directory # if there are other problems (e.g. permissions) except that it already # exists an exception will be raised try: os.makedirs(self.tmp_directory) except OSError: if not os.path.isdir(self.tmp_directory): raise self.cube_list = iris.load(os.path.join(directory, filename), constraints=constraints, callback=callback) self._orig_standard_name = self.cube_list[0].standard_name self._orig_var_name = self.cube_list[0].var_name self._orig_long_name = self.cube_list[0].long_name self.calendar = self.cube_list[0].coord('time').units.calendar self._orig_units = self.cube_list[0].units for ndim, coord in enumerate(self.cube_list[0].dim_coords): if coord.units.is_time_reference(): self._timeaxis = ndim break # save the period of the entire dataset self._orig_period = ( self.cube_list[0].dim_coords[self._timeaxis].units.num2date( self.cube_list[0].dim_coords[self._timeaxis].points[0]), self.cube_list[-1].dim_coords[self._timeaxis].units.num2date( self.cube_list[-1].dim_coords[self._timeaxis].points[-1]) ) # save the geographical extent x = self.cube_list[0].coord(axis="X", dim_coords=True) y = self.cube_list[0].coord(axis="Y", dim_coords=True) # save the coordinate system self._coord_system = x.coord_system.as_cartopy_crs() if not x.has_bounds(): x.guess_bounds() y.guess_bounds() x_edges = np.concatenate((x.bounds[:,0], np.array([x.bounds[-1,-1]]*y.shape[0]), x.bounds[:,-1], np.array([x.bounds[0,0]]*y.shape[0]))) y_edges = np.concatenate((np.array([y.bounds[0,0]]*x.shape[0]), y.bounds[:,0], np.array([y.bounds[-1,-1]]*x.shape[0]), y.bounds[:,-1])) ll_crs = Geodetic() lon_lat_edges = ll_crs.transform_points( x.coord_system.as_cartopy_crs(), x_edges, y_edges)[:,:-1] east, west = max(lon_lat_edges[:,0]), min(lon_lat_edges[:,0]) north, south = max(lon_lat_edges[:,1]), min(lon_lat_edges[:,1]) self._orig_extent = (north, east, south, west) x.bounds = None y.bounds = None
def _extent_constraint(self): """ if Dataset has an extent set return the geographical constraint with at least one extra line/row at the north/south- and west/east-edge, respectively to guarantee a sufficient large extent for interpolating on a smaller grid. Returns: :class:`iris.Constraint` over the x and y axis """ north, east, south, west = self.extent from matplotlib.path import Path poly = Path([[west, south], [east, south], [east, north], [west, north], [west, south]], closed=True) ll_crs = Geodetic() x = self.cube_list[0].coord(axis='X', dim_coords=True) y = self.cube_list[0].coord(axis='Y', dim_coords=True) dx = x.points[1] - x.points[0] dy = y.points[1] - y.points[0] # get the order of the spatial dimensions xdim = 1 ydim = 0 if self.cube_list[0].coord_dims(x) < self.cube_list[0].coord_dims(y): xdim = 0 ydim = 1 xgrid, ygrid = np.meshgrid(x.points, y.points) ll_field = ll_crs.transform_points(self._coord_system, xgrid, ygrid)[:, :, :2] ll_flat = ll_field.reshape((-1, 2)) mask = poly.contains_points(ll_flat).reshape(xgrid.shape) inside_indices = np.where(mask) minx, maxx = inside_indices[xdim].min(), inside_indices[xdim].max() miny, maxy = inside_indices[ydim].min(), inside_indices[ydim].max() west_bound, east_bound = x.points[minx] - dx, x.points[maxx] + dx south_bound, north_bound = y.points[miny] - dy, y.points[maxy] + dy return iris.Constraint( coord_values={ x.standard_name: lambda cell: west_bound <= cell.point <= east_bound, y.standard_name: lambda cell: south_bound <= cell.point <= north_bound })
def _extent_constraint(self): """ if Dataset has an extent set return the geographical constraint with at least one extra line/row at the north/south- and west/east-edge, respectively to guarantee a sufficient large extent for interpolating on a smaller grid. Returns: iris.Constraint over the x and y axis """ north, east, south, west = self.extent from matplotlib.path import Path poly = Path([[west, south], [east, south], [east, north], [west, north], [west,south]], closed=True) ll_crs = Geodetic() x = self.cube_list[0].coord(axis='X', dim_coords=True) y = self.cube_list[0].coord(axis='Y', dim_coords=True) dx = x.points[1] - x.points[0] dy = y.points[1] - y.points[0] # get the order of the spatial dimensions xdim = 1 ydim = 0 if self.cube_list[0].coord_dims(x) < self.cube_list[0].coord_dims(y): xdim = 0 ydim = 1 xgrid, ygrid = np.meshgrid(x.points, y.points) ll_field = ll_crs.transform_points(self._coord_system, xgrid, ygrid)[:,:,:2] ll_flat = ll_field.reshape((-1,2)) mask = poly.contains_points(ll_flat).reshape(xgrid.shape) inside_indices = np.where(mask) minx, maxx = inside_indices[xdim].min(), inside_indices[xdim].max() miny, maxy = inside_indices[ydim].min(), inside_indices[ydim].max() west_bound, east_bound = x.points[minx]-dx, x.points[maxx]+dx south_bound, north_bound = y.points[miny]-dy, y.points[maxy]+dy return iris.Constraint(coord_values={ x.standard_name: lambda cell: west_bound <= cell.point <= east_bound, y.standard_name: lambda cell: south_bound <= cell.point <= north_bound })
def resetCov(self): for i in range(0, len(self.sat_txt)): self.ax_cov[i].remove() self.sat_txt[i].remove() self.ax_cov = [] self.sat_txt = [] for i in range(0, len(self.Sats)): self.ax_cov.append( self.ax.fill([0, 0], [0, 0], transform=Geodetic(), color='white', alpha=self.cov_alpha)[0]) self.sat_txt.append( self.ax.text([], [], "", color='yellow', size=8, transform=Geodetic(), ha="center"))
def data_gen(self): self.ax_saa, = self.ax.fill([0, 0], [0, 0], color='green', alpha=self.saa_alpha) self.ax_tray, = self.ax.plot([], [], color='green', linewidth=1.5, linestyle='--', transform=Geodetic()) self.ax_sat, = self.ax.plot([], [], 'yo', ms=6) self.ax_cov = [] self.sat_txt = [] self.resetCov()
def ecef_coords(lats: ndarray, lons: ndarray) -> Tuple[ndarray, ndarray, ndarray]: """ Transform latitude-longitude coordinates to earth centred, earth fixed cartesian XYZ coordinates. Args: lats: Latitude coordinates. lons: Longitude coordinates. Returns: - X transformed coordinates. - Y transformed coordinates. - Z transformed coordinates. """ # Cartopy Geodetic and Geocentric both default to the WGS84 datum spherical_latlon_crs = Geodetic() ecef_crs = Geocentric() xyz = ecef_crs.transform_points( spherical_latlon_crs, np.array(lons), np.array(lats) ) return xyz[..., 0], xyz[..., 1], xyz[..., 2]
def __init__(self, directory, filename, constraints=None, callback=None): """ Args: * directory (str): path to the data * filename (str): glob pattern of data files Kwargs: * constraints (:class:`iris.Constraint`): any valid constraint on the data * callback (callable): a function to add metadata to the cube | *function signature*: (cube, field, filename) """ from cartopy.crs import Geodetic self.directory = directory self.filename = filename self.cube_list = iris.load(os.path.join(directory, filename), constraints=constraints, callback=callback) self._orig_standard_name = self.cube_list[0].standard_name self._orig_var_name = self.cube_list[0].var_name self._orig_long_name = self.cube_list[0].long_name self.calendar = self.cube_list[0].coord('time').units.calendar self._orig_units = self.cube_list[0].units for ndim, coord in enumerate(self.cube_list[0].dim_coords): if coord.units.is_time_reference(): self._timeaxis = ndim break # save the period of the entire dataset self._orig_period = ( self.cube_list[0].dim_coords[self._timeaxis].units.num2date( self.cube_list[0].dim_coords[self._timeaxis].points[0]), self.cube_list[-1].dim_coords[self._timeaxis].units.num2date( self.cube_list[-1].dim_coords[self._timeaxis].points[-1] + np.diff(self.cube_list[-1].dim_coords[ self._timeaxis].points)[-1])) # save the geographical extent x = self.cube_list[0].coord(axis="X", dim_coords=True) y = self.cube_list[0].coord(axis="Y", dim_coords=True) # save the coordinate system self._coord_system = x.coord_system.as_cartopy_crs() # make a bounding box in lon/lat # if the dataset consists only of one cell/row/column draw a large # box around it remove_bounds = False if not x.has_bounds(): remove_bounds = True try: x.guess_bounds() except ValueError: x.bounds = np.repeat(x.points, 2) + np.array([-1, 1]) * 30000 try: y.guess_bounds() except ValueError: y.bounds = np.repeat(y.points, 2) + np.array([-1, 1]) * 30000 x_edges = np.concatenate( (x.bounds[:, 0], np.array([x.bounds[-1, -1]] * y.shape[0]), x.bounds[:, -1], np.array([x.bounds[0, 0]] * y.shape[0]))) y_edges = np.concatenate( (np.array([y.bounds[0, 0]] * x.shape[0]), y.bounds[:, 0], np.array([y.bounds[-1, -1]] * x.shape[0]), y.bounds[:, -1])) ll_crs = Geodetic() lon_lat_edges = ll_crs.transform_points( x.coord_system.as_cartopy_crs(), x_edges, y_edges)[:, :-1] east, west = max(lon_lat_edges[:, 0]), min(lon_lat_edges[:, 0]) north, south = max(lon_lat_edges[:, 1]), min(lon_lat_edges[:, 1]) self._orig_extent = (north, east, south, west) if remove_bounds: x.bounds = None y.bounds = None # set the initial temporal and spatial extent self.period = self._orig_period self.extent = self._orig_extent
def addSat(self): add_sat = self.avail_sats_lst.get(self.avail_sats_lst.curselection()) self.ax_cov.append( self.ax.fill([0, 0], [0, 0], transform=Geodetic(), color='white', alpha=self.cov_alpha)[0]) self.sat_txt.append( self.ax.text([], [], "", color='yellow', size=8, transform=Geodetic(), ha="center")) if (add_sat in self.argos): self.createSatFromFile(add_sat, "TLE/argos.txt", "Argos Data Collection System") elif (add_sat in self.cubesat): self.createSatFromFile(add_sat, "TLE/cubesat.txt", "CubeSat") elif (add_sat in self.dmc): self.createSatFromFile(add_sat, "TLE/dmc.txt", "Disaster Monitoring") elif (add_sat in self.goes): self.createSatFromFile(add_sat, "TLE/goes.txt", "GOES") elif (add_sat in self.intelsat): self.createSatFromFile(add_sat, "TLE/intelsat.txt", "Intelsat") elif (add_sat in self.iridium): self.createSatFromFile(add_sat, "TLE/iridium.txt", "Iridium") elif (add_sat in self.iridium_next): self.createSatFromFile(add_sat, "TLE/iridium-NEXT.txt", "Iridium Next") elif (add_sat in self.molniya): self.createSatFromFile(add_sat, "TLE/molniya.txt", "Molniya") elif (add_sat in self.noaa): self.createSatFromFile(add_sat, "TLE/noaa.txt", "NOAA") elif (add_sat in self.planet): self.createSatFromFile(add_sat, "TLE/planet.txt", "Planet") elif (add_sat in self.resource): self.createSatFromFile(add_sat, "TLE/resource.txt", "Earth Resources") elif (add_sat in self.sarsat): self.createSatFromFile(add_sat, "TLE/sarsat.txt", "Search & Rescue") elif (add_sat in self.spire): self.createSatFromFile(add_sat, "TLE/spire.txt", "Spire") elif (add_sat in self.tdrss): self.createSatFromFile(add_sat, "TLE/tdrss.txt", "Tracking and Data Relay") elif (add_sat in self.tle_new): self.createSatFromFile(add_sat, "TLE/tle-new.txt", "Last 30 Days' Launches") elif (add_sat in self.weather): self.createSatFromFile(add_sat, "TLE/weather.txt", "Weather") else: self.Sats.append(Sat(add_sat, tle=tlefile.read(add_sat))) self.curr_sats_lst.insert(END, add_sat) self.sortSats() self.srch_box.focus() for i, sat in enumerate(self.Sats): self.curr_sats_lst.delete(i) self.curr_sats_lst.insert(i, sat.name)
def update_fid(self): self.dataind = self.dataind.reset_index() self.ax2.cla() land = NaturalEarthFeature( category='cultural', name='admin_0_countries', scale='10m', facecolor='none', edgecolor='#524c50', alpha=0.2) self.ax2.add_feature(land, zorder=2) # todo: actual of Schipol are 3.4, 5.41 (3.2 e 5.8) self.ax2.set_extent((3.2, 5.8, 51, 54)) self.ax2.plot(self.dataind.loc[:, 'lon'], self.dataind.loc[:, 'lat'], zorder=4, transform=Geodetic()) # todo:add different color depending on trajectory self.selected.set_visible(True) self.selected.set_data(self.fid._x, self.fid._y) self.text.set_text('selected: ' + self.fid.get_text()) self.ax3.cla() # todo: add correct units depending on featuer self.ax3.set_aspect('auto') self.ax3.plot(self.dataind.loc[:, 'ts'], self.dataind.loc[:, self.extra_feature]) self.fig.canvas.draw()
def __init__(self, directory, filename, constraints=None, callback=None, tmp_directory=None): """ Args: * directory (str): path to the data * filename (str): glob pattern of data files Kwargs: * constraints (:class:`iris.Constraint`): any valid constraint on the data * callback (callable): a function to add metadata to the cube | *function signature*: (cube, field, filename) * tmp_directory (str): path to a write-able directory where intermediate data can be saved defaults to directory/tmp """ from cartopy.crs import Geodetic self.directory = directory self.filename = filename self.tmp_directory = tmp_directory or os.path.join(directory, 'tmp') # try to create the temporary directory # if there are other problems (e.g. permissions) except that it already # exists an exception will be raised try: os.makedirs(self.tmp_directory) except OSError: if not os.path.isdir(self.tmp_directory): raise self.cube_list = iris.load(os.path.join(directory, filename), constraints=constraints, callback=callback) self._orig_standard_name = self.cube_list[0].standard_name self._orig_var_name = self.cube_list[0].var_name self._orig_long_name = self.cube_list[0].long_name self.calendar = self.cube_list[0].coord('time').units.calendar self._orig_units = self.cube_list[0].units for ndim, coord in enumerate(self.cube_list[0].dim_coords): if coord.units.is_time_reference(): self._timeaxis = ndim break # save the period of the entire dataset self._orig_period = ( self.cube_list[0].dim_coords[self._timeaxis].units.num2date( self.cube_list[0].dim_coords[self._timeaxis].points[0]), self.cube_list[-1].dim_coords[self._timeaxis].units.num2date( self.cube_list[-1].dim_coords[self._timeaxis].points[-1] + np.diff( self.cube_list[-1].dim_coords[self._timeaxis].points)[-1] ) ) # save the geographical extent x = self.cube_list[0].coord(axis="X", dim_coords=True) y = self.cube_list[0].coord(axis="Y", dim_coords=True) # Determine source coordinate system if x.coord_system is None: # Assume WGS84 latlon if unspecified warnings.warn('Coordinate system of latitude and longitude ' 'coordinates is not specified. Assuming WGS84 Geodetic.') self._coord_system = iris.coord_systems.GeogCS(semi_major_axis=6378137.0, inverse_flattening=298.257223563).as_cartopy_crs() else: # save the coordinate system self._coord_system = x.coord_system.as_cartopy_crs() remove_bounds = False if not x.has_bounds(): x.guess_bounds() y.guess_bounds() remove_bounds = True x_edges = np.concatenate( (x.bounds[:, 0], np.array([x.bounds[-1, -1]] * y.shape[0]), x.bounds[:, -1], np.array([x.bounds[0, 0]] * y.shape[0]))) y_edges = np.concatenate( (np.array([y.bounds[0, 0]] * x.shape[0]), y.bounds[:, 0], np.array([y.bounds[-1, -1]] * x.shape[0]), y.bounds[:, -1])) ll_crs = Geodetic() lon_lat_edges = ll_crs.transform_points( # x.coord_system.as_cartopy_crs(), x_edges, y_edges)[:, :-1] self._coord_system, x_edges, y_edges)[:, :-1] east, west = max(lon_lat_edges[:, 0]), min(lon_lat_edges[:, 0]) north, south = max(lon_lat_edges[:, 1]), min(lon_lat_edges[:, 1]) self._orig_extent = (north, east, south, west) if remove_bounds: x.bounds = None y.bounds = None