Skip to content

Models

scixplorer.model.Model

The base class of every model. These methods are available on all of them (Document.select(), Journal.get(...), …).

scixplorer.model.Model.select

select(*fields)

class method

Start a query over this model, fetching fields (all stored fields if none).

scixplorer.model.Model.get

get(*exprs, **equals)

class method

Return the single object matching exprs and field=value keywords.

Raises cls.DoesNotExist if nothing matches.

scixplorer.model.Model.describe

describe()

class method

Describe the fields of this model, in definition order.

scixplorer.model.Model.to_dict

to_dict()

The values loaded on this instance, by field name in definition order.

Never loads missing values, and does not include relations.

scixplorer.models.document.Document

Written Document after from scixplorer import Document.

Document(**values)

class

A document (paper, book, dataset, software, …) in ADS / SciX.

Search with select and where:

papers = (
    Document
    .select(Document.title)
    .where((Document.author[0] == "Kewley, L") & Document.year.between(2015, 2020))
    .order_by(Document.citation_count.desc())
    .limit(10)
)

Fields hold the values ADS returned; None means ADS had no value. Search-only fields (such as full) can be queried but not read.

Deferred fields (_deferred): ack, body, caption, citation, credit, mention and reference are not fetched by a plain Document.select(), because they are large (full text, or lists of bibcodes that can run to tens of thousands) and rarely needed. They are fetched when selected explicitly, or loaded on first access.

Identity: a document is identified by the first of its identifiers (_identifiers: bibcode, scix_id, id) that has a value. Two documents are equal when that is the same field with the same value; a document with no identifier is equal only to itself.

Lazy loading: reading a stored field that was not fetched sends one search request that loads it for every document of the same result page that lacks it, with a exceptions.LazyLoadWarning. Documents are found by their identifier (in practice the bibcode; documents of the page identified by another field are loaded with one more request per field). The request is synchronous, even inside async code, so there select the fields you need. The identifiers (always fetched) and score (only meaningful for the query that produced the document) are never loaded this way, and a document with no identifier loads nothing.

Relations: journal (from the bibcode), affiliation (from aff_id), uat_concepts (from uat_id) and planetary_features (from planetary_feature_id) give Journal, Affiliation, UATConcept and PlanetaryFeature objects, and can be searched by their fields (Document.journal.title.contains("astro")), as can those models’ fields directly (Journal.title.contains("astro")). The last two need their data downloaded once (data.refresh("uat"), data.refresh("planetary_features")), except to match ids directly (Document.uat_concepts == 498). Each such condition is about any related object; .any(...) makes several about the same one: Document.planetary_features.any((PlanetaryFeature.target == "Titan") & (PlanetaryFeature.feature_type == "Mare")).

Per-author conditions: doc.authors is one Author per author (.name, .aff, .affiliation, .email, .orcid, …), built from the per-author arrays author, aff, aff_id, email and the ORCID fields. In a search, everything inside one Document.authors.any(...) (or .all(...), every author) is about the same author, and an index picks a position:

Document.authors.any((Author.name == "Kewley, L") & (Author.affiliation.country == "Australia"))
Document.authors[0].orcid == "0000-0002-1825-0097"

A single condition means the same as its shorthand: Document.authors[0].name == x is Document.author[0] == x, and Document.authors.any(Author.affiliation.country == x) is Document.affiliation.country == x. A condition Solr cannot express exactly (several about one author at any position, or all) is sent as a necessary condition and checked on each returned document.

scixplorer.models.document.Document.citations

citations(expr)

class method

Documents that cite the documents matching expr.

Document.citations(Document.bibcode == "2003AJ....125..525J") finds the documents citing that one; references finds those it cites. See https://ui.adsabs.harvard.edu/help/search/citations-and-references.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.references

references(expr)

class method

Documents cited by the documents matching expr.

Document.references(Document.bibcode == "2003AJ....125..525J") finds the documents that one cites; citations finds those citing it. See https://ui.adsabs.harvard.edu/help/search/citations-and-references.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.trending

trending(expr)

class method

Documents most read by users who read recent papers matching expr.

These are papers currently being read by people interested in the field. See https://ui.adsabs.harvard.edu/help/search/second-order.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.useful

