text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def links(self,**args): ''' Return Gist URL-Link, Clone-Link and Script-Link to embed ''' if 'name' in args: self.gist_name = args['name'] self.gist_id = self.getMyID(self.gist_name) elif 'id' in args: self.gist_id = args['id'] else: raise Exception('Gist Name/ID must be provided') if self.gis...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_forecasts(self): """ Load neighborhood probability forecasts. """
run_date_str = self.run_date.strftime("%Y%m%d") forecast_file = self.forecast_path + "{0}/{1}_{2}_{3}_consensus_{0}.nc".format(run_date_str, self.ensemble_name, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_coordinates(self): """ Loads lat-lon coordinates from a netCDF file. """
coord_file = Dataset(self.coordinate_file) if "lon" in coord_file.variables.keys(): self.coordinates["lon"] = coord_file.variables["lon"][:] self.coordinates["lat"] = coord_file.variables["lat"][:] else: self.coordinates["lon"] = coord_file.variables["XLONG"]...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def evaluate_hourly_forecasts(self): """ Calculates ROC curves and Reliability scores for each forecast hour. Returns: A pandas DataFrame containing forecast met...
score_columns = ["Run_Date", "Forecast_Hour", "Ensemble Name", "Model_Name", "Forecast_Variable", "Neighbor_Radius", "Smoothing_Radius", "Size_Threshold", "ROC", "Reliability"] all_scores = pd.DataFrame(columns=score_columns) for h, hour in enumerate(range(self.start_ho...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def evaluate_period_forecasts(self): """ Evaluates ROC and Reliability scores for forecasts over the full period from start hour to end hour Returns: A pandas Da...
score_columns = ["Run_Date", "Ensemble Name", "Model_Name", "Forecast_Variable", "Neighbor_Radius", "Smoothing_Radius", "Size_Threshold", "ROC", "Reliability"] all_scores = pd.DataFrame(columns=score_columns) if self.coordinate_file is not None: coord_mask ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bootstrap_main(args): """ Main function explicitly called from the C++ code. Return the main application object. """
version_info = sys.version_info if version_info.major != 3 or version_info.minor < 6: return None, "python36" main_fn = load_module_as_package("nionui_app.nionswift") if main_fn: return main_fn(["nionui_app.nionswift"] + args, {"pyqt": None}), None return None, "main"
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _migrate_library(workspace_dir: pathlib.Path, do_logging: bool=True) -> pathlib.Path: """ Migrate library to latest version. """
library_path_11 = workspace_dir / "Nion Swift Workspace.nslib" library_path_12 = workspace_dir / "Nion Swift Library 12.nslib" library_path_13 = workspace_dir / "Nion Swift Library 13.nslib" library_paths = (library_path_11, library_path_12) library_path_latest = library_path_13 if not os.pa...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_input_csv_forecast_json(input_csv_file, forecast_json_path, condition_models, dist_models): """ Reads forecasts from json files and merges them with th...
try: run_date = input_csv_file[:-4].split("_")[-1] print(run_date) ens_member = "_".join(input_csv_file.split("/")[-1][:-4].split("_")[3:-1]) ens_name = input_csv_file.split("/")[-1].split("_")[2] input_data = pd.read_csv(input_csv_file, index_col="Step_ID") full_jso...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def mark_data_dirty(self): """ Called from item to indicate its data or metadata has changed."""
self.__cache.set_cached_value_dirty(self.__display_item, self.__cache_property_name) self.__initialize_cache() self.__cached_value_dirty = True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def recompute_if_necessary(self, ui): """Recompute the data on a thread, if necessary. If the data has recently been computed, this call will be rescheduled for ...
self.__initialize_cache() if self.__cached_value_dirty: with self.__is_recomputing_lock: is_recomputing = self.__is_recomputing self.__is_recomputing = True if is_recomputing: pass else: # the only way t...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def recompute_data(self, ui): """Compute the data associated with this processor. This method is thread safe and may take a long time to return. It should not be...
self.__initialize_cache() with self.__recompute_lock: if self.__cached_value_dirty: try: calculated_data = self.get_calculated_data(ui) except Exception as e: import traceback traceback.print_exc() ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def thumbnail_source_for_display_item(self, ui, display_item: DisplayItem.DisplayItem) -> ThumbnailSource: """Returned ThumbnailSource must be closed."""
with self.__lock: thumbnail_source = self.__thumbnail_sources.get(display_item) if not thumbnail_source: thumbnail_source = ThumbnailSource(ui, display_item) self.__thumbnail_sources[display_item] = thumbnail_source def will_delete(thumbn...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def getMyID(self,gist_name): ''' Getting gistID of a gist in order to make the workflow easy and uninterrupted. ''' r = requests.get( '%s'%BASE_URL+'/users/%s/gists' % self.user, headers=self.gist.header ) if (r.status_code == 200): r_text = json.loads(r.text) limit = len(r.json()) for g,...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def close(self): """Close the document controller. This method must be called to shut down the document controller. There are several paths by which it can be ca...
assert self.__closed == False self.__closed = True self.finish_periodic() # required to finish periodic operations during tests # dialogs for weak_dialog in self.__dialogs: dialog = weak_dialog() if dialog: try: dialog...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_periodic(self, interval: float, listener_fn): """Add a listener function and return listener token. Token can be closed or deleted to unlisten."""
class PeriodicListener: def __init__(self, interval: float, listener_fn): self.interval = interval self.__listener_fn = listener_fn # the call function is very performance critical; make it fast by using a property # instead of a logic...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __update_display_items_model(self, display_items_model: ListModel.FilteredListModel, data_group: typing.Optional[DataGroup.DataGroup], filter_id: typing.Optio...
with display_items_model.changes(): # change filter and sort together if data_group is not None: display_items_model.container = data_group display_items_model.filter = ListModel.Filter(True) display_items_model.sort_key = None displ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def focused_data_item(self) -> typing.Optional[DataItem.DataItem]: """Return the data item with keyboard focus."""
return self.__focused_display_item.data_item if self.__focused_display_item else None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def selected_display_item(self) -> typing.Optional[DisplayItem.DisplayItem]: """Return the selected display item. The selected display is the display ite that has...
# first check for the [focused] data browser display_item = self.focused_display_item if not display_item: selected_display_panel = self.selected_display_panel display_item = selected_display_panel.display_item if selected_display_panel else None return display_i...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _get_two_data_sources(self): """Get two sensible data sources, which may be the same."""
selected_display_items = self.selected_display_items if len(selected_display_items) < 2: selected_display_items = list() display_item = self.selected_display_item if display_item: selected_display_items.append(display_item) if len(selected_dis...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def calculate_origin_and_size(canvas_size, data_shape, image_canvas_mode, image_zoom, image_position) -> typing.Tuple[typing.Any, typing.Any]: """Calculate origin...
if data_shape is None: return None, None if image_canvas_mode == "fill": data_shape = data_shape scale_h = float(data_shape[1]) / canvas_size[1] scale_v = float(data_shape[0]) / canvas_size[0] if scale_v < scale_h: image_canvas_size = (canvas_size[0], canvas_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def auto_migrate_storage_system(*, persistent_storage_system=None, new_persistent_storage_system=None, data_item_uuids=None, deletions: typing.List[uuid.UUID] = N...
storage_handlers = persistent_storage_system.find_data_items() ReaderInfo = collections.namedtuple("ReaderInfo", ["properties", "changed_ref", "large_format", "storage_handler", "identifier"]) reader_info_list = list() for storage_handler in storage_handlers: try: large_format = isi...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def from_pypirc(pypi_repository): """ Load configuration from .pypirc file, cached to only run once """
ret = {} pypirc_locations = PYPIRC_LOCATIONS for pypirc_path in pypirc_locations: pypirc_path = os.path.expanduser(pypirc_path) if os.path.isfile(pypirc_path): parser = configparser.SafeConfigParser() parser.read(pypirc_path) if 'distutils' not in parser....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pypirc_temp(index_url): """ Create a temporary pypirc file for interaction with twine """
pypirc_file = tempfile.NamedTemporaryFile(suffix='.pypirc', delete=False) print(pypirc_file.name) with open(pypirc_file.name, 'w') as fh: fh.write(PYPIRC_TEMPLATE.format(index_name=PYPIRC_TEMP_INDEX_NAME, index_url=index_url)) return pypirc_file.name
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_api(version: str, ui_version: str=None) -> API_1: """Get a versioned interface matching the given version and ui_version. version is a string in the form ...
ui_version = ui_version if ui_version else "~1.0" return _get_api_with_app(version, ui_version, ApplicationModule.app)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def mask_xdata_with_shape(self, shape: DataAndMetadata.ShapeType) -> DataAndMetadata.DataAndMetadata: """Return the mask created by this graphic as extended data....
mask = self._graphic.get_mask(shape) return DataAndMetadata.DataAndMetadata.from_data(mask)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def data(self, data: numpy.ndarray) -> None: """Set the data. :param data: A numpy ndarray. .. versionadded:: 1.0 Scriptable: Yes """
self.__data_item.set_data(numpy.copy(data))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def display_xdata(self) -> DataAndMetadata.DataAndMetadata: """Return the extended data of this data item display. Display data will always be 1d or 2d and either...
display_data_channel = self.__display_item.display_data_channel return display_data_channel.get_calculated_display_values(True).display_data_and_metadata
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_dimensional_calibrations(self, dimensional_calibrations: typing.List[CalibrationModule.Calibration]) -> None: """Set the dimensional calibrations. :param ...
self.__data_item.set_dimensional_calibrations(dimensional_calibrations)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def graphics(self) -> typing.List[Graphic]: """Return the graphics attached to this data item. .. versionadded:: 1.0 Scriptable: Yes """
return [Graphic(graphic) for graphic in self.__display_item.graphics]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_point_region(self, y: float, x: float) -> Graphic: """Add a point graphic to the data item. :param x: The x coordinate, in relative units [0.0, 1.0] :para...
graphic = Graphics.PointGraphic() graphic.position = Geometry.FloatPoint(y, x) self.__display_item.add_graphic(graphic) return Graphic(graphic)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def mask_xdata(self) -> DataAndMetadata.DataAndMetadata: """Return the mask by combining any mask graphics on this data item as extended data. .. versionadded:: 1...
display_data_channel = self.__display_item.display_data_channel shape = display_data_channel.display_data_shape mask = numpy.zeros(shape) for graphic in self.__display_item.graphics: if isinstance(graphic, (Graphics.SpotGraphic, Graphics.WedgeGraphic, Graphics.RingGraphic, G...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def data_item(self) -> DataItem: """Return the data item associated with this display panel. .. versionadded:: 1.0 Scriptable: Yes """
display_panel = self.__display_panel if not display_panel: return None data_item = display_panel.data_item return DataItem(data_item) if data_item else None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_data_item(self, data_item: DataItem) -> None: """Set the data item associated with this display panel. :param data_item: The :py:class:`nion.swift.Facade....
display_panel = self.__display_panel if display_panel: display_item = data_item._data_item.container.get_display_item_for_data_item(data_item._data_item) if data_item._data_item.container else None display_panel.set_display_panel_display_item(display_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_data_item(self, data_item: DataItem) -> None: """Add a data item to the group. :param data_item: The :py:class:`nion.swift.Facade.DataItem` object to add....
display_item = data_item._data_item.container.get_display_item_for_data_item(data_item._data_item) if data_item._data_item.container else None if display_item: self.__data_group.append_display_item(display_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def close(self) -> None: """Close the task. .. versionadded:: 1.0 This method must be called when the task is no longer needed. """
self.__data_channel_buffer.stop() self.__data_channel_buffer.close() self.__data_channel_buffer = None if not self.__was_playing: self.__hardware_source.stop_playing()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def record(self, frame_parameters: dict=None, channels_enabled: typing.List[bool]=None, timeout: float=None) -> typing.List[DataAndMetadata.DataAndMetadata]: """R...
if frame_parameters: self.__hardware_source.set_record_frame_parameters(self.__hardware_source.get_frame_parameters_from_dict(frame_parameters)) if channels_enabled is not None: for channel_index, channel_enabled in enumerate(channels_enabled): self.__hardware_so...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_record_task(self, frame_parameters: dict=None, channels_enabled: typing.List[bool]=None) -> RecordTask: """Create a record task for this hardware sourc...
return RecordTask(self.__hardware_source, frame_parameters, channels_enabled)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def grab_next_to_finish(self, timeout: float=None) -> typing.List[DataAndMetadata.DataAndMetadata]: """Grabs the next frame to finish and returns it as data and m...
self.start_playing() return self.__hardware_source.get_next_xdatas_to_finish(timeout)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_control_output(self, name: str, value: float, *, options: dict=None) -> None: """Set the value of a control asynchronously. :param name: The name of the c...
self.__instrument.set_control_output(name, value, options)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_property_as_float(self, name: str) -> float: """Return the value of a float property. :return: The property value (float). Raises exception if property wi...
return float(self.__instrument.get_property(name))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_property_as_float(self, name: str, value: float) -> None: """Set the value of a float property. :param name: The name of the property (string). :param val...
self.__instrument.set_property(name, float(value))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def data_items(self) -> typing.List[DataItem]: """Return the list of data items. :return: The list of :py:class:`nion.swift.Facade.DataItem` objects. .. versionad...
return [DataItem(data_item) for data_item in self.__document_model.data_items]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def display_items(self) -> typing.List[Display]: """Return the list of display items. :return: The list of :py:class:`nion.swift.Facade.Display` objects. .. versi...
return [Display(display_item) for display_item in self.__document_model.display_items]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_source_data_items(self, data_item: DataItem) -> typing.List[DataItem]: """Return the list of data items that are data sources for the data item. :return: ...
return [DataItem(data_item) for data_item in self._document_model.get_source_data_items(data_item._data_item)] if data_item else None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_dependent_data_items(self, data_item: DataItem) -> typing.List[DataItem]: """Return the dependent data items the data item argument. :return: The list of ...
return [DataItem(data_item) for data_item in self._document_model.get_dependent_data_items(data_item._data_item)] if data_item else None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_data_item(self, title: str=None) -> DataItem: """Create an empty data item in the library. :param title: The title of the data item (optional). :return...
data_item = DataItemModule.DataItem() data_item.ensure_data_source() if title is not None: data_item.title = title self.__document_model.append_data_item(data_item) return DataItem(data_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_data_item_from_data(self, data: numpy.ndarray, title: str=None) -> DataItem: """Create a data item in the library from an ndarray. The data for the dat...
return self.create_data_item_from_data_and_metadata(DataAndMetadata.DataAndMetadata.from_data(data), title)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_data_item_from_data_and_metadata(self, data_and_metadata: DataAndMetadata.DataAndMetadata, title: str=None) -> DataItem: """Create a data item in the l...
data_item = DataItemModule.new_data_item(data_and_metadata) if title is not None: data_item.title = title self.__document_model.append_data_item(data_item) return DataItem(data_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def copy_data_item(self, data_item: DataItem) -> DataItem: """Copy a data item. .. versionadded:: 1.0 Scriptable: No """
data_item = copy.deepcopy(data_item._data_item) self.__document_model.append_data_item(data_item) return DataItem(data_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def snapshot_data_item(self, data_item: DataItem) -> DataItem: """Snapshot a data item. Similar to copy but with a data snapshot. .. versionadded:: 1.0 Scriptable...
data_item = data_item._data_item.snapshot() self.__document_model.append_data_item(data_item) return DataItem(data_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_data_item_by_uuid(self, data_item_uuid: uuid_module.UUID) -> DataItem: """Get the data item with the given UUID. .. versionadded:: 1.0 Status: Provisional...
data_item = self._document_model.get_data_item_by_uuid(data_item_uuid) return DataItem(data_item) if data_item else None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_graphic_by_uuid(self, graphic_uuid: uuid_module.UUID) -> Graphic: """Get the graphic with the given UUID. .. versionadded:: 1.0 Status: Provisional Script...
for display_item in self._document_model.display_items: for graphic in display_item.graphics: if graphic.uuid == graphic_uuid: return Graphic(graphic) return None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def has_library_value(self, key: str) -> bool: """Return whether the library value for the given key exists. Please consult the developer documentation for a list...
desc = Metadata.session_key_map.get(key) if desc is not None: field_id = desc['path'][-1] return bool(getattr(ApplicationData.get_session_metadata_model(), field_id, None)) return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_library_value(self, key: str) -> typing.Any: """Get the library value for the given key. Please consult the developer documentation for a list of valid ke...
desc = Metadata.session_key_map.get(key) if desc is not None: field_id = desc['path'][-1] return getattr(ApplicationData.get_session_metadata_model(), field_id) raise KeyError()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_library_value(self, key: str, value: typing.Any) -> None: """Set the library value for the given key. Please consult the developer documentation for a lis...
desc = Metadata.session_key_map.get(key) if desc is not None: field_id = desc['path'][-1] setattr(ApplicationData.get_session_metadata_model(), field_id, value) return raise KeyError()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete_library_value(self, key: str) -> None: """Delete the library value for the given key. Please consult the developer documentation for a list of valid ke...
desc = Metadata.session_key_map.get(key) if desc is not None: field_id = desc['path'][-1] setattr(ApplicationData.get_session_metadata_model(), field_id, None) return raise KeyError()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def all_display_panels(self) -> typing.List[DisplayPanel]: """Return the list of display panels currently visible. .. versionadded:: 1.0 Scriptable: Yes """
return [DisplayPanel(display_panel) for display_panel in self.__document_controller.workspace_controller.display_panels]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_display_panel_by_id(self, identifier: str) -> DisplayPanel: """Return display panel with the identifier. .. versionadded:: 1.0 Status: Provisional Scripta...
display_panel = next( (display_panel for display_panel in self.__document_controller.workspace_controller.display_panels if display_panel.identifier.lower() == identifier.lower()), None) return DisplayPanel(display_panel) if display_panel else None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def display_data_item(self, data_item: DataItem, source_display_panel=None, source_data_item=None): """Display a new data item and gives it keyboard focus. Uses ...
for display_panel in self.__document_controller.workspace_controller.display_panels: if display_panel.data_item == data_item._data_item: display_panel.request_focus() return DisplayPanel(display_panel) result_display_panel = self.__document_controller.next_re...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_data_item_from_data(self, data: numpy.ndarray, title: str=None) -> DataItem: """Create a data item in the library from data. .. versionadded:: 1.0 .. d...
return DataItem(self.__document_controller.add_data(data, title))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_data_item_from_data_and_metadata(self, data_and_metadata: DataAndMetadata.DataAndMetadata, title: str=None) -> DataItem: """Create a data item in the l...
data_item = DataItemModule.new_data_item(data_and_metadata) if title is not None: data_item.title = title self.__document_controller.document_model.append_data_item(data_item) return DataItem(data_item)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def document_windows(self) -> typing.List[DocumentWindow]: """Return the document windows. .. versionadded:: 1.0 Scriptable: Yes """
return [DocumentWindow(document_controller) for document_controller in self.__application.document_controllers]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_panel(self, panel_delegate): """Create a utility panel that can be attached to a window. .. versionadded:: 1.0 Scriptable: No The panel_delegate shoul...
panel_id = panel_delegate.panel_id panel_name = panel_delegate.panel_name panel_positions = getattr(panel_delegate, "panel_positions", ["left", "right"]) panel_position = getattr(panel_delegate, "panel_position", "none") properties = getattr(panel_delegate, "panel_properties", ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_hardware_source_by_id(self, hardware_source_id: str, version: str): """Return the hardware source API matching the hardware_source_id and version. .. ver...
actual_version = "1.0.0" if Utility.compare_versions(version, actual_version) > 0: raise NotImplementedError("Hardware API requested version %s is greater than %s." % (version, actual_version)) hardware_source = HardwareSourceModule.HardwareSourceManager().get_hardware_source_for_ha...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def library(self) -> Library: """Return the library object. .. versionadded:: 1.0 Scriptable: Yes """
assert self.__app.document_model return Library(self.__app.document_model)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pad_matrix(self, matrix, pad_value=0): """ Pad a possibly non-square matrix to make it square. :Parameters: matrix : list of lists matrix to pad pad_value : ...
max_columns = 0 total_rows = len(matrix) for row in matrix: max_columns = max(max_columns, len(row)) total_rows = max(max_columns, total_rows) new_matrix = [] for row in matrix: row_len = len(row) new_row = row[:] if tot...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __step1(self): """ For each row of the matrix, find the smallest element and subtract it from every element in its row. Go to Step 2. """
C = self.C n = self.n for i in range(n): minval = min(self.C[i]) # Find the minimum value for this row and subtract that minimum # from every element in the row. for j in range(n): self.C[i][j] -= minval return 2
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __step3(self): """ Cover each column containing a starred zero. If K columns are covered, the starred zeros describe a complete set of unique assignments. In...
n = self.n count = 0 for i in range(n): for j in range(n): if self.marked[i][j] == 1: self.col_covered[j] = True count += 1 if count >= n: step = 7 # done else: step = 4 return ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __step4(self): """ Find a noncovered zero and prime it. If there is no starred zero in the row containing this primed zero, Go to Step 5. Otherwise, cover th...
step = 0 done = False row = -1 col = -1 star_col = -1 while not done: (row, col) = self.__find_a_zero() if row < 0: done = True step = 6 else: self.marked[row][col] = 2 st...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __step6(self): """ Add the value found in Step 4 to every element of each covered row, and subtract it from every element of each uncovered column. Return to...
minval = self.__find_smallest() for i in range(self.n): for j in range(self.n): if self.row_covered[i]: self.C[i][j] += minval if not self.col_covered[j]: self.C[i][j] -= minval return 4
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __find_smallest(self): """Find the smallest uncovered value in the matrix."""
minval = sys.maxsize for i in range(self.n): for j in range(self.n): if (not self.row_covered[i]) and (not self.col_covered[j]): if minval > self.C[i][j]: minval = self.C[i][j] return minval
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __find_a_zero(self): """Find the first uncovered element with value 0"""
row = -1 col = -1 i = 0 n = self.n done = False while not done: j = 0 while True: if (self.C[i][j] == 0) and \ (not self.row_covered[i]) and \ (not self.col_covered[j]): ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __find_star_in_row(self, row): """ Find the first starred element in the specified row. Returns the column index, or -1 if no starred element was found. """
col = -1 for j in range(self.n): if self.marked[row][j] == 1: col = j break return col
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __find_star_in_col(self, col): """ Find the first starred element in the specified row. Returns the row index, or -1 if no starred element was found. """
row = -1 for i in range(self.n): if self.marked[i][col] == 1: row = i break return row
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __find_prime_in_row(self, row): """ Find the first prime element in the specified row. Returns the column index, or -1 if no starred element was found. """
col = -1 for j in range(self.n): if self.marked[row][j] == 2: col = j break return col
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __clear_covers(self): """Clear all covered matrix cells"""
for i in range(self.n): self.row_covered[i] = False self.col_covered[i] = False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __erase_primes(self): """Erase all prime markings"""
for i in range(self.n): for j in range(self.n): if self.marked[i][j] == 2: self.marked[i][j] = 0
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, a, b, c, d): """ Update contingency table with new values without creating a new object. """
self.table.ravel()[:] = [a, b, c, d] self.N = self.table.sum()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def output_tree_ensemble(tree_ensemble_obj, output_filename, attribute_names=None): """ Write each decision tree in an ensemble to a file. Parameters tree_ensemb...
for t, tree in enumerate(tree_ensemble_obj.estimators_): print("Writing Tree {0:d}".format(t)) out_file = open(output_filename + ".{0:d}.tree", "w") #out_file.write("Tree {0:d}\n".format(t)) tree_str = print_tree_recursive(tree.tree_, 0, attribute_names) out_file.write(tree_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def print_tree_recursive(tree_obj, node_index, attribute_names=None): """ Recursively writes a string representation of a decision tree object. Parameters tree_o...
tree_str = "" if node_index == 0: tree_str += "{0:d}\n".format(tree_obj.node_count) if tree_obj.feature[node_index] >= 0: if attribute_names is None: attr_val = "{0:d}".format(tree_obj.feature[node_index]) else: attr_val = attribute_names[tree_obj.feature[nod...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def fitness_vs(self, v): """Fitness function in the validation set In classification it uses BER and RSE in regression"""
base = self._base if base._classifier: if base._multiple_outputs: v.fitness_vs = v._error # if base._fitness_function == 'macro-F1': # v.fitness_vs = v._error # elif base._fitness_function == 'BER': # v....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_fitness(self, v): """Set the fitness to a new node. Returns false in case fitness is not finite"""
base = self._base self.fitness(v) if not np.isfinite(v.fitness): self.del_error(v) return False if base._tr_fraction < 1: self.fitness_vs(v) if not np.isfinite(v.fitness_vs): self.del_error(v) return False ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def output_sector_csv(self,csv_path,file_dict_key,out_path): """ Segment forecast tracks to only output data contined within a region in the CONUS, as defined by...
csv_file = csv_path + "{0}_{1}_{2}_{3}.csv".format( file_dict_key, self.ensemble_name, self.member, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def clean_dict(d0, clean_item_fn=None): """ Return a json-clean dict. Will log info message for failures. """
clean_item_fn = clean_item_fn if clean_item_fn else clean_item d = dict() for key in d0: cleaned_item = clean_item_fn(d0[key]) if cleaned_item is not None: d[key] = cleaned_item return d
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def clean_list(l0, clean_item_fn=None): """ Return a json-clean list. Will log info message for failures. """
clean_item_fn = clean_item_fn if clean_item_fn else clean_item l = list() for index, item in enumerate(l0): cleaned_item = clean_item_fn(item) l.append(cleaned_item) return l
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def clean_tuple(t0, clean_item_fn=None): """ Return a json-clean tuple. Will log info message for failures. """
clean_item_fn = clean_item_fn if clean_item_fn else clean_item l = list() for index, item in enumerate(t0): cleaned_item = clean_item_fn(item) l.append(cleaned_item) return tuple(l)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sample_stack_all(count=10, interval=0.1): """Sample the stack in a thread and print it at regular intervals."""
def print_stack_all(l, ll): l1 = list() l1.append("*** STACKTRACE - START ***") code = [] for threadId, stack in sys._current_frames().items(): sub_code = [] sub_code.append("# ThreadID: %s" % threadId) for filename, lineno, name, line in traceba...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def _eval(self): "Evaluates a individual using recursion and self._pos as pointer" pos = self._pos self._pos += 1 node = self._ind[pos] if isinstance(node, Function): args = [self._eval() for x in range(node.nargs)] node.eval(args) for x in arg...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def create_random_ind_full(self, depth=0): "Random individual using full method" lst = [] self._create_random_ind_full(depth=depth, output=lst) return lst
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def grow_use_function(self, depth=0): "Select either function or terminal in grow method" if depth == 0: return False if depth == self._depth: return True return np.random.random() < 0.5
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def create_random_ind_grow(self, depth=0): "Random individual using grow method" lst = [] self._depth = depth self._create_random_ind_grow(depth=depth, output=lst) return lst
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def create_population(self, popsize=1000, min_depth=2, max_depth=4, X=None): "Creates random population using ramped half-and-half method" import itertools args = [x for x in itertools.product(range(min_depth, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def fitness_vs(self): "Median Fitness in the validation set" l = [x.fitness_vs for x in self.models] return np.median(l)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def graphviz(self, directory, **kwargs): "Directory to store the graphviz models" import os if not os.path.isdir(directory): os.mkdir(directory) output = os.path.join(directory, 'evodag-%s') for k, m in enumerate(self.models): m.graphviz(output % k, **kwar...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def neighborhood_probability(self, threshold, radius): """ Calculate a probability based on the number of grid points in an area that exceed a threshold. Args: t...
weights = disk(radius, dtype=np.uint8) thresh_data = np.zeros(self.data.shape[1:], dtype=np.uint8) neighbor_prob = np.zeros(self.data.shape, dtype=np.float32) for t in np.arange(self.data.shape[0]): thresh_data[self.data[t] >= threshold] = 1 maximized = fftconvol...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_data(self): """ Loads data from each ensemble member. """
for m, member in enumerate(self.members): mo = ModelOutput(self.ensemble_name, member, self.run_date, self.variable, self.start_date, self.end_date, self.path, self.map_file, self.single_step) mo.load_data() if self.data is None: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def point_consensus(self, consensus_type): """ Calculate grid-point statistics across ensemble members. Args: consensus_type: mean, std, median, max, or percenti...
if "mean" in consensus_type: consensus_data = np.mean(self.data, axis=0) elif "std" in consensus_type: consensus_data = np.std(self.data, axis=0) elif "median" in consensus_type: consensus_data = np.median(self.data, axis=0) elif "max" in consensus_ty...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def point_probability(self, threshold): """ Determine the probability of exceeding a threshold at a grid point based on the ensemble forecasts at that point. Arg...
point_prob = np.zeros(self.data.shape[1:]) for t in range(self.data.shape[1]): point_prob[t] = np.where(self.data[:, t] >= threshold, 1.0, 0.0).mean(axis=0) return EnsembleConsensus(point_prob, "point_probability", self.ensemble_name, self.run_date, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def neighborhood_probability(self, threshold, radius, sigmas=None): """ Hourly probability of exceeding a threshold based on model values within a specified radi...
if sigmas is None: sigmas = [0] weights = disk(radius) filtered_prob = [] for sigma in sigmas: filtered_prob.append(EnsembleConsensus(np.zeros(self.data.shape[1:], dtype=np.float32), "neighbor_prob_r_{0:d}_s_{1:d...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def period_max_neighborhood_probability(self, threshold, radius, sigmas=None): """ Calculates the neighborhood probability of exceeding a threshold at any time o...
if sigmas is None: sigmas = [0] weights = disk(radius) neighborhood_prob = np.zeros(self.data.shape[2:], dtype=np.float32) thresh_data = np.zeros(self.data.shape[2:], dtype=np.uint8) for m in range(self.data.shape[0]): thresh_data[self.data[m].max(axis=0)...