Frequently asked questions

Why an alias ?

the alias property in the astrophysix package is an optional parameter only mandatory within SimulationStudy HDF5 files that are meant to be uploaded on the Galactica simulation database. This optional property can be found in various classes :

The alias must verify a specific format. For more details, see Alias formatting.

These alias properties are used to reference in a unique way the projects, protocols and experiments displayed on the web pages and appear in the URL of your web browser when you wish to visit the page of a given project or simulation. These URLs need to be unique. For example, this is the URL of a ORION_FIL_MHD simulation of the ORION project in the STAR_FORM (ProjectCategory.StarFormation) project category :

How can I check validity for Galactica ?

When you try to upload a SimulationStudy HDF5 file onto the Galactica web application, the server will check the consistency of the project you are trying to upload against the content of the database. These checks are more stringent than the ones performed by astrophysix upon saving the HDF5 file. In case your project cannot be uploaded, a panel showing error messages will be displayed :

_images/galactica_import_error.png

Galactica admin. interface : an error occurred while trying to upload a SimulationStudy HDF5 file on the Galactica web server. The Simulation seems to miss its alias parameter.

This example project was created by the following script, running quite silently :

>>> from astrophysix.simdm import SimulationStudy, Project, ProjectCategory
>>> from astrophysix.simdm.experiment import Simulation
>>> from astrophysix.simdm.protocol import SimulationCode
>>>
>>> # Project creation + study
>>> proj = Project(category=ProjectCategory.StarFormation, alias="ECOGAL_DEMO",
...                project_title="ECOGAL demo project")
>>> study = SimulationStudy(project=proj)
>>>
>>> # Simulation code definition : RAMSES
>>> ramses = SimulationCode(name="Ramses 3.0", code_name="Ramses",
...                         code_version="3.0.1", alias="RAMSES_3")
>>>
>>> # Simulation setup, with alias missing
>>> simu = Simulation(simu_code=ramses, name="ORION MHD run",
...                   description="MHD simulation description",
...                   execution_time="2020-01-01 00:00:00")
>>> # Add simulation into project
>>> proj.simulations.add(simu)
>>>
>>> # Save study in HDF5 file
>>> study.save_HDF5("./orion_study_light.h5")

Upon saving your study HDF5 file

You have the possibility to enable Galactica validity checks upon saving your HDF5 file by adding a galactica_checks=True option to the SimulationStudy.save_HDF5() method :

>>> study.save_HDF5("./orion_study_light.h5", galactica_checks=True)
[WARNING] 'ORION MHD run' simulation Galactica alias is missing.

Which tells you that your Simulation.alias is missing.

SimDM object direct check

You can also directly call the galactica_validity_check() method of any object of your study to perform those checks even prior to saving your SimulationStudy HDF5 file :

>>> simu.galactica_validity_check()
[WARNING] 'ORION MHD run' simulation Galactica alias is missing.

These validity checks include, e.g. :

  • alias format validation,

  • missing parameters in an object,

  • object name/alias unicity,

  • some string parameters maximum length,

  • minimum number of items in catalogs (\(n_{obj} \ge 1\)).

Alias formatting

Valid Galactica aliases are non-empty character string attributes of maximum length 16 which verify the following regular expression pattern : ^[A-Z]([A-Z0-9_]*[A-Z0-9])?$.

>>> simu.alias = "_hydro_RUN_8_"
>>> simu.galactica_validity_check()
[WARNING] 'ORION MHD run' simulation Galactica alias is not valid (The alias can contain capital
letters, digits and '_' only. It must start with a capital letter and cannot end with a '_'.)

See also

FAQ section : Why an alias ?

How to delete object from lists ?

Let us assume that you wish to remove a Snapshot from a Simulation. Then you can use the standard del python operator to remove it :

>>> simu.snapshots
Snapshot list :
+---+---------------------------+--------------------------------------+
| # |           Index           |                 Item                 |
+---+---------------------------+--------------------------------------+
| 0 | My best snapshot !        | 'My best snapshot !' snapshot        |
+---+---------------------------+--------------------------------------+
| 1 | My second best snapshot ! | 'My second best snapshot !' snapshot |
+---+---------------------------+--------------------------------------+
>>> del simu.snapshots[1]
>>> simu.snapshots
Snapshot list :
+---+---------------------------+--------------------------------------+
| # |           Index           |                 Item                 |
+---+---------------------------+--------------------------------------+
| 0 | My best snapshot !        | 'My best snapshot !' snapshot        |
+---+---------------------------+--------------------------------------+

See also

ObjectList example in the API reference.

How to delete files from a Datafile ?

To remove a file from a Datafile, you can use the standard del python operator:

>>> from astrophysix.utils.file import FileType
>>>
>>> power_spectrum_datafile.display_files()
[Power scpectrum] datafile. Attached files :
+-----------+-----------------------------+
| File type |          Filename           |
+-----------+-----------------------------+
| PNG       | spectrum_1.png              |
+-----------+-----------------------------+
| JPEG      | spectrum_with_overlays.jpg  |
+-----------+-----------------------------+
>>>
>>> del power_spectrum_datafile[FileType.PNG_FILE]
>>> power_spectrum_datafile.display_files()
[Power scpectrum] datafile. Attached files :
+-----------+-----------------------------+
| File type |          Filename           |
+-----------+-----------------------------+
| JPEG      | spectrum_with_overlays.jpg  |
+-----------+-----------------------------+

See also

How to add/remove objects in an existing Catalog ?

To modify the size of an existing Catalog, you must first clear it completely and then reinsert new CatalogField instances :

>>> # Catalog contained 200 objects, now we want 354 !
>>> new_fields = [CatalogFields(obj_prop=f.object_property, values=N.random.uniform(size=354))
...               for f in wrong_size_cat.catalog_fields]
>>> for i in range(len(wrong_size_cat.catalog_fields)):  # Empty the object list
...     del wrong_size_cat.catalog_fields[0]
>>> # Add new fields (size: 354)
>>> for new_field in new_fields:
...     wrong_size_cat.catalog_fields.add(nf)