|
115 | 115 | ureg.define("atom = 1") |
116 | 116 | ureg.define("bohr_magneton = e * hbar / (2 * m_e) = µᵇ = µ_B = mu_B") |
117 | 117 | ureg.define("electron_mass = 9.1093837015e-31 kg = mₑ = m_e") |
| 118 | +ureg.define("sccm = cm³/min") |
118 | 119 |
|
119 | 120 | LOG_LEVEL = os.environ.get("MPCONTRIBS_CLIENT_LOG_LEVEL", "INFO") |
120 | 121 | log_level = getattr(logging, LOG_LEVEL.upper()) |
@@ -1402,7 +1403,7 @@ def get_attachment(self, aid_or_md5: str) -> Type[Attachment]: |
1402 | 1403 | self.attachments.getAttachmentById(pk=aid, _fields=["_all"]).result() |
1403 | 1404 | ) |
1404 | 1405 |
|
1405 | | - def init_columns(self, columns: dict = None) -> dict: |
| 1406 | + def init_columns(self, columns: dict = None, name: str = None) -> dict: |
1406 | 1407 | """initialize columns for a project to set their order and desired units |
1407 | 1408 |
|
1408 | 1409 | The `columns` field of a project tracks the minima and maxima of each `data` field |
@@ -1435,8 +1436,11 @@ def init_columns(self, columns: dict = None) -> dict: |
1435 | 1436 | Args: |
1436 | 1437 | columns (dict): dictionary mapping data column to its unit |
1437 | 1438 | """ |
1438 | | - if not self.project: |
1439 | | - raise MPContribsClientError("initialize client with project argument!") |
| 1439 | + name = self.project or name |
| 1440 | + if not name: |
| 1441 | + raise MPContribsClientError( |
| 1442 | + "initialize client with project or set `name` argument!" |
| 1443 | + ) |
1440 | 1444 |
|
1441 | 1445 | columns = flatten(columns or {}, reducer="dot") |
1442 | 1446 |
|
@@ -1497,9 +1501,7 @@ def init_columns(self, columns: dict = None) -> dict: |
1497 | 1501 |
|
1498 | 1502 | # TODO catch unsupported column renaming or implement solution |
1499 | 1503 | # reconcile with existing columns |
1500 | | - resp = self.projects.getProjectByName( |
1501 | | - pk=self.project, _fields=["columns"] |
1502 | | - ).result() |
| 1504 | + resp = self.projects.getProjectByName(pk=name, _fields=["columns"]).result() |
1503 | 1505 | existing_columns = {} |
1504 | 1506 |
|
1505 | 1507 | for col in resp["columns"]: |
@@ -1556,9 +1558,7 @@ def init_columns(self, columns: dict = None) -> dict: |
1556 | 1558 | if not valid: |
1557 | 1559 | raise MPContribsClientError(error) |
1558 | 1560 |
|
1559 | | - return self.projects.updateProjectByName( |
1560 | | - pk=self.project, project=payload |
1561 | | - ).result() |
| 1561 | + return self.projects.updateProjectByName(pk=name, project=payload).result() |
1562 | 1562 |
|
1563 | 1563 | def delete_contributions(self, query: dict = None, timeout: int = -1): |
1564 | 1564 | """Remove all contributions for a query |
|
0 commit comments