useful(expr)

class method

Documents frequently cited by the most relevant papers matching expr.

These are usually studies that discuss methods and techniques useful to conduct research in the field. See https://ui.adsabs.harvard.edu/help/search/second-order.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.reviews

reviews(expr)

class method

Documents citing the most relevant papers matching expr: the reviews of the field.

Takes the papers citing those matching expr, and ranks them by how many of them each cites. See https://ui.adsabs.harvard.edu/help/search/second-order.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.similar

similar(expr)

class method

Documents whose abstracts are similar in wording to those of the documents matching expr.

See https://ui.adsabs.harvard.edu/help/search/second-order.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.citis

citis(expr)

class method

Like citations, using less memory but more slowly.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.classic_relevance

classic_relevance(expr)

class method

The documents matching expr, ranked (almost) as ADS Classic’s relevance score did.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.instructive

instructive(expr)

class method

A synonym of reviews.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.join_citations

join_citations(expr)

class method

Like citations, using a Lucene block join (Solr joincitations()).

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.join_references

join_references(expr)

class method

Like references, using a Lucene block join (Solr joinreferences()).

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.reviews2

reviews2(expr)

class method

The original implementation of reviews.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.useful2

useful2(expr)

class method

The original implementation of useful.

Parameters

  • expr: an expression, or a Solr query string.

scixplorer.models.document.Document.top_n

top_n(n, expr, order_by=None)

class method

The first n documents matching expr (Solr topn()).

Parameters

  • n: how many documents.
  • expr: an expression, or a Solr query string.
  • order_by: how to rank them before taking the first n: an scixplorer.expr.Order such as Document.citation_count.desc(), or a field handle (ascending). By default, by relevance.

scixplorer.models.document.Document.pos

pos(expr, start, end=None)

class method

Documents where expr matches at a position (1-indexed, inclusive) of a multivalued field.

For authors prefer indexing: Document.author[0] == "Kewley, L" (first author) is pos(author == ..., 1), and Document.author[0:3] the first three. pos is for expressions written as Solr strings.

Parameters

  • expr: an expression, or a Solr query string.
  • start: the first position, counting from 1.
  • end: the last position (inclusive); None means start.

scixplorer.models.document.Document.raw

raw(query)

class method

A condition written in Solr syntax, sent as is (combine it with &, |, ~).

scixplorer.models.document.Document.in_

in_(source)

class method

Documents in source: a Library, or bibcodes.

A library is tested by ADS itself (docs(library/<id>)), without fetching its bibcodes. Anything else may be bibcode strings, documents, or iterables of them, and becomes Document.bibcode.in_(...).

scixplorer.models.document.Document.not_in

not_in(source)

class method

Documents not in source (see in_).

scixplorer.models.library.Library

Written Library after from scixplorer import Library.

Library(**values)

class

An ADS library: a named collection of documents kept by ADS for a user.

Find libraries with queries (Library.get(name="Gaia"), Library.select().where(Library.num_documents > 100)), which list your libraries and filter them locally; a query pinning Library.id fetches that library directly, so other users’ public libraries work too. Create one with create. Every other change is an explicit method making one API call (update, add, remove, empty, delete, set operations, permissions); nothing is saved implicitly, and assigning to a field only changes the local object.

Metadata fields missing from the object (for example after create) are fetched together, once, on first access. bibcodes is fetched on first access and cached until a method changes the documents. Fields the server maintains (such as date_last_modified) are not updated locally by the methods; call refresh for that.

Requests are sent with the client= argument of a method if given, else with the client in the client attribute (None unless set by the user, or by create and the set operations when given a client), else with get_default_client. Lazy loading and bibcodes use the attribute or the default. Libraries returned by a query do not remember the query’s client: set library.client if needed.

scixplorer.models.library.Library.create

create(name=None, description=None, public=False, documents=(), *, client=None)

class method

Create a library on ADS and return it.

Parameters

  • name: the name, which must be unique among your libraries; if None it is not sent and ADS assigns one.
  • description: the description; if None it is not sent.
  • public: whether anyone may read the library.
  • documents: bibcodes, documents, libraries, or iterables of these.
  • client: the client to use; it is also remembered as client on the returned library.

scixplorer.models.library.Library.update

update(*, name=None, description=None, public=None, client=None)

Change the name, description and/or visibility on ADS, and locally.

Only the arguments given are sent. Raises ValueError if none is given.

scixplorer.models.library.Library.refresh

refresh(*, client=None)

Fetch the metadata again, replacing the local values, and forget cached bibcodes.

scixplorer.models.library.Library.bibcodes

property bibcodes

The bibcodes of the documents, fetched on first access and cached.

scixplorer.models.library.Library.documents

property documents

A query for the documents in this library, searched on ADS.

scixplorer.models.library.Library.add

add(*documents, client=None)

Add documents (bibcodes, documents, libraries, or iterables of these).

Returns the number ADS actually added (documents already present are not).

scixplorer.models.library.Library.remove

remove(*documents, client=None)

Remove documents; returns the number ADS actually removed.

scixplorer.models.library.Library.empty

empty(*, client=None)

Remove every document.

scixplorer.models.library.Library.delete

delete(*, client=None)

Delete the library from ADS. The object can no longer be used afterwards.

scixplorer.models.library.Library.union

union(*libraries, name=None, description=None, public=False, client=None)

Create a library holding the documents in this library or any of libraries.

scixplorer.models.library.Library.intersection

intersection(*libraries, name=None, description=None, public=False, client=None)

Create a library holding the documents in this library and all of libraries.

scixplorer.models.library.Library.difference

difference(*libraries, name=None, description=None, public=False, client=None)

Create a library holding the documents in this library but in none of libraries.

scixplorer.models.library.Library.copy_to

copy_to(library, *, client=None)

Add this library’s documents to library (a Library or an id).

scixplorer.models.library.Library.get_permissions

get_permissions(*, client=None)

Who may access the library: {email: ["owner"] or ["read", "write", ...]}.

scixplorer.models.library.Library.set_permissions

set_permissions(email, *, read=False, write=False, admin=False, client=None)

Set the permissions of the ADS user with this email address (all False revokes them).

scixplorer.models.library.Library.transfer

transfer(email, *, client=None)

Make the ADS user with this email address the owner.

You lose all access to the library unless the new owner grants it.

scixplorer.models.library.Library.iter

__iter__()

Iterate over the documents (searched on ADS).

scixplorer.models.library.Library.len

__len__()

The number of documents, as ADS reports it in num_documents.

scixplorer.models.library.Library.contains

__contains__(item)

Whether a document (a bibcode or an object with a bibcode) is in the library.

scixplorer.models.journal.Journal

Written Journal after from scixplorer import Journal.

Journal(**values)

class

A journal or other publication series, identified by its ADS abbreviation (bibstem).

Journals are held in memory and queried locally:

Journal.get(abbreviation="ApJ").title

journals = (
    Journal
    .select()
    .where(Journal.title.contains("astro"))
    .order_by(Journal.title)
)

scixplorer.models.journal.Journal.lookup

lookup(abbreviation)

class method

The journal with this abbreviation, or None. Constant time.

scixplorer.models.affiliation.Affiliation

Written Affiliation after from scixplorer import Affiliation.

Affiliation(**values)

class

An institution, identified by its ADS canonical affiliation id (e.g. 'A00211').

Affiliations are held in memory and queried locally:

affiliations = (
    Affiliation
    .select()
    .where(Affiliation.country_code == "AU")
    .order_by(Affiliation.abbreviation)
)

Countries are spelled out as the upstream data spells them (“United States”, “United Kingdom”), and those spellings can change between releases of the data; country == "USA" simply matches nothing. Filter on country_code (ISO 3166-1 alpha-2, e.g. “US”) for a stable condition.

Institutions form a hierarchy (a department within a university): see parents, children and siblings.

scixplorer.models.affiliation.Affiliation.lookup

lookup(affiliation_id)

class method

The affiliation with this id, or None. Constant time.

scixplorer.models.affiliation.Affiliation.parents

property parents

The parent institutions, in parent_ids order (unknown ids skipped).

scixplorer.models.affiliation.Affiliation.parent

property parent

The first parent institution, or None.

scixplorer.models.affiliation.Affiliation.children

property children

A query for the institutions that list this one as a parent.

scixplorer.models.affiliation.Affiliation.siblings

property siblings

A query for the other institutions sharing at least one parent with this one.

scixplorer.models.uat.UATConcept

Written UATConcept after from scixplorer import UATConcept.

UATConcept(**values)

class

A concept of the Unified Astronomy Thesaurus, identified by its number (e.g. 486).

Concepts are held in memory and queried locally once the thesaurus has been downloaded (refresh("uat") in data):

UATConcept.lookup(486).name

concepts = (
    UATConcept
    .select()
    .where(UATConcept.name == "exoplanets")
    .order_by(UATConcept.name)
)

Concepts form a hierarchy in which a concept may have several broader concepts: see parents, children, ancestors and descendants. name and alt_names are matched like SciX text (== finds the words as a phrase, ignoring case; use .exact() for the whole name).

scixplorer.models.uat.UATConcept.lookup

lookup(concept_id)

class method

The concept with this number (an int, or a string of digits), or None. Constant time.

scixplorer.models.uat.UATConcept.parents

property parents

The broader concepts, in parent_ids order (unknown numbers skipped).

scixplorer.models.uat.UATConcept.children

property children

A query for the narrower concepts (those listing this one as a parent).

scixplorer.models.uat.UATConcept.ancestors

property ancestors

Every broader concept, nearest first, each once; safe if the data has cycles.

scixplorer.models.uat.UATConcept.descendants

property descendants

Every narrower concept, nearest first, each once; safe if the data has cycles.

scixplorer.models.planetary.PlanetaryFeature

Written PlanetaryFeature after from scixplorer import PlanetaryFeature.

PlanetaryFeature(**values)

class

A named feature on a planet, moon or small body, identified by its gazetteer id (e.g. 2071, Gale crater).

Features are held in memory and queried locally once the gazetteer has been downloaded (refresh("planetary_features") in data):

craters = (
    PlanetaryFeature
    .select()
    .where((PlanetaryFeature.target == "Mars") & (PlanetaryFeature.feature_type == "Crater"))
    .order_by(PlanetaryFeature.name)
)

name is matched like SciX text (== finds the words as a phrase, ignoring case, so name == "Olympus" also finds “Olympus Mons”; use .exact("Olympus Mons") for the whole name). The other text fields are matched exactly, including case.

scixplorer.models.planetary.PlanetaryFeature.lookup

lookup(feature_id)

class method

The feature with this id (an int, or a string of digits), or None. Constant time.

scixplorer.models.author.Author

Written Author after from scixplorer import Author.

Author(**values)

class

One author of a Document, from doc.authors.

Values come from entry position of the document’s per-author arrays; "-" (ADS’s “none”) and missing entries give None (an empty list for aff_id). Authors are not searched on their own: use their fields inside Document.authors.any(...) / .all(...), where everything is about one author.

scixplorer.expr.days_ago

Written days_ago after from scixplorer import days_ago.

days_ago(n)

The time n days before now, as evaluated by Solr.

scixplorer.expr.now

Written now after from scixplorer import now.

now()

The current time, as evaluated by Solr.

scixplorer.search.to_solr

Written search.to_solr after from scixplorer import search.

to_solr(query_or_expr)

The Solr q string that a document query (or a filter expression) sends.

For a search sent to /search/bigquery this is the query applied to the uploaded bibcodes, without them; for one with a per-record condition checked client-side, it holds only that condition’s necessary part. A filter that can never match gives the query matching nothing. Raises exceptions.UnsupportedQueryError if the query needs the bibcodes of a library (library_membership="bibcodes").

scixplorer.search.plan

Written search.plan after from scixplorer import search.

plan(query, *, library_bibcodes=None)

Plan query: decide the request parameters without performing any I/O.

With config.library_membership == "bibcodes", library_bibcodes must map the id of every library in the filter to its bibcodes (the backend fetches them). Raises exceptions.QueryError (or its subclass exceptions.UnsupportedQueryError) for a query that cannot be sent, and ValueError for an invalid configuration.