.. _model_views: Model Videos ============ Videos from a model can be extracted after the simulation has been completed. This functionality internally uses the orcaflex `AVI video extraction `_ functionality and can be used to extract multiple videos with different model views and video parameters for the same model Defining video parameters ------------------------- Video specification parameters can be defined using a sequence of ``qalx_orcaflexdata_models.VideoSpecification`` instances. Only ``start_time`` and ```end_time`` are required parameters and default values are used for any unspecified specification parameters. .. note:: The ``model_views`` parameter accepts an optional list of ``ModelView`` instances, and a video will be extracted for each one of these views. In the case that the ``model_views`` parameter is not specified, only a single video with the default model view will be extracted for that specific instance of VideoSpecification .. code-block:: python from qalx_orcaflex import data_models as dm view_1 = dm.ModelView(ViewName="Front view", ViewAzimuth=270.0) view_2 = dm.ModelView(ViewName="Side view", ViewAzimuth=315.0) video_parameters = dm.VideoSpecification( start_time=-8.0, end_time=16.0, width=600, height=600, codec="MRLE", model_views=[view_1, view_2] ) Usage ----- The example below shows how to extract two videos per model in a batch, using a different azimuth .. code-block:: python import OrcFxAPI as ofx import qalx_orcaflex.data_models as dm from qalx_orcaflex.core import ModelSource, OrcaFlexBatch, QalxOrcaFlex qfx = QalxOrcaFlex() batch_options = dm.BatchOptions( batch_queue="example-batch-queue", sim_queue="example-sim-queue", ) with OrcaFlexBatch(name=f"My Hang-off Batch", session=qfx, batch_options=batch_options) as batch: m = ofx.Model() line = m.CreateObject(ofx.otLine, "My Line") for end_b_x in range(40, 80, 10): line.EndBX = end_b_x hang_off = 250 - end_b_x hang_off_info = dm.RawInfo( key="Hang-off point", value=hang_off ) view_1 = dm.ModelView( ViewName=f"Front of hang-off @ {hang_off}m", ViewSize=50.0, ViewCentre=[end_b_x, 0.0, -21.5], ViewAzimuth=270.0, ViewGamma=0.0, ViewElevation=0.0, Width=1500, Height=800, GraphicsMode="WireFrame", ) view_2 = dm.ModelView( ViewName=f"Side of hang-off @ {hang_off}m", ViewSize=50.0, ViewCentre=[end_b_x, 0.0, -21.5], ViewAzimuth=315.0, ViewGamma=0.0, ViewElevation=0.0, Width=1500, Height=800, GraphicsMode="WireFrame", ) current_speed = dm.ModelInfo( object_name="Environment", data_name="RefCurrentSpeed", alias="Current Speed" ) load_case_info = dm.LoadCaseInfo( model_info=[current_speed], raw_info=[hang_off_info]) video_specification = [ dm.VideoSpecification( start_time=-8.0, end_time=16.0, model_views=[view_1, view_2] ) ] batch.add( ModelSource(m, f"HangOff={hang_off}"), load_case_info=load_case_info, model_videos=[video_specification] ) .. note:: The ``model_videos`` parameter passed to the ``add`` method needs to be a sequence, e.g. a ``list`` even in the case that only one instance of ``ViewSpecification`` is passed In the case that no ``model_views`` are specified one video will be extracted with the default model view. In the following example, one such instance of ``ViewSpecification`` is created, along with a second instance: .. code-block:: python import OrcFxAPI as ofx import qalx_orcaflex.data_models as dm from qalx_orcaflex.core import ModelSource, OrcaFlexBatch, QalxOrcaFlex qfx = QalxOrcaFlex() batch_options = dm.BatchOptions( batch_queue="example-batch-queue", sim_queue="example-sim-queue", ) with OrcaFlexBatch(name=f"My Hang-off Batch", session=qfx, batch_options=batch_options) as batch: m = ofx.Model() line = m.CreateObject(ofx.otLine, "My Line") for end_b_x in range(40, 80, 10): line.EndBX = end_b_x hang_off = 250 - end_b_x hang_off_info = dm.RawInfo( key="Hang-off point", value=hang_off ) current_speed = dm.ModelInfo( object_name="Environment", data_name="RefCurrentSpeed", alias="Current Speed" ) load_case_info = dm.LoadCaseInfo( model_info=[current_speed], raw_info=[hang_off_info]) video_spec_1 = dm.VideoSpecification( start_time=4.0, end_time=10.0, ) view_1 = dm.ModelView( ViewName=f"Front of hang-off @ {hang_off}m", ViewSize=50.0, ViewCentre=[end_b_x, 0.0, -21.5], ) video_spec_2 = dm.VideoSpecification( start_time=-8.0, end_time=16.0, model_views=[view_1] ) batch.add( ModelSource(m, f"HangOff={hang_off}"), load_case_info=load_case_info, model_videos=[video_spec_1, video_spec_2] ) In this example, for each model in the ``for`` loop, two videos will be extracted. One video from 4.0 sec to 10.0 sec and the default model view and one video from -8.0 sec to 16.0 sec with the custom ``view_1`` view Download videos from a batch ---------------------------- Videos specified on a batch can be then downloaded as shown below .. code-block:: python from qalx_orcaflex.core import QalxOrcaFlex qfx = QalxOrcaFlex() qfx.save_batch_videos( batch_name="My Hang-off Batch", save_dir=r"C:/Users/AnneAlysis/OFX/Hang-offBatch/Videos" ) Extract videos from a sim file ------------------------------ In the case that you are interested in extracting a video from an existing simulation file(``.sim``), you can do this using the functionality of the :ref:`video_bot`. A job can be send to the bot as shown below .. code-block:: python from qalx_orcaflex.core import QalxOrcaFlex from qalx_orcaflex.data_models import OrcaFlexJob, ModelView, VideoSpecification qfx = QalxOrcaFlex() # Add the required videos specification model_view_1 = ModelView("View 1") model_view_2 = ModelView("View 2", ViewAzimuth=100.0, ViewElevation=1.0) model_view_3 = ModelView("View 3", ViewAzimuth=200.0, ViewElevation=-1.0) model_videos = [ VideoSpecification( start_time=-8.0, end_time=15.9, width=200, height=200, model_views=[model_view_1, model_view_2], ), VideoSpecification( start_time=-8.0, end_time=15.9, width=200, height=200, codec="XVID", model_views=[model_view_3], ), ] # Add the sim file item qalx_sim_item = qfx.item.add(source="/path/to/sim_file/simple_model.sim") videos_job = OrcaFlexJob(model_videos=model_videos, sim_file=qalx_sim_item) qfx.save_batch_videos( batch_name="My Hang-off Batch", save_dir=r"C:/Users/AnneAlysis/OFX/Hang-offBatch/Videos" ) # Send the job to the queue named "video-queue-example" video_set_guid = qfx.send_to_video_sim_queue( queue_name="video-queue-example", ofx_job=videos_job ) # Once the video extraction process is complete, we can download the videos qfx.save_job_videos(video_set_guid, "/path/to/save/location